Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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)

share|improve this question

migrated from stackoverflow.com Jun 28 '12 at 21:32

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

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

share|improve this answer
    
Very nice, thanks. But I don't suppose you can tell what I'm misunderstanding with my approach? –  smackcrane Jun 28 '12 at 20:07
1  
@smackcrane The first element in the Show[] list determines the PlotRange ... –  belisarius Jun 28 '12 at 20:11
    
I was under the impression that PlotRange->All fixed that problem –  smackcrane Jun 28 '12 at 20:20
    
Why is your animation all in pink like an error box? –  Mr.Wizard Jun 29 '12 at 6:51
    
@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. –  Mr.Wizard Jun 29 '12 at 6:55
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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