//Methods calculates the distance between the two points public static double Distance2D(Points2D firstPoint, Points2D secondPoint) { double distance = Math.Sqrt( Math.Pow(firstPoint.x2 - secondPoint.x2, 2) + Math.Pow(firstPoint.y2 - secondPoint.y2, 2) ); return(distance); }
static void Main(string[] args) { Random random = new Random(); Points2D[] points2D = new Points2D[10]; for (int i = 0; i < 10; i++) { int x = random.Next(1, 10); int y = random.Next(1, 10); points2D[i] = new Points2D(x, y); } for (int i = 0; i < 10; i++) { double closestDistance = Math.Sqrt(200); int closestPoint = 0; for (int j = 0; j < 10; j++) { if (j != i) { double distance = points2D[i].Distance2D(points2D[j]); if (distance < closestDistance) { closestPoint = j; closestDistance = distance; } } } Console.WriteLine("closest point to point " + i + " " + points2D[i].Location2D() + " is point " + closestPoint + " " + points2D[closestPoint].Location2D() + ", the distance is " + closestDistance); } Console.WriteLine(); Points3D[] points3D = new Points3D[10]; for (int i = 0; i < 10; i++) { int x = random.Next(1, 10); int y = random.Next(1, 10); int z = random.Next(1, 10); points3D[i] = new Points3D(x, y, z); } for (int i = 0; i < 10; i++) { double closestDistance = Math.Sqrt(300); int closestPoint = 0; for (int j = 0; j < 10; j++) { if (j != i) { double distance = points3D[i].Distance3D(points3D[j]); if (distance < closestDistance) { closestPoint = j; closestDistance = distance; } } } Console.WriteLine("closest point to point " + i + " " + points3D[i].Location3D() + " is point " + closestPoint + " " + points3D[closestPoint].Location3D() + ", the distance is " + closestDistance); } }
public Game() { this.windowWidth = 1920; this.windowHeight = 1080; this.window = new RenderWindow(new VideoMode(this.windowWidth, this.windowHeight), "Vector Field", Styles.Default); //this.window.SetVerticalSyncEnabled(true); this.window.Closed += this.OnClose; this.window.Resized += this.OnResize; this.window.MouseMoved += this.OnMouseMoved; this.clock = new Clock(); this.deltaTime = 0f; this.currentMousePosition = new Vector2f(0f, 0f); this.previousMousePosition = new Vector2f(0f, 0f); this.points = new Points2D((int)Math.Pow(2, 18), (int)Math.Pow(2, 8), this.windowWidth, this.windowHeight); this.song = new Audio("C:\\Users\\Alfred\\RiderProjects\\VectorField\\VectorField\\Gosh.ogg"); this.song.SetLoop(true); }
public double Distance2D(Points2D p) { double distance = Math.Sqrt((Math.Pow((x - p.x), 2) + Math.Pow((y - p.y), 2))); return(distance); }