69
$\begingroup$

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.

$\endgroup$
6
  • 4
    $\begingroup$ See for example this answer by Yu-Sung Chang $\endgroup$
    – Heike
    Commented May 9, 2012 at 11:28
  • $\begingroup$ Would you mind editing in code that can be copied (not just screenshots)? $\endgroup$
    – Yves Klett
    Commented May 9, 2012 at 11:28
  • $\begingroup$ @YvesKlett sorry, didn't think the code was worth adding ... $\endgroup$
    – cormullion
    Commented May 9, 2012 at 11:38
  • 3
    $\begingroup$ Nah, I´d say it is always worth prepping the question as far as possible to attract and encourage answers. $\endgroup$
    – Yves Klett
    Commented May 9, 2012 at 11:42
  • 1
    $\begingroup$ BTW, the excellent upload palette works wonders here... $\endgroup$
    – Yves Klett
    Commented May 9, 2012 at 11:44

3 Answers 3

69
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ Should this technique work with ParametricPlot3D, etc? $\endgroup$
    – JohnD
    Commented Nov 15, 2012 at 1:51
  • 1
    $\begingroup$ @texasAUtiger yes it should... just about for any function using the ViewPoint option. $\endgroup$
    – Yves Klett
    Commented Nov 15, 2012 at 7:37
  • $\begingroup$ It does not seem to work with Show though $\endgroup$ Commented Apr 17, 2020 at 16:52
57
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – BoLe
    Commented Apr 7, 2013 at 10:38
23
$\begingroup$

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.
$\endgroup$
5
  • $\begingroup$ 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)? $\endgroup$
    – cormullion
    Commented May 9, 2012 at 12:15
  • 1
    $\begingroup$ Plus we learn the german translation for "extract" ;-) $\endgroup$
    – Yves Klett
    Commented May 9, 2012 at 12:18
  • $\begingroup$ @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). $\endgroup$ Commented May 9, 2012 at 12:22
  • 5
    $\begingroup$ 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). $\endgroup$
    – BoLe
    Commented Apr 7, 2013 at 10:46
  • $\begingroup$ You may find it easier to refer to your graphic by sheet output number, e.g., ExtrahiereViews[%36] $\endgroup$ Commented Mar 17, 2021 at 17:48

Your Answer

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

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