Maybe you want an animation parameterized by the time $t$? This would do it in an interactive way:
With[{missileSize = 10},
Manipulate[
Graphics[{
{Red,
Disk[
{100 t, 80 t - 16 t^2}, missileSize
]},
{Blue,
Disk[
{500 - 200 (t - 2), 80 (t - 2) - 16 (t - 2)^2}, missileSize
]}
},
Frame -> True,
GridLines -> Automatic,
PlotRange -> {{0, 800}, {-200, 400}},
AspectRatio -> Automatic],
{t, 0, 7}]
]
Alternatively, you could create an animation like this:
t = Table[Graphics[{
{Red,
Disk[
{100 t, 80 t - 16 t^2}, 10
]},
{Blue,
Disk[
{500 - 200 (t - 2), 80 (t - 2) - 16 (t - 2)^2}, 10
]}
},
Frame -> True,
PlotRange -> {{0, 800}, {-200, 400}},
AspectRatio -> Automatic],
{t, 0, 5, .1}];
ListAnimate[t]
The animation above was created with
Export["missiles.gif", t]
Edit
Since it was asked in the comment, I'll add the 3D analogue here, too - although Verbeia already did something like it with Manipulate
:
xMin = 0;
xMax = 800;
yMin = -200;
yMax = 200;
zMin = -200;
zMax = 400;
ground = {Green,
Polygon[{{xMin, yMin, zMin}, {xMin, yMax, zMin}, {xMax, yMax,
zMin}, {xMax, yMin, zMin}}]};
t = Table[
Graphics3D[{ground, {Red,
Sphere[{100 t, 0, 80 t - 16 t^2}, 10]}, {Blue,
Sphere[{500 - 200 (t - 2), 0, 80 (t - 2) - 16 (t - 2)^2}, 10]}},
Boxed -> True,
PlotRange -> {{xMin, xMax}, {yMin, yMax}, {zMin, zMax}}], {t, 0,
6, .1}];
ListAnimate[t]
If you compare to the 2D code, I just replaced Disk
by Sphere
, made the height the z
coordinate and set the y
coordinate of the projectiles to 0
.
The other changes are just small tweaks: I defined the plot range as variables so I can use them to define a rectangular Polygon
representing the ground
. Instead of the Framed
option, there is the Boxed
option (which can also be omitted or set to False
).