2
$\begingroup$

Instead of a point, I want to animate a 3D Sphere to following the path of this 3D-spline. How would I do this with the given code below. Any solutions to this ?

 pts = {{0, 0, 1}, {1, 1, 1}, {0.5, 1.5, 1}}; 
 s = BSplineFunction[pts, SplineClosed -> True, SplineDegree -> 1];
 Animate[
   ParametricPlot3D[s[t], {t, 0, 1}, 
     Epilog :> {Red, PointSize[Large], Point[s[t]]}], 
  {t, 0., 1.}]
$\endgroup$
  • $\begingroup$ 1. You should use a different dummy variable for ParametricPlot3D[] and Animate[] 2. Epilog is only intended for appending 2D primitives. Thus: Animate[Show[ParametricPlot3D[s[t], {t, 0, 1}], Graphics3D[{Red, PointSize[Large], Point[s[u]]}]], {u, 0., 1.}] $\endgroup$ – J. M. is away Mar 12 '18 at 19:08
1
$\begingroup$

You can't put 3D graphics objects in a epilog clause. The Epilog option is strictly for adding a 2D foreground to a plot, 2D or 3D. You should use Show and make the sphere with a Graphics expression. Like so.

pts = {{0, 0, 1}, {1, 1, 1}, {0.5, 1.5, 1}};
s = BSplineFunction[pts, SplineClosed -> True, SplineDegree -> 1];

Animate[
  Show[
    ParametricPlot3D[s[t], {t, 0, 1}],
    Graphics3D[{Red, Sphere[s[t], Scaled[.02]]}]],
  {t, 0., 1}]

plot

$\endgroup$
  • $\begingroup$ Thank you, this was very helpful $\endgroup$ – Brandon M Mar 13 '18 at 21:47
  • $\begingroup$ @BrandonM. Helpful but not worth an up-vote? $\endgroup$ – m_goldberg Mar 13 '18 at 22:06
  • $\begingroup$ How do I do that? I'm new to stackexchange. $\endgroup$ – Brandon M Mar 14 '18 at 16:17
  • $\begingroup$ @BrandonM. Just click on the up-arrow on lefthand side of the answer -- above the acceptance checkmark that you have already clicked on (and thanks for that). $\endgroup$ – m_goldberg Mar 14 '18 at 19:10
1
$\begingroup$
Animate[ParametricPlot3D[s[t], {t, 0, 1}, MeshFunctions -> {#4 &}, 
   Mesh -> {{u}}, MeshStyle -> Red] /. Point[x_] :> Sphere[x, .05], {u,  0., 1.}]

enter image description here

$\endgroup$

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.