//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); }
static void ProjectileTrial(double gamma) { double v0 = 10; var target = new Tuple<double, double>(5, 2); var p = new PlotData(0, 2, .01); p.AddPoint(target.Item1, target.Item2, "Target to hit"); var projFrict = new LaminarFrictionProjectile(gamma); projFrict.SetvMag(v0); double ang1 = projFrict.GetAngleToTarget(target.Item1, target.Item2); projFrict.SetvMagTheta(v0, ang1); p.SetNewEq(projFrict); p.AddParametricTrial("x", "y", "t", "Launch angle: " + ang1.ToString() + " gamma: " + gamma.ToString()); var projNoFric = new NoFrictionProjectile(); projNoFric.setVmag(v0); var ang2 = projNoFric.GetAnglesToTarget(target.Item1, target.Item2); projNoFric.setTheta(ang2.Item1); p.SetNewEq(projNoFric); p.AddParametricTrial("x", "y", "t", "Launch angle: " + ang2.Item1.ToString() + " gamma: " + gamma.ToString()); p.Graph(); projFrict.GetThetaForMaxDistance(); }
static void LaminarFrictionProjectileTrial() { LaminarFrictionProjectile proj = new LaminarFrictionProjectile(2); proj.SetvMag(10); var target = new Tuple<double, double>(2, .1); var angle = proj.GetAngleToTarget(target.Item1, target.Item2); PlotData p = new PlotData(proj, 0, 2, .01); p.AddPoint(target.Item1, target.Item2, "Target to hit"); if (angle == double.MinValue) throw new Exception("no solution"); proj.SetvMagTheta(10, angle); p.AddParametricTrial("x", "y", "t", "Launch angle: " + angle.ToString()); p.Graph(); }