Say I'd like to visualise a height function of a torus by animating a plane going upwards, and highlighting the intersection via Mesh/MeshFunctions. I draw the torus using ParametricPlot3D, and I would like it to be very smooth and nice looking, so I put somewhat high values of PlotPoints and/or MaxRecursion. I produce an animation using Table with the parameter being the value in Mesh.

Now the problem is, that each frame of my animation recomputes the torus, which takes a lot of time. Is there a way to only compute the torus once, and then just compute different meshes for each frame? Maybe I could compute all the meshes while computing the plot, and then just display one at the time? Can I extract meshes as, say, GraphicsComplex and combine it back with the plot in Show?

  • 4
    $\begingroup$ Please edit your question to include the code you have so far. Your question is less likely to get answered if people have to spend a bunch of time just trying to figure out how to recreate the animation from your description alone. If people can just take your code and run it to see how it works, they're much more likely to be able to offer a solution if one exists. $\endgroup$ – MassDefect Jun 5 '20 at 17:38
  • $\begingroup$ @MassDefect Right, I'll keep that in mind next time! $\endgroup$ – OnDragi Jun 5 '20 at 20:19

It's possible with some amount of effort. The key is to make separate plots of the surface without the meshlines, and a plot with just the meshlines. Since the OP did not bother to put in example code, I wrote up the following:

p1 = ParametricPlot3D[{(3 + Cos[u]) Cos[v], (3 + Cos[u]) Sin[v], Sin[u]},
                      {u, -π, π}, {v, -π, π}, Lighting -> "Classic", Mesh -> None, 
                      PlotPoints -> 95, PlotStyle -> ColorData[97, 1]]

             ParametricPlot3D[{(3 + Cos[u]) Cos[v], (3 + Cos[u]) Sin[v], Sin[u]},
                              {u, -π, π}, {v, -π, π}, Mesh -> {{h}},
                              MeshFunctions -> {#3 &},  
                              MeshStyle -> Directive[AbsoluteThickness[5],
                                                     ColorData[97, 4]], 
                              PlotPoints -> 45, PlotStyle -> None]],
        {h, -1, 1, 1/10}]

I have deliberately omitted showing the output, so that you can evaluate and see for yourself what happens with this code.

  • $\begingroup$ Your last bit to this answer somehow reminds me of, “...left up to the reader.”, except that I would much rather have what you wrote, haha! How robust/smooth is Show when wrapped with something like Animate or Manipulate? Awesome answer as always, J.M.—I look forward to evaluating this myself later today :D $\endgroup$ – CA Trevillian Jun 5 '20 at 17:56
  • 1
    $\begingroup$ Show[]'s only job is to appropriately combine any Graphics[]/Graphics3D[] object fed to it, and set options for the final display if supplied. So, the quality of the final result is really dependent on the graphics objects fed to it. $\endgroup$ – J. M.'s ennui Jun 5 '20 at 18:00
  • $\begingroup$ Ah! Many thanks. I was mostly curious about things such as jittery animations & the-like, so that bodes well! Good deal. $\endgroup$ – CA Trevillian Jun 5 '20 at 18:02
  • 1
    $\begingroup$ +1 The animation is smoother with finer steps, e.g., {h, -1, 1, 1/100} and adding the option BoxRatios -> {1, 1, 0.4}] to the Show makes the Mesh travel clearer. $\endgroup$ – Bob Hanlon Jun 5 '20 at 18:54
  • $\begingroup$ Aha! That is simpler than I thought. So setting PlotStyle->None makes it compute just the Mesh, and I can still control how smooth the Mesh itself will be with PlotPoints. So not only does it speed up the process, I can also potentially make the Mesh more/less detailed than the rest of the plot. Sorry for not including an example, I'll keep that in mind next time (now you already wrote the important part of what I had). Thank you for a great quick answer! (for my working example ~60s-->~2s, and since two seconds are mostly the plot itself, it's really like \inf-->2s, hehe) Thanks! $\endgroup$ – OnDragi Jun 5 '20 at 20:13

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.