4
$\begingroup$

A recurrent problem with Manipulate-based animation is that the widget often changes shape as one manipulates it, because, e.g., axis decorations come in and out of existence. In this example, an additional problem is that a component of the image that should remain unchanged throughout the manipulation (it is essentially a background image) is nonetheless redrawn at the start and finish of each manipulation. What's worse is that in the first of such paired redrawings, a simplified version of the image is rendered; in the second, a more polished version is drawn.

Here's the code for the widget:

unitSquareToTorus[x_, y_] := Module[
  {u = 2 Pi x, v = 2 Pi y},
  {(2 + Cos[u]) Cos[v], (2 + Cos[u]) Sin[v], Sin[u]}
];

Manipulate[
  Show[
    {
       ParametricPlot3D[{
                           (2 + Cos[v]) Cos[u]
                         , (2 + Cos[v]) Sin[u]
                         , Sin[v]
                        }
                        , {u, 0, 2 Pi}
                        , {v, 0, 2 Pi}
                        , PlotStyle -> Opacity[0.25]
                       ]
     , Graphics3D[{PointSize[Large], Point[unitSquareToTorus[t/12, t]]}]
    }
    , ImageSize -> 600
   ]
   , {t, 0, 24}
 ]

And this is what it looks like:

Mathematica graphics

Ideally, when the slider is moved, all that should happen is that the black dot should move smoothly over the surface of the torus. Everything else (i.e. the rest of the widget, the torus, the bounding box, the axis labels, etc.) should be rock-solid-fixed. Is that possible?

$\endgroup$

2 Answers 2

5
$\begingroup$

Wrap Dynamic around the things to be updated:

Manipulate[
 Show[{ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], Sin[v]},
     {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Opacity[0.25]],
    Graphics3D[{PointSize[Large], 
     Dynamic@Point[unitSquareToTorus[t/12, t]]}]}, 
  ImageSize -> 600], {t, 0, 24}]

There is a technical constraint: This works because the only thing that depends on t is the Point. So wrapping it in Dynamic isolates that object to be updated when t is changed. If there were other parts of the code that depended on t, one would have to wrap them in Dynamic as well. Sometimes the structure of the code entails that everything has to be updated. But here, it's simple.

$\endgroup$
5
$\begingroup$

Another possibility is simply to save the static part, here, in plot:

plot = ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], 
    Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Opacity[0.25]];
Manipulate[
 Show[{plot, 
   Graphics3D[{PointSize[Large], Point[unitSquareToTorus[t/12, t]]}]},
   ImageSize -> 600], {t, 0, 24}]
$\endgroup$

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.