using System;
namespace ExpandingGalaxy
{
public class Point
{
public Point( double x, double y )
{
this.x = x;
this.y = y;
}
public double x { get; set; }
public double y { get; set; }
}
public class MainClass
{
const double H = 3.5;
const double DT = 0.1;
private static Point[] Calc()
{
const int RANDOM_MAX = 21478643;
const int SEED = 503;
double x, y;
Point[] points = new Point[200];
Random rand = new Random( SEED );
int i = 0;
while( true )
{
x = ( double )( 1.0 / RANDOM_MAX * rand.Next( -100000000, 100000000 ) );
y = ( double )( 1.0 / RANDOM_MAX * rand.Next( -100000000, 100000000 ) );
if( Math.Pow( x, 2 ) + Math.Pow( y, 2 ) <= 1.0 )
{
points[i] = new Point( x, y );
i++;
if( ( i == 200 ) )
break;
}
}
return points;
}
private static void ExpandingSimulate( Point[] points, Point[] vxPoints )
{
for( int i = 0; i < points.Length; i++ )
{
points[i].x += vxPoints[i].x * DT;
points[i].y += vxPoints[i].y * DT;
}
}
private static Point[] GetVxValue( Point[] points )
{
Point[] vxPoint = new Point[200];
for( int i = 0; i < points.Length; i++ )
{
vxPoint[i] = new Point( points[i].x * H, points[i].y * H );
}
return vxPoint;
}
public static void Main( string[] args )
{
Point[] points0 = Calc();
Point[] vxPoint = GetVxValue( points0 );
for( int i = 0; i < points0.Length; i++ )
{
points0[i].x += 10;
points0[i].y += 10;
}
using( System.IO.StreamWriter writer = new System.IO.StreamWriter( @"data.csv" ) )
{
for( int i = 0; i < 20; i++ )
{
ExpandingSimulate( points0, vxPoint );
if( ( i == 0 ) || ( i == 5 ) || ( i == 19 ) )
{
for( int j = 0; j < points0.Length; j++ )
writer.WriteLine( "{0}, {1}", points0[j].x, points0[j].y );
writer.WriteLine();
}
}
}
}
}
}