5
$\begingroup$

Here's a simple example of using Manipulate to interactively change the viewer's point-of-view for a 3D graphics object:

Manipulate[
 Framed[
  Graphics3D[{PolyhedronData["Dodecahedron", "Faces"]},
   ViewPoint -> 
    3.0 {Cos[\[Theta]] Cos[\[Phi]], Sin[\[Theta]] Cos[\[Phi]], 
      Sin[\[Phi]]},
   ViewAngle -> 0.5,
   ImageSize -> 200
   ],
  FrameStyle -> LightGray],
 {{\[Theta], 1.0}, 0, 2 \[Pi], Appearance -> "Labeled"},
 {{\[Phi],   0.5}, 0,   \[Pi], Appearance -> "Labeled"}
 ]

The resulting widget looks like this:

Mathematica graphics

Moving the widget's sliders does rotate the point-of-view, but a similar effect can be achieved by "directly" rotating the 3D image (i.e. "dragging" over the object's image with the cursor), like one can do with any other 3D graphics object in Mathematica. If one does this to the 3D object displayed within the widget, then the slider controls stop working.

How can I modify this widget so that such direct manipulations, instead of disabling the sliders, actually update their values?

(The net effect would be to have two complementary ways to modify the point-of-view: just as the sliders give control over the image's point-of-view, any modification of this point-of-view by some other channel should be instantaneously reflected in the values of the sliders.)

$\endgroup$

1 Answer 1

5
$\begingroup$

The second argument to Dynamic is the key. The code does not keep track of ViewVertical, which will change as the graphics are rotated by the mouse. See the references at the end for some of the answers where I used this technique.

Manipulate[
 Framed[Graphics3D[{PolyhedronData["Dodecahedron", "Faces"]}, 
   ViewPoint -> 
    Dynamic[3.0 {Cos[θ] Cos[ϕ], Sin[θ] Cos[ϕ], Sin[ϕ]},
      (θ = Mod[ArcTan[#[[1]], #[[2]]], 2 Pi];
       ϕ = ArcTan[Norm[#[[1 ;; 2]]], #[[3]]]) &],
   ViewAngle -> 0.5, ImageSize -> 200], FrameStyle -> LightGray],
 {{θ, 1.0}, 0, 2 π, Appearance -> "Labeled"},
 {{ϕ, 0.5}, -π/2, π/2, Appearance -> "Labeled"},
 TrackedSymbols :> None]

I did something similar here: Synchronizing the camera view of multiple Image3D panels within a Manipulate interface

See also my answer to Transparent Cylinder with Dashed Edges only, in which the control uses

ViewVector -> Dynamic[viewVec], ViewVertical -> Dynamic[vert]

to interact with the rotation of 3D graphics.

In How can I create a fountain effect?, I used a dynamic ViewPoint and ViewVertical to calculate the arc of water spraying out of a hose.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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