0
$\begingroup$

I have a piece of code which plots parametric functions using for loops.

a = {6, 2}
b = {2, 6}
c = {-1, -2}
func = {}
For[i = 1, i <= 2, i++, 
plot = ParametricPlot3D[{a [[i]] Cos[t] - c[[i]], b [[i]] Sin[t], 
0}, {t, 0, 2 Pi}, PlotRange -> 7];
AppendTo[func, plot]]

Show[func]

This plots the following pathsenter image description here

if i animate them using the following code:

a = {6, 1}
b = {2, 1}
c = {-1, -2}
func = {}
For[i = 1, i <= 2, i++, 
plot = ParametricPlot3D[{a[[i]] Cos[t] - c[[i]], b[[i]]Sin[t], 
0}, {t, 0, 2 Pi}, PlotRange -> 7];
AppendTo[func, plot]]

Animate[Show[func, 
  Graphics3D[{PointSize[Large], Red, 
  Point[Dynamic[{a [[1]] Cos[t] - c[[1]], b[[1]] Sin[t], 0}]]}]
  ] , {t, 0, 10}]

I only get one point travelling around the elliptical path.

However,if i replace values of a[1],b[1],c[1] with i, as per the loop

Animate[Show[func, 
      Graphics3D[{PointSize[Large], Red, 
      Point[Dynamic[{a [[i]] Cos[t] - c[[i]], b[[i]] Sin[t], 0}]]}]
      ] , {t, 0, 10}]

i get this plotenter image description here and this error message: "Coordinate {-Part[{-1., -2.}, 3] - 0.9974703237996385 Part[{6., 1.}, 3], (-0.07108412719478453) Part[{2., 1.}, 3], 0.} should be a triple of numbers, or a Scaled form."

Is it possible to animate points travelling around their individual parametric paths within the same plot?

$\endgroup$
3
$\begingroup$
a = {6, 1}
b = {2, 1}
c = {-1, -2}
func = {}
For[i = 1, i <= 2, i++, 
 plot = ParametricPlot3D[{a[[i]] Cos[t] - c[[i]], b[[i]] Sin[t], 
    0}, {t, 0, 2 Pi}, PlotRange -> 7];
 AppendTo[func, plot]]

Animate[Show[func, 
  Graphics3D[{PointSize[Large], Red, 
    Point[Table[{a[[i]] Cos[t] - c[[i]], b[[i]] Sin[t], 0}, {i, 1, 
       2}]]}]], {t, 0, 10}]

enter image description here

Note :
- in your code, Dynamic is useless
- it is recommended not to use For[...]. Hence I use Table[...] in my mofiication of your code.

By the way, your code :

func = {}
For[i = 1, i <= 2, i++, 
 plot = ParametricPlot3D[{a[[i]] Cos[t] - c[[i]], b[[i]] Sin[t], 
    0}, {t, 0, 2 Pi}, PlotRange -> 7];
 AppendTo[func, plot]]  

could be rewritten like this :

func = Table[
  ParametricPlot3D[{a[[i]] Cos[t] - c[[i]], b[[i]] Sin[t], 0}, {t, 0, 
    2 Pi}, PlotRange -> 7], {i, 1, 2}]
$\endgroup$
  • $\begingroup$ Thanks for help, is there way to alter the framerate of the animation so that that it runs smoother? I have ~2000 objects that have been rotated by Euler rotation matrix and when I run the animation, its very slow $\endgroup$ – Luke4737 Mar 25 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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