2
$\begingroup$

Here is a bit of code borrowed from Parametrize a circle as a tube?.

ParametricPlot3D[
 5 {Sin[u] Cos[v], Sin[u] Sin[v], Cos[u]} + {1, -4, 3}, {u, 0, 
  Pi}, {v, 0, 2 Pi},
 RegionFunction -> Function[{x, y, z}, y <= 0],
 AxesLabel -> {x, y, z}]

When you rotate an image in MATLAB, the azimuth and elevation appears in the lower left-hand corner, which you can then use in the view command in your code.

Does Mathematica have a similar tool? I really like to rotate the image until I get a view that I really like. Then I'd like some view some information that I can use in my code.

**Suggestion by Guess who it is: **

enter image description here

$\endgroup$
6
  • $\begingroup$ Apply Options[] to your 3D plot after spinning it around. $\endgroup$ – J. M.'s ennui May 23 '15 at 3:25
  • $\begingroup$ BTW: when tagging, please use the most relevant tag. If your question is more about, say, how to plot a derivative rather than the actual derivative, then the appropriate tag is plotting, not calculus-and-analysis. $\endgroup$ – J. M.'s ennui May 23 '15 at 3:29
  • $\begingroup$ @Guess who it is How do you apply Options[] to the 3D plot after spinning it around? I tried Options[%]. Not sure what you mean to do. $\endgroup$ – David May 23 '15 at 4:03
  • $\begingroup$ Something like Options[(* insert the actual 3D plot here *)]; spin the plot inside the Options[] around, and whenever you see something you like, Shift-Enter to see the viewing parameters, among other things. $\endgroup$ – J. M.'s ennui May 23 '15 at 4:26
  • $\begingroup$ Thanks. It worked! See my edit in my original post. Although, it might only be appropriate for the smaller image. $\endgroup$ – David May 23 '15 at 4:40
4
$\begingroup$

Perhaps this will be helpful in exploring. At the end of gif I am trying to illustrate you can select, copy and paste the desired option values.

pl = ParametricPlot3D[
   5 {Sin[u] Cos[v], Sin[u] Sin[v], Cos[u]} + {1, -4, 3}, {u, 0, 
    Pi}, {v, 0, 2 Pi}, RegionFunction -> Function[{x, y, z}, y <= 0]];
DynamicModule[{vp, va, vv, 
  vc}, {vp, va, vv, 
   vc} = {ViewPoint, ViewAngle, ViewVertical, ViewCenter} /. 
   AbsoluteOptions[pl];
 Panel[Column[{
    Show[pl, SphericalRegion -> True, ViewPoint -> Dynamic[vp], 
     ViewAngle -> Dynamic[va], ViewVertical -> Dynamic[vv], 
     ViewCenter -> Dynamic[vc]],
    Dynamic[
     Grid@Transpose[{{ViewPoint, ViewAngle, ViewVertical, 
         ViewCenter}, {vp, va, vv, vc}}]],
    Row[{"vcx", Slider[Dynamic[vc[[1]]], {0, 1}]}],
    Row[{"vcy", Slider[Dynamic[vc[[2]]], {0, 1}]}],
    Row[{"vcz", Slider[Dynamic[vc[[3]]], {0, 1}]}]
    }]]]

enter image description here

$\endgroup$
2
$\begingroup$

I use this idiom for this:

Defer[AbsoluteOptions][
 Graphics3D[Cuboid[]]]

Which just pre-heads the output so you don't have to type around the graphics object. I find that ViewPoint and ViewVertical are the two settings I need to recover the orientations I play around with:

Defer[{ViewPoint, ViewVertical} /. AbsoluteOptions[#] &][
 Graphics3D[Cuboid[]]]

To make this into a function:

viewSpec[g_] := Module[{f},
   f = Thread[{ViewPoint, ViewVertical} -> ({ViewPoint, ViewVertical} /. AbsoluteOptions[#])] &;
   Defer[f][g]];

viewSpec[Graphics3D[Cuboid[]]]

Here's one way to make a more native-like appearance (click on the button to copy to clipboard):

viewHUD[Graphics3D[all___]] := 
  Module[{vv = {0, 0, 1}, vp = {1.3, -2.4, 2}}, (*defaults from documentation*)
   Print[Dynamic[
     Module[{spec = {ViewVertical -> vv, ViewPoint -> vp}},
      Button[spec, CopyToClipboard[spec]; Beep[]]]]];

   Graphics3D[all, ViewVertical -> Dynamic[vv], ViewPoint -> Dynamic[vp]]];

viewHUD[Graphics3D[Cuboid[]]]

You can also stringify the specification and trim the surrounding curly braces before you CopyToClipboard so that you can paste them easier.

And by the way, there isn't really any way you would have known to go about these things in these ways. Some of these deeper things (like knowing you can Dynamize and therefore link the view settings in Graphics3D) is just from playing around and investigating them.

$\endgroup$
2
  • $\begingroup$ Probably, you intended to write ViewPoint -> vp instead of ViewVector -> vp $\endgroup$ – J. M.'s ennui May 23 '15 at 5:32
  • $\begingroup$ @Guesswhoitis. you're right ty. fixed. i am dyslexic with respect to mathematica 3D view specification parameter names. $\endgroup$ – amr May 23 '15 at 5:37
1
$\begingroup$

Try this:

     Manipulate[
        ParametricPlot3D[
         5 {Sin[u] Cos[v], Sin[u] Sin[v], Cos[u]} + {1, -4, 3}, 
      {u, 0, Pi}, {v, 0, 2 Pi}, 
        RegionFunction -> Function[{x, y, z}, y <= 0], 
        AxesLabel -> {x, y, z},
        ViewPoint -> 
   5 {Cos[θ] Sin[ϕ], Sin[θ] Sin[ϕ], Cos[ϕ]}],
     {θ, 0, 2 π, Appearance -> "Open"},
     {ϕ, 0, π, Appearance -> "Open"}]
$\endgroup$

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.