Message Boards Message Boards

Understanding Graphics3D's view options: the intuitive way

Graphics3D with anchored rotation axis

Attachments:
POSTED BY: Silvia Hao
10 Replies

Sometimes I read the manual and think "Wow, this doesn't make sense, not intuitive. Vectors are points?". But your explanation helped me fix the test case:

obj = {Cos[#/50 Pi], Sin[#/50 Pi], 0} & /@ Range[110];
viewPt = 2 {1 + Sin[#/20 Pi], 0, Cos[#/20 Pi]} & /@ Range[40];
viewVec = With[{tan = #[[3]] - #[[1]] & /@ 
      RotateRight[Partition[viewPt, 3, 1, 1]]}, 
   Divide[# - 2 Cross[#, {0, 1, 0}] & /@ tan, 5]];
viewNorm = Cross[#, {0, 1, 0}] & /@ viewVec;

gOBJ = {
   Darker@Red, Tube[{0, 0, 1/2} + # & /@ obj, 1/10],
   Darker@Blue, Tube[{0, 0, -1/2} + # & /@ obj, 1/10],
   Blend[{Orange, Brown}], Sphere[{2, 0, 0}],
   Blend[{Brown, Yellow}], Tube[obj, 1/2],
   Black, 
   Sphere[#/2 + {1, 0, 0}, 1/10] & /@ 
    viewPt[[{-7, -5, -1, 5, 13, 19, 23, 25}]]
   };

Graphics3D[{
  Red, MapThread[Arrow[{#1, #1 + #2}] &, {viewPt, viewVec}],
  Blue, MapThread[Arrow[{#1, #1 + #2}] &, {viewPt, viewNorm}],
  gOBJ}, ViewVertical -> {0, 0, 1}, Boxed -> False, 
 ViewPoint -> 3 {0, 1, 1}] 

model

ListAnimate[Graphics3D[gOBJ,
    ViewVector -> {viewPt[[#]], viewPt[[#]] + viewVec[[#]]},
    ViewVertical -> viewNorm[[#]],
    ViewAngle -> Pi/3, Boxed -> False] & /@ Range[40]]

Through the hoop

Turns out ViewVertical needs to be set, see also this wikipedia article on Frenet-Serret perspective. This is still along way from having a meebits character walking around the surface of an elliptic curve and looking around at the scenery.

POSTED BY: Brad Klee

Silvia, you are probably right about that change in Version 12, according to the change log:

Major OS integration updates to Mac and Linux notebook interfaces using the 64-bit Cocoa API and Qt 5, respectively, with the Linux interface no longer requiring a supporting X server

Good, hope to move on from that error soon.

Your credentials appear impressive, so it looks like you could probably accept a challenge from my dissertation. If you want, see Fig. 2.13:

screen cap

Is it possible to put in a camera (where projection to $\mathbb{R}^3$ is reasonably finite) that zooms around the surface, showing its features from different perspectives? I'm hoping for something like this:

obj = {Cos[#/50 Pi], Sin[#/50 Pi], 0} & /@ Range[110];
viewPt = 2 {1 + Sin[#/10 Pi], 0, Cos[#/10 Pi]} & /@ Range[20];
viewVec =   With[{tan = #[[3]] - #[[1]] & /@ 
      RotateRight[Partition[viewPt, 3, 1, 1]]},
   Divide[# - Cross[#, {0, 1, 0}] & /@ tan, 5]];

Graphics3D[{Blend[{Brown, Yellow}], Tube[obj, 1/2], Red, 
  MapThread[Arrow[{#1, #1 + #2}] &, {viewPt, viewVec}]},
 ViewVertical -> {0, 0, 1}, Boxed -> False, ViewPoint -> 3 {0, 1, 1}]

camera path

But the animation doesn't look anything like I would expect it to:

ListAnimate[Graphics3D[{Blend[{Brown, Yellow}], Tube[obj, 1/2]},
    ViewPoint -> viewPt[[#]], ViewVector -> viewVec[[#]],
    ViewAngle -> Pi/4] & /@ Range[20]]

fail image

There's plenty of vector space to play around with inventive angles, but the options so far are not very intuitive, agree with you.

POSTED BY: Brad Klee

Hi Brad, I'm not sure I fully understand the view config you want, but I noticed in your code MapThread[Arrow[{#1, #1 + #2}] &, {viewPt, viewVec}] , which might not be doing what you meant for.

ViewPoint is the position of the camera in a scaled coordinate system, while ViewVector is either the position of the camera or a pair of positions corresponding to ViewPoint and ViewCenter, BUT either way they're in the "absolute" (or non-scaled) coordinate system. So adding an absolute vector to a scaled position does not give immediately meaningful result.

Also, if we are using explicit ViewVector option in Graphics3D, then ViewPoint won't affect the result, as according to the documentation:

Explicit settings for ViewVector override settings for ViewPoint.

POSTED BY: Silvia Hao
Posted 2 years ago

Silvia's exploration is a common problem for all of us. The technical setting in details of Wolfram functions are always puzzles for users from old version to new version.

So, I dared not to rotate the camera; I usually rotate the object or model.

POSTED BY: Frederick Wu

Hopefully my post encourages you enough to rotate the camera now. :)

POSTED BY: Silvia Hao

The "jittery issue" is a problem with Mathematica, possibly having a low level dependency on operating system, see also this earlier thread.

You are right about SphericalRegion being a smart option to set, but why should I have to if I've already entirely bounded the content by a great circle? It does fix the "zitterbewegung":

enter image description here

In user land I would expect this output, without jitter, whether or not I set SphericalRegion.

Just to show you how ugly this issue can get, here's another failed call I came up with working on the Penrose tiling thread. Obviously this would not be good to send to twitter:

penrose jitter

When I was making this I'm sure that I changed to zooming camera to hide "extra entropy $\Delta$". To make it more obvious, I use the following function:

JitterTest[path_, file_] := Export[  path <> "JitterTest" <> file,
  Map[ImageSubtract @@ # &,   Partition[Import[path <> file], 2, 1]],
  "AnimationRepetitions" -> \[Infinity]]

jitter test

The problem, I guess, is with rasterization from vectors. There should be no noise interior to edge growth, and definitely no difference whatsoever in repeated frames at the end of the animation. If this error can't be trackbacked to the source and fixed on my end, then this is another reason, contra Jon McCloone, that Wolfram Language is not like open source. Especially if it ultimately has to do with Linux.

In last Weekend's thread about Taking the Autoglyphs by Root Pulling, you can see the chosen vector views use Polygon[] rather than Line[]. The reason for this choice is that I noticed similar problems and overlap inconsistencies with Line[]. The best solution I can think of presently is just to rasterize vector objects then ReplacePart them into a data array and output using Image[], as I did for the second bitmap view.

Ultimately when displaying to a screen bitmapping is always an issue. Even if we finally start to get some weird machines or weird gadgets with hexel displays (hexagonal tiling) rather than pixel displays (square tiling), bitmapping will still be an issue.

Another interesting page I found in the manual is How To | Connect a Gamepad. The idea for camera control on isometric view strategy game is clicking $L$ or $R$ shoulder buttons would cause a smooth rotation between one of four symmetrically equivalent, fixed viewpoints. Then arrows and letters can be used for scanning and selecting, menu navigation, whatever, etc...

Thanks again for the extra Option, nice knowledge you have.

--Brad

POSTED BY: Brad Klee

Hi Brad, I tried your Penrose tiling example on 12.3 for Windows 10 and recorded ListAnimate's result on my screen with an external camera. I think the testing result on my side is "pixel-perfect". Please check attached notebook for detail.

However, I do remember seeing the jittery issue on certain older Mathematica version. (I can't really remember it, maybe 11?) As my personal understanding, since version 12, there has been some change in FrontEnd in order to support 4K display, which might be related to this kind of issues. I guess they are likely OS-related.

POSTED BY: Silvia Hao

Hi Silvia, nice post. Thought to add a note, since I've been on this topic lately.

Usually setting ViewVertical & ViewPoint is enough to get a good result. ViewVertical defines a directed line in space, and ViewPoint a point (obviously). Looking from the point there is one rotational degree of freedom, which is then fixed to the vector of ViewVertical. Perspective can be controlled by taking near or far ViewPoints, with limit to infinity approaching ViewProjection->"Orthographic" (?). The problem is with bounding box. Using some of the previous chess assets:

glist1 = Show[GameState[TwoKnights], 
     Graphics3D[{Black, Sphere[{0, 0, 2}],
       Sphere[RotationMatrix[Pi/50 #, {0, 0, 1}].{0, 64, 0}] & /@ 
        Range[100]}],
     ViewPoint ->  100 ({Sqrt[2] Cos[Pi/50 *#], Sqrt[2] Sin[Pi/50 *#], 1}),
     Boxed -> True, ViewVertical -> {0, 0, 1}, 
     PlotRange -> {{-65, 65}, {-65, 65}, {-2, 16}},
     ImageSize -> 500] & /@ Range[0, 100];
ListAnimate[glist1]

Two Knights Error

This is not what we want, and setting Boxed->False does not change much. According to stack exchange, there is another option to set "ShrinkWrap"?? Anyways, here's an improved rotation:

glist2 = Show[GameState[TwoKnights], 
     Graphics3D[{Black, Sphere[{0, 0, 2}],
       Sphere[RotationMatrix[Pi/50 #, {0, 0, 1}].{0, 64, 0}] & /@ 
        Range[100]}],
     Boxed -> False, Method -> {"ShrinkWrap" -> True},
     ViewPoint -> 100 ({Sqrt[2] Cos[Pi/50 *#], Sqrt[2] Sin[Pi/50 *#], 1}),
     ViewVertical -> {0, 0, 1}, 
     PlotRange -> {{-65, 65}, {-65, 65}, {-2, 16}},
     ImageSize -> 500] & /@ Range[0, 100];
ListAnimate[glist2]

Two Knights Okay

This looks much better, though the animation still has a bit of jitter. If I were to mask out the black spheres on the boundary, probably it would look slightly more smooth.

POSTED BY: Brad Klee

Hi Brad, nice post there!

Regarding the automatic resizing in your example, I guess it could be eliminated by either specifying a fixed ViewAngle, or by using SphericalRegion -> True (maybe along with RotationAction option). My feeling is the SphericalRegion is smarter, but appropriate ViewAngle is probably works better for your jittery issue. Regarding "ShrinkWrap", I think it used to be "hidden", but it's now a documented option! :)

Indeed I'm planning to build a 3D viewer inside the FrontEnd. It's not for a particular scene, but hopefully works as a general viewer and pre-rendering camera editor. Right now my plan is using Graphics3D with some dynamic mechanism under the curtain, which will only be used to generate camera settings for rendering, but leaving the scene edit functionality to plain WL code.

POSTED BY: Silvia Hao

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract