After showing some graphics objects with Graphics3D you can move the image by interactively changing the ViewPoint option, or by simply dragging, resizing or rotating the image. Does the latter change the ViewPoint internally? Can this be queried?
For example.
By program:
Manipulate [
viewpoint->{x,y,y};
Graphics3D[Cuboid[],ViewPoint->viewpoint],
,{x,-25,25}
,{y,-25,25}
,{z,-25,25}]
By 'mouse'
Graphics3D[
Cuboid[]]
Effects of by program above can be simulated. Can I 'query' effect on ViewPoint as a result of i.e. the rotation?
Try this code:
gr = Graphics3D[Cuboid[], SphericalRegion -> True, Boxed -> False]
(* this is one way to extract the values: *)
vp = ViewPoint /. AbsoluteOptions[gr]
vv = ViewVertical /. AbsoluteOptions[gr]
(* the following is completely another way. try rotating the output of this: *)
Row[
{Show[gr, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv]],
Show[gr, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv]]}
]
(* values will dynamically update here: *)
Dynamic[vp]
Dynamic[vv]
Hope this helps come up with a solution to your problem.
EDIT: You can also just copy and paste an already mouse-rotated graphic into ViewPoint /. Options[...]
Here is enhanced version of the code by Szabolcs. The main difference is that usage of DynamicModule
allows to avoid pink background of Graphics3D
which indicates an error due to undefined symbols vp
and vv
. This output works right even after saving the notebook and restarting Mathematica without re-evaluating the code!
gr = Graphics3D[Cuboid[], SphericalRegion -> True, Boxed -> False];
DynamicModule[{vp = ViewPoint /. AbsoluteOptions[gr],
vv = ViewVertical /. AbsoluteOptions[gr]},
Column[{Row[
Table[Show[gr, ViewPoint -> Dynamic@vp,
ViewVertical -> Dynamic@vv], {3}]], Dynamic@vp, Dynamic@vv}]]
This behavior is well-documented: "Values of local variables in a DynamicModule
are by default automatically saved when a notebook containing the DynamicModule
is saved, so that these values in effect persist across sessions of Mathematica".
It can be done manually by selecting the cell containing your graphics and giving the menu command Cell > Show Expression
(ctrl-shift-E). The graphics are replaced with the corresponding cell expression and the ViewPoint
option setting is visible in plain text.
Another possibility is:
Cases[ NotebookGet[EvaluationNotebook[]], (ViewPoint -> e_) -> e, Infinity]
(* Out[51]= {{1.73834, -2.29064, 1.78357}, {0.651043, -0.128738,
3.31807}, {-3.03116, -1.38541, 0.585417}} *)
This finds all occurrences of ViewPoint in your notebook and outputs their coordinates. You'll probably know which one you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With