69

Is there a way to find out the current viewing parameters of a 3D view? What often happens is that I create a view, for example:

Graphics3D[{Blue, Cuboid[], Yellow, Sphere[]}, Boxed -> False]

first view

and then spend some time adjusting it using the mouse to pan, zoom, and rotate it:

second view

Now I'd like to know what those settings (view point, etc.) are, so that they can be integrated as defaults into the next edit. It looks like an easy problem but I can't find out how to do it. At the moment there's a lot of trial and error involved.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
cormullion
  • 24,243
  • 4
  • 64
  • 133

3 Answers3

67

You can dynamically extract ViewPoint and others like this (also useful for synchronization of different plots etc.):

vp = Options[Graphics3D, ViewPoint][[1, 2]];

Graphics3D[Cuboid[], ViewPoint -> Dynamic[vp]]

Mathematica graphics

This value is now constantly updated:

Dynamic[vp]

{1.3, -2.4, 2.}

This seem also to work fine with other functions that use the ViewPoint option. Below, ViewPoint and ViewVertical are in sync for both objects:

{vp, vv} = Options[Graphics3D, {ViewPoint, ViewVertical}][[All, 2]];

Grid[{{Graphics3D[Cuboid[], ViewPoint -> Dynamic[vp], 
    ViewVertical -> Dynamic[vv]], 
   ParametricPlot3D[{Cos[u], Sin[u] + Cos[v], Sin[v]}, {u, 0, 
     2 Pi}, {v, -Pi, Pi}, ViewPoint -> Dynamic[vp], 
    ViewVertical -> Dynamic[vv]]}}]

Mathematica graphics

Yves Klett
  • 15,383
  • 5
  • 57
  • 124
57

Perhaps the most easiest way is to use Options

  1. Graphics3D[Cuboid[]] to plot the figure;
  2. Manipulate the figure at your will,such as zooming in, rotate and so on;
  3. Copy the manipulated figure and add //Options after it, and press enter. You will get the options of the manipulated figure.

enter image description here

rm -rf
  • 88,781
  • 21
  • 293
  • 472
yulinlinyu
  • 4,815
  • 2
  • 29
  • 36
  • I've put this to good use. I set variable view with a rotated-and-shrinked copy-pasted graphics gr with postfix extraction: view = gr // Options[#, {ViewPoint, ViewVertical}] & and then use Sequence @@ view in the cell that generated gr. – BoLe Apr 07 '13 at 10:38
23

The following function may be helpful:

ExtrahiereViews[ll_]:=
  Flatten[Union[Extract[ll,Position[ll,#]]&/@
  {ViewPoint->_, ViewCenter->_, ViewVertical->_,
   ViewAngle->_, ViewVector->_, ViewRange->_}]];  

How to do:

  1. Enter ExtrahiereViews[] in a cell below the graphic.
  2. Move the graphic to your liking.
  3. Set the cursor between the brackets of ExtrahiereViews.
  4. Make a "Copy output from above" (CtrlShiftL) and evaluate. You'll get the values.
rm -rf
  • 88,781
  • 21
  • 293
  • 472
Peter Breitfeld
  • 5,182
  • 1
  • 24
  • 32
  • Thanks - I can't get it working yet, but thanks nonetheless, still working on it. Do you mean copy the graphic into the place where the ll_ is? Then what happens to the ll? Also, should I remove the semicolon? And by Copy output from above do you mean "Insert>Output From Above" (command-shift-L on Mac)? – cormullion May 09 '12 at 12:15
  • 1
    Plus we learn the german translation for "extract" ;-) – Yves Klett May 09 '12 at 12:18
  • @cormullion 1.) If you don't move, rotate, ... the grahphics with the mouse, the output will be an empty list. 2.) Yes, you have to Ctrl+Shilt+L the graphcs between the [ ]. The ll used in the definition will then be replaces by the graphic (which is a mathematica object like any other). – Peter Breitfeld May 09 '12 at 12:22
  • 5
    This is how I do it now, thanks. Function defined shorter: ExtrahiereViews[ll_] := Options[ll, {ViewPoint, ViewVertical}] (will extract only two options I personally need). – BoLe Apr 07 '13 at 10:46
  • You may find it easier to refer to your graphic by sheet output number, e.g., ExtrahiereViews[%36] – Tim Sylvester Mar 17 '21 at 17:48