I have a simple animation of a spacecraft being gravitationally deflected by Mars and wanted to be able to represent Mars as a red disk, but am having trouble doing this. Here is the code (where the last animate is my attempt at adding a red disk to the animation):
m[2] = 6.4185*10^23;
r[2] = 3.3899*10^6;
G = 6.672*10^-11;
tmax2 = 2.5*86400
xr = 5.74143*10^8
yr = 4.64259*10^7
vxr = -3275.65
vyr = -227.858
soln = NDSolve[{
x''[t] == -((G m[2] x[t])/(x[t]^2 + y[t]^2)^(3/2)),
y''[t] == -((G m[2] y[t])/(x[t]^2 + y[t]^2)^(3/2)),
x[0] == xr, y[0] == yr, x'[0] == vxr, y'[0] == vyr}, {x[t],
y[t]}, {t, 0, tmax2} , MaxSteps -> 1000000,
Method -> "StiffnessSwitching"]
Show[ParametricPlot[Evaluate[{x[t], y[t]} /. soln], {t, 0, tmax2},
AxesLabel -> {x, y}, PlotStyle -> Automatic, PlotRange -> Full,
ImageSize -> Large], Graphics[{Red, Disk[{0, 0}, r[2]]}]]
Animate[ParametricPlot[{{x[t], y[t]}} /. soln /. t -> a, {t,
Max[0, a - 10000], a}, AxesLabel -> {x, y}, Axes -> False,
ImageSize -> Large], {a, 0, tmax2}, AnimationRate -> 1000]
Animate[Graphics[{Red,
Disk[{0, 0}, r[2]]}], [ParametricPlot[{{x[t], y[t]}} /. soln /.
t -> a, {t, Max[0, a - 10000], a}, AxesLabel -> {x, y},
Axes -> False, ImageSize -> Large], {a, 0, tmax2},
AnimationRate -> 1000]]
As can be seen below the disk shows up nicely in the "still" version, but I get a syntax error when trying to put the disk in the animated version. Any help would very much be appreciated, thanks very much.
Epilog
andProlog
. $\endgroup$Show
to combineGraphics
objects. You already used it for the still version but not for the animated one. But for a simpleDisk
object usingEpilog
is probably the best. $\endgroup$