3
$\begingroup$

Lets say two cannon is fired at different initial position, initial angle and initial speed.

let say initial speed,angle and position for

projectile 1= v0=18; theta=49 Degree; position={0,0} projectile 2= v0=15; theta=56 Degree; position={95,100}

How to write a code that can simulate this event.

How to calculate these two projectiles distances as a function of time say from t=0 to t=10 seconds.

Between both fired canon ball what is their distances? at lets say t=7.9 seconds.

this is my code so far

x0 = 0; y0 = 0; g = -9.81;
vx0 := v0*Sin[theta]; vy0 := v0*Cos[theta];

x[t_] := x0 + v0*Cos[theta]*t;
y[t_] := y0 + v0*Sin[theta]*t + 0.5 g*t^2;

v0 = 18.0; theta = 49 Degree;
T = -2 (y0 + v0*Sin[theta])/g;
pp1 = ParametricPlot[{x[t], y[t]}, {t, 0, 1 T}, PlotRange -> All, 
   PlotStyle -> Blue];

v0 = 15.0; theta = 56 Degree;
T = -2 (y0 + v0*Sin[theta])/g;
pp2 = ParametricPlot[{x[t], y[t]}, {t, 0, 1 T}, PlotRange -> All, 
   PlotStyle -> Red];
Show[{pp1, pp2}]

enter image description here

All Help is Really Appreciated

$\endgroup$
0

2 Answers 2

6
$\begingroup$

You can make a function for the trajectory of a projectile, which takes the initial position, velocity, angle, and time as arguments.

projTrajectory[{x0_, y0_}, v0_, theta_, t_] := 
 Module[{T = -(v0 Sin[theta] + Sqrt[-2 g y0 + v0^2 Sin[theta]^2])/g},
  {x0, y0} + If[t < T, {v0*Cos[theta]*t,
     v0*Sin[theta]*t + 0.5 g*t^2},
    {v0*Cos[theta]*T,
     v0*Sin[theta]*T + 0.5 g*T^2}
    ]
  ]

It looks a bit complicated with the Module, but the point is to make sure the projectile stays put when it hits the ground, so we calculate that time beforehand. You could modify it to let it roll afterwards if you like.

ParametricPlot[{
  projTrajectory[{0, 2}, 18.0, 49 Degree, t],
  projTrajectory[{0, 0}, 15.0, 56 Degree, t]
  }, {t, 0, 3}, AspectRatio -> .5]

enter image description here

And you can plot the distance between the projectiles as a function of time,

Plot[Norm[projTrajectory[{0, 2}, 18.0, 49 Degree, t] -
   projTrajectory[{0, 0}, 15.0, 56 Degree, t]], {t, 0, 10}]

enter image description here

And then you could make it interactive,

Manipulate[
 Row[
  {ParametricPlot[{
     projTrajectory[{0, 2}, 18.0, 49 Degree, t],
     projTrajectory[{0, 0}, 15.0, 56 Degree, t]
     }, {t, 0, Tmax}, AspectRatio -> .5, ImageSize -> 400, 
    PlotRange -> {{0, 40}, {0, 14}}, 
    PlotLabel -> Style["Trajectories", 18]],
   Plot[Norm[projTrajectory[{0, 2}, 18.0, 49 Degree, t] -
      projTrajectory[{0, 0}, 15.0, 56 Degree, t]], {t, 0, Tmax}, 
    AspectRatio -> .5, ImageSize -> 400, 
    PlotRange -> {{0, 5}, {0, 14}}, 
    PlotLabel -> Style["Separation", 18]]}
  ], {{Tmax, 0.01}, 0.01, 5, .1}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Hi, +1, g needs to be defined. $\endgroup$
    – bobbym
    Mar 18, 2016 at 19:15
3
$\begingroup$
x0 = 0; y0 = 0; g = -9.81;
r = {x0 + v0 t Cos@\[Theta], y0 + v0 t Sin@\[Theta] + g t^2/2};
path[t_] = {Block[{v0 = 18, \[Theta] = 49 Degree}, r], 
   Block[{v0 = 15, \[Theta] = 56 Degree}, r]};
Animate[
 Show[
  ParametricPlot[Evaluate@path@t0, {t0, 0, t}, 
   PlotRange -> {{0, 33}, {0, 12}}],
  Graphics[{{Gray, Line@path@t}, {Red, PointSize[0.02], 
     Point@path@t}, {Text[ToString[Norm@Flatten@Differences@path@t], 
      First@path@t + {-4, 1}]}}]
  ],
 {t, 10^-4, 3}, AnimationRate -> 0.4]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.