Skip to main content

graphics3d - Extract current viewing parameters from a 3D view?


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.



Answer



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


Comments