예제 #1
0
        //Homework #2
        static void ProjectileTrial()
        {
            var target = new Tuple<double, double>(5, 2);
            double vMag = 10;
            NoFrictionProjectile proj1 = new NoFrictionProjectile();
            proj1.setVmag(vMag);
            var angle = proj1.GetAnglesToTarget(target.Item1, target.Item2).Item2;
            proj1.setTheta(angle);
            double t = proj1.GetTimeOfFlight();
            PlotData p = new PlotData(proj1, 0, t, .01);
            p.AddPoint(target.Item1, target.Item2, "Target to hit");
            p.AddParametricTrial("x", "y", "t", "No friction\nLaunch angle: \n" + angle.ToString());
            LaminarFrictionProjectile proj2 = new LaminarFrictionProjectile();
            p.SetNewEq(proj2);
            double gamma = .1;

            proj2.SetGamma(gamma);
            proj2.SetvMag(vMag);
            angle = proj2.GetAngleToTarget(target.Item1, target.Item2);
            proj2.SetvMagTheta(vMag, angle);
            p.AddParametricTrial("x", "y", "t", "Launch angle: \n" + angle.ToString() + "\nGamma: " + gamma.ToString());
            gamma = .01;
            proj2.SetGamma(gamma);
            angle = proj2.GetAngleToTarget(target.Item1, target.Item2);
            proj2.SetvMagTheta(vMag, angle);
            p.AddParametricTrial("x", "y", "t", "Launch angle: \n" + angle.ToString() + "\nGamma: " + gamma.ToString());
            gamma = .001;
            proj2.SetGamma(gamma);
            angle = proj2.GetAngleToTarget(target.Item1, target.Item2);
            proj2.SetvMagTheta(vMag, angle);
            p.AddParametricTrial("x", "y", "t", "Launch angle: \n" + angle.ToString() + "\nGamma: " + gamma.ToString());
            //p.Graph();

            for (double i = .3; i < .5; i+=.01) {
                proj2.SetGamma(i);
                proj2.SetvMag(vMag);
                angle = proj2.GetAngleToTarget(target.Item1, target.Item2);
                if(angle < 0){
                    Console.WriteLine("Largest gamma with which the projectile can reach the target:");
                    i -= .01;
                    Console.WriteLine((i).ToString());
                    Console.WriteLine("\nNumber of iterations to convergence:");
                    proj2.SetGamma(i);
                    Console.WriteLine(proj2.NumberOfIterationsToConvergence(target.Item1, target.Item2).ToString());
                    break;
                }
            }
            Console.Read();

            //ProjectileTrial(.001);
            //ProjectileTrial(.01);
            //ProjectileTrial(.1);
            //ProjectileTrial(1);
        }