Esempio n. 1
0
        static void ClosestLine()
        {
            //Collect data from user
            Console.Write("Enter the x coordinate of the ship (km): ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the ship (km): ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the ship (km): ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D ship = new Vector3D(x, y, z); //km
            Console.Write("Enter the x coordinate of the meteor (km): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the meteor (km): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the meteor (km): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D meteor = new Vector3D(x, y, z); //km
            Console.Write("Enter the x coordinate of the meteor's trajectory (km/s): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the meteor's trajectory (km/s): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the meteor's trajectory (km/s): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D trajectory = new Vector3D(x, y, z); //km/s

            //The mathening
            Vector3D closestPoint = ship.ClosestPointLine(meteor, trajectory); //km, the closest point on the line

            //Output
            Console.WriteLine("Closest Point is: " + closestPoint + " km");
            Console.WriteLine("Distance of closest approach is: {0:N2} km", (closestPoint - ship).GetMagnitude());
        }