0
$\begingroup$

Have used the below code to animate a plot for motion of a spherical pendulum

    sol = Flatten[
   NDSolve[{theta''[t] == phi'[t]^2 Cos[theta[t]] - 
        g/l Sin[theta[t]], phi''[t] == (-2 phi'[t] theta'[t] Cos[theta[t]])/
        Sin[theta[t]], theta[0] == Pi/2, theta'[0] == 
       0, phi[0] == Pi/2, phi'[0] == 1} /. {g -> 9.81, 
      l -> 1}, {theta, phi}, {t, 0, 30}]];
x[t_] := Evaluate[(Sin[theta[t]] Cos[phi[t]]) /. sol]
y[t_] := Evaluate[(Sin[theta[t]] Sin[phi[t]]) /. sol]
z[t_] := -Evaluate[Cos[theta[t]] /. sol]
ParametricPlot3D[{x[t], y[t], z[t]}, {t, 0, 30}]
Animate[ParametricPlot3D[{x[t], y[t], z[t]}, {t, 0, n}], {n, 0.1, 30, 
  0.01}]

but at around 10 seconds in the lines start to wiggle and aren't smooth, is there a way to fix this? Thanks. screenshot of wiggly lines

$\endgroup$
5
  • $\begingroup$ Try increasing the setting for PlotPoints. $\endgroup$
    – J. M.'s torpor
    Mar 28 '18 at 11:52
  • $\begingroup$ Sorry, just to be clear, the lines on the stationary plot are perfect, it is only when the plot is animated that the problem arises. Thanks. $\endgroup$
    – Marky
    Mar 28 '18 at 12:31
  • $\begingroup$ "when the plot is animated" - that's because of the default setting for PerformanceGoal in ParametricPlot3D[]. Try adding PerformanceGoal -> "Quality". $\endgroup$
    – J. M.'s torpor
    Mar 28 '18 at 13:40
  • $\begingroup$ This worked! Thank you so much for your help, much appreciated. $\endgroup$
    – Marky
    Mar 28 '18 at 13:47
  • $\begingroup$ It will work, yes, but the price of having smooth curves is a slightly slower animation. You need to decide if this trade-off is worth it. $\endgroup$
    – J. M.'s torpor
    Mar 28 '18 at 13:51