10
$\begingroup$

I'm trying to animate a torus being cut by a plane, so that as the plane enters the torus the part in front of the plane disappears (the idea is to show the cross section). That much I can do, but I can't seem to get the camera to behave. I'd like everything to stay the same size and position, but despite setting ViewVector, ViewAngle, and ViewVertical the scene becomes smaller as the animation progresses. Note that I chose the settings pretty arbitrarily. I am baffled as to why the camera view changes with these three options fixed.

Here is the code (I produce the frames in a table, and then export them for the animation).

Table[Show[
  ContourPlot3D[(1 - Sqrt[x^2 + (y + 1/2)^2])^2 + z^2 - 1/4 == 
    0, {x, -2, 2}, {y, -2, 2 - 2 t}, {z, -2, 2}, Mesh -> False], (*The torus*)
  ContourPlot3D[y == 2 - 2 t, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
   Mesh -> False, ContourStyle -> {White, Opacity[.5]}],         (*The plane*)
  Axes -> False, Boxed -> True, PlotRange -> All,
  ViewVector -> {{5 Sqrt[6], 10 Sqrt[6], 5 Sqrt[6]}, {0, 0, 0}}, 
  ViewAngle -> 3 Pi/50, ViewVertical -> {0, 0, 1}], {t, 0, 1, .5}]

And here is the result.

Torus cross sections

As you can see, the camera zooms out and seems to rotate slightly. Any idea how to fix this?

(Edited to add PlotRange -> All)

$\endgroup$
0

1 Answer 1

10
$\begingroup$
Table[Show[
  ContourPlot3D[(1 - Sqrt[x^2 + (y + 1/2)^2])^2 + z^2 - 1/4 == 
    0, {x, -2, 2}, {y, -2, 2 - 2 t}, {z, -2, 2}, Mesh -> False, 
   PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}],(*The torus*)

  ContourPlot3D[y == 2 - 2 t, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
   Mesh -> False, ContourStyle -> {White, Opacity[.5]}],(*The plane*)


  Axes -> False, Boxed -> True, 
  ViewVector -> {{5 Sqrt[6], 10 Sqrt[6], 5 Sqrt[6]}, {0, 0, 0}}, 
  ViewAngle -> 3 Pi/50, ViewVertical -> {0, 0, 1}], {t, 0, 1, .5}]

enter image description here

enter image description here

$\endgroup$
6
  • $\begingroup$ Very nice, thanks. But I don't suppose you can tell what I'm misunderstanding with my approach? $\endgroup$
    – smackcrane
    Commented Jun 28, 2012 at 20:07
  • 1
    $\begingroup$ @smackcrane The first element in the Show[] list determines the PlotRange ... $\endgroup$ Commented Jun 28, 2012 at 20:11
  • $\begingroup$ I was under the impression that PlotRange->All fixed that problem $\endgroup$
    – smackcrane
    Commented Jun 28, 2012 at 20:20
  • $\begingroup$ Why is your animation all in pink like an error box? $\endgroup$
    – Mr.Wizard
    Commented Jun 29, 2012 at 6:51
  • 1
    $\begingroup$ @smackcrane you can set the PlotRange as an option of Show but All is variable. If you use PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}} it will work. $\endgroup$
    – Mr.Wizard
    Commented Jun 29, 2012 at 6:55

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.