0
$\begingroup$

Does anyone know how to animate the trajectory of a particle, but make sure before the particle reaching a certain spot, there's nothing. I mean I want to make an animation that look like https://en.wikipedia.org/wiki/Lunar_precession#/media/File:Animation_of_Moon_orbit_around_Earth_-_Polar_view.gif

What I don't want is plotting the parametric plot first and add a moving particle along the line, such as Animating a parametric plot. Because I do not have 50 reputations yet, I cannot ask and comment on this link. So I copy the code below, and see if someone can give me suggestion how to make modification.

Thank you very much for reading my question.

r = 2; l = 6; m = 9; g = -9.81; t0 = 0; tf = 6.67;

x[t_] = (l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]];
y[t_] = r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]];

kE = (1/2) m ((x'[t])^2 + (y'[t])^2);
pE = m g (r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]);
lagrangian = kE - pE;
eL[t_] = (D[lagrangian, θ[t]] - D[D[lagrangian, θ'[t]], t]) //FullSimplify;

soln = NDSolve[{eL[t] == 0, θ[0] == 0, θ'[0] == 0}, θ, {t, t0, tf}];

Animate[ParametricPlot[{(l - r θ) Cos[θ] + r Sin[θ], r Cos[θ] - (l - r θ) Sin[θ]}, {θ, 0, -20}, Epilog -> {PointSize -> 0.015, Evaluate[Point[{(l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]],r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]}] /. soln[[1]]]}], {t, t0, tf}]
$\endgroup$

1 Answer 1

5
$\begingroup$
r = 2; l = 6; m = 9; g = -9.81; t0 = 0; tf = 6.67;

x[t_] = (l - r θ[t]) Cos[θ[t]] + r Sin[θ[t]];
y[t_] = r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]];

kE = (1/2) m ((x'[t])^2 + (y'[t])^2);
pE = m g (r Cos[θ[t]] - (l - r θ[t]) Sin[θ[t]]);
lagrangian = kE - pE;
eL[t_] = (D[lagrangian, θ[t]] - D[D[lagrangian, θ'[t]], t]) // FullSimplify;

soln = NDSolve[{eL[t] == 0, θ[0] == 0, θ'[0] == 0}, θ, {t, t0, tf}];

ListAnimate[
 Table[Graphics[{Blue, Rectangle[{-l*2, 0}, {l*1.2, l*2}], Yellow, 
    Line[Table[{x[t], y[t]} /. soln, {t, 0, tn, .01*tn}]], 
    PointSize[Large], Red, Point[{x[tn], y[tn]} /. soln]}], {tn, 0.1, 
   tf, .01*tf}]]

fig1

To draw a trajectory with a thick solid line, use the code

ListAnimate[
 Table[Graphics[{Blue, Rectangle[{-l*2, 0}, {l*1.2, l*2}], Yellow, 
    Thick, Line[
     Flatten[Table[{x[t], y[t]} /. soln, {t, 0, tn, .01*tn}], 1]], 
    PointSize[Large], Red, Point[{x[tn], y[tn]} /. soln]}], {tn, 0.1, 
   tf, .01*tf}]]

fig2

$\endgroup$
4
  • $\begingroup$ Is it possible to show the trajectory with lines instead of ListAnimate? $\endgroup$ Feb 3, 2019 at 23:43
  • 1
    $\begingroup$ Everything is possible. Explain what you want? $\endgroup$ Feb 4, 2019 at 0:17
  • $\begingroup$ Thank you for reply. I want smooth line following the particle's motion instead of discrete dots. $\endgroup$ Feb 4, 2019 at 0:41
  • 1
    $\begingroup$ @YunlinZeng See update. $\endgroup$ Feb 4, 2019 at 22:45

Your Answer

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

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