2

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

David
  • 14,883
  • 4
  • 44
  • 117

3 Answers3

5

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

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
2

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.

amr
  • 5,487
  • 1
  • 22
  • 32
1

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"}]
LCarvalho
  • 9,233
  • 4
  • 40
  • 96
David G. Stork
  • 41,180
  • 3
  • 34
  • 96