6
$\begingroup$

If I run code

Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}]

the output is

enter image description here

After rotating (by mouse click and drag) the output in some direction, and run the same code again

Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}]

then the output becomes

enter image description here

Again, rotate the output in some direction, and run the same code

Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}]

then the output becomes

enter image description here

I knew that with ViewPoint option, Mathematica tries to fix 'a kind of view property'. The code stated above, will not generate graphics like

enter image description here

But also I knew that it is not enough to fix the view completely, with ViewPoint option only.

How can I completely fix the view ? For example, How can I generate

enter image description here

from a certain code, with 100% assurance, regardless of the state (what I've done so far since starting mathematica program) of Mathematica ?

$\endgroup$
3
  • 1
    $\begingroup$ The FE is clever(ish) about how it handles stuff like this. If it sees a following Output cell with a Graphics expression it tries to preserve the options that expression currently has. That's what you're running into. Just delete the cell if it's an issue. $\endgroup$
    – b3m2a1
    Aug 27 '19 at 21:29
  • 2
    $\begingroup$ try (1) setting an explicit value for ViewVertical and (2) adding the option PreserveImageOptions ->True. E.g., try if Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}, ViewVertical -> {-0.3, 0.6, 0.7}, PreserveImageOptions -> True] works. $\endgroup$
    – kglr
    Aug 27 '19 at 21:39
  • 2
    $\begingroup$ @b3m2a1 Too clever I'd say! $\endgroup$
    – Chris K
    Aug 27 '19 at 22:09
6
$\begingroup$

Set an explicit value for ViewPoint and for ViewVertical.

Add the option PreserveImageOptions -> True if you want to preserve other options (such as ImageSize) set interactively, PreserveImageOptions -> False if you want them to revert to the original values after interactive changes:

Graphics3D[Cuboid[], 
 ViewPoint -> {1, 1, 1}, 
 ViewVertical -> {0.5, 0, 1},
 PreserveImageOptions -> True]

enter image description here

Graphics3D[Cuboid[], 
 ViewPoint -> {1, 1, 1}, 
 ViewVertical -> {0.5, 0, 1},
 PreserveImageOptions -> False]

enter image description here

$\endgroup$
2
3
$\begingroup$

We can find the appropriate options from this input:

Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}] // AbsoluteOptions

(*{AlignmentPoint -> Center, AspectRatio -> Automatic, 
AutomaticImageSize -> False, Axes -> False, AxesEdge -> Automatic, 
AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> {}, 
Background -> None, BaselinePosition -> Automatic, BaseStyle -> {}, 
Boxed -> True, BoxRatios -> {1., 1., 1.}, BoxStyle -> {}, 
ClipPlanes -> None, ClipPlanesStyle -> Automatic, 
ColorOutput -> Automatic, ContentSelectable -> Automatic, 
ControllerLinking -> Automatic, ControllerMethod -> Automatic, 
ControllerPath -> Automatic, CoordinatesToolOptions -> Automatic, 
DisplayFunction -> Identity, Epilog -> {}, FaceGrids -> None, 
FaceGridsStyle -> {}, FormatType -> TraditionalForm, 
ImageMargins -> 0., ImagePadding -> All, ImageSize -> Automatic, 
ImageSizeRaw -> Automatic, LabelStyle -> {}, Lighting -> Automatic, 
Method -> Automatic, PlotLabel -> None, 
PlotRange -> {{0., 1.}, {0., 1.}, {0., 1.}}, 
PlotRangePadding -> Automatic, PlotRegion -> Automatic, 
PreserveImageOptions -> Automatic, Prolog -> {}, 
RotationAction -> "Fit", SphericalRegion -> False, 
Ticks -> Automatic, TicksStyle -> {}, TouchscreenAutoZoom -> False, 
ViewAngle -> Automatic, ViewCenter -> {0.5, 0.5, 0.5}, 
ViewMatrix -> Automatic, ViewPoint -> {1., 1., 1.}, 
ViewProjection -> Automatic, ViewRange -> All, 
ViewVector -> Automatic, ViewVertical -> {0., 0., 1.}}*)  

Then, the desired & appropriate parameters may be set:

Graphics3D[Cuboid[], ViewPoint -> {1, 1, 1}, 
ViewCenter -> {0.5`, 0.5`, 0.5`}, ViewVertical -> {0.`, 0.`, 1.`}]

Use AbsoluteOptions to determine the definitive options for the current viewpoint you have outputted. From here, copy and paste these into your desired definition. What I mean by this is that you take your Cuboid output, defined with the noted Viewpoint, and then type //AbsoluteOptions after the output. Evaluate this and use the output to be applied to your definition.

I have no experience with the answer of user @kglr, however, I can say with absolute certainty and confidence that if you find a viewpoint you like, perform the above procedure and you will have the desired output every time you evaluate it, just as you need/ask for here.

Hope this helps!

$\endgroup$
1
  • 1
    $\begingroup$ Thank you for AbsoluteOptions! I didn't know that. $\endgroup$
    – imida k
    Aug 28 '19 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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