Message Boards Message Boards

0
|
10629 Views
|
9 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Force traditional XYZ axis layout while using Graphics3D?

Posted 5 years ago

While using Graphics3D I need to produce a traditional x-y-z labeled axis system. I need X, Y, and Z axis to intersect at "0", the Cartesian origin. What I get is the software interfering (perhaps it is an effort to make the graphics more readable): XYZ Not Intersecting At Origin

How do I force:

  • Axes intersect at 0;
  • X is left/right orientation;
  • Y is down/up orientation;
  • Z is out/in orientation.

EDIT: I did find AxesEdge and AxesOrigin, but have been unable to make it work as I was hoping. AxesEdge examples seem to only exist for "Automatic" or "None".

POSTED BY: Dan Stimits
9 Replies
Posted 5 years ago

Bingo! It is the offset from a corner of bounding box being different from center of bounding box which was changing things. I am going to read all I can on the bounding box.

Then I will do as you mention to add Arrow[] instead of the built in coordinate system. This makes sense. Thank you.

POSTED BY: Dan Stimits
Anonymous User
Anonymous User
Posted 5 years ago

I suggest making your own if you are still not where you need to be.

Axis can be controlled, as can be PlotRange (which tends to stabilize things not being optimally chosen, having a set plotrange). You can specify the axis options and how many tic marks to use and labeling too. But I admit there are many graphics options and what combination of these would make what you need "semi-permanent" i cannot say for sure.

Did you consider options changing? so even if you pick the lock of correct options it may not work in the future (or similarly fixing what wr considers a small change in plot options could for you be a huge burden to re-solve in another way - or even impossible). wr does "avoid doing that", but.

If it still does not work just use Arrow[] and make your own axis and optionally Line[] to make tick marks, Text[] for labels: that's all it is. Don't be afraid to make your own if it won't take long - Mathematica is made to be flexible.

POSTED BY: Anonymous User
Posted 5 years ago

Your questions

Is this what you get for a view when entering the code I just added?

Evaluated your code without any editing. My view is close to your last image. It seems to be from a camera slightly higher up compared with yours. And the axes labels (xyz) are not as big or bold as yours.

Should bounding box and geometry coordinate systems be the same for this case?

Yes, if ViewCenter is set to Automatic. See what follows further below.

Is this last image what I should expect from a view point of {0,0,-2}?

If I edit the code to ViewPoint->{0,0,-2} I get something completely different from your last image. But what I get is not what one would expect from looking directly along the Z-axis.

Are you using Mathematica under Linux?

No, I am on Windows 10.

Location of ViewCenter

ViewCenter is specified in Scaled coordinates. {0,0,0} corresponds to a corner of the bounding box. Center of bounding box has Scaled coordinates {0.5, 0.5, 0.5}. You get that with ViewCenter->Automatic. Its the default setting. Try that, then the view orientation might be more like the expected.

POSTED BY: Hans Milton
Posted 5 years ago

A shorter possibility than what I explain below is that the bounding box has a different coordinate system than the XYZ of the graphics (a rotation). So if what follows makes sense, then it is a bug. If what follows does not make sense, then it implies the "camera" view angle has a different coordinate system than the XYZ of the graphics. I'm tending towards the idea that it is a caching bug since when I originally entered this it did as expected, and results only failed after adding code and then removing code or editing code.

If this gets too long, just jump to the question at the end.

Take a very close look at the image following the text of my previous post. Search for "What this produces when Cone is not shown:", and then note the graphic this refers to. The bounding box is centered on {0,0,0}, meaning bounding box and actual coordinate system match for this case (bounding box and graphics should correspond 1:1). Note that this image is from slightly above and to the right of the bounding box center. This seems wrong since the code is from above and left (if they use the same coordinate system...or is my idea of -0.25 being "left" wrong?):

  ViewCenter -> {0, 0, 0},
  ViewPoint -> {-0.25, 0.25, 2},

In that same post with the original graphic, right at the top, I had to add an "EDIT" regarding the view:

EDIT: I noticed that my original view which should be from slightly above and left is now not what I thought it was. View should be from {-0.25,0.25,2} pointed directly at {0,0,0}. For a while the "plane only" demo was viewing this correctly. Now this is viewing from above and right (not left, which it should).

Originally I did see that image was with camera above and left (which is what an X coordinate of -0.25 would do) in terms of the graphics I saw prior to posting. Later on, using that same view point of {-0.25,0.25,2} pointed directly at {0,0,0} in a bounding box which is symmetric about the center of the coordinate system (the coordinate system center of the graphic and bounding box were the same without the cone), the camera view shifted to the positive X direction, and I didn't know why. Basically I had been commenting and uncommenting code to experiment, but upon going back to the original the view perspective never went back to viewing from above and to the left. The view from after having shifted things around when adding the cone was being preserved and did not go back to what it should be. The bounding box seems to mistakenly believe there is still more geometry to show where the cone no longer exists. Even after commenting out the cone the bounding box is being treated as if the cone is still there. The view is being cached for some reason and not refreshed upon edit.

Later on I changed the InfiniteLine to just Line from -1 to 1 along each axis and commented out the cone once more. This was to force bounding box to include -1 to 1 of each axis. This was done as an edit, not as new code. The result was that the view point and center remained to the upper right, not left, even though the bounding box was what I expected.

If you were to enter the code for the first time, then the display would be correct. Each time you edit such that bounding box changes, and then revert the edit, the view does not revert as other geometry is edited out. This became true even on new documents. The following should have a view centered on {0,0,0} of both axes and bounding box. The actual camera should be above and left. If you then uncomment the cone, then view should go to the right as the cone extends the total image. Following this, if you recomment the cone, then the view will not go back to the original form as it should (the cone goes away, but the bounding box changes from having added the cone originally does not go away). This seems to be a caching issue. This is what I see, and the view is wrong for an X coordinate of negative 0.25:

enter image description here

Don't know if it matters, but my 11.3 is running on Linux. I'd consider it possible that the cache mechanism differs on different operating systems. However, it looks like there is a simple cache directory mechanism on Linux, so maybe I have to delete the cache each time I edit.

Incidentally, if I run this code with ViewPoint (camera) at {0,0,2}, there is a definite rotation which I do not expect, and once again it says that either the bounding box coordinate system differs from the graphic, or else some bug is getting me (I still have "Show" in because I was expecting to add "Manipulate" later):

Show[
 Graphics3D[
   {
   RGBColor[1, 1, 0, 0.8],
   InfinitePlane [  {  {0, 0, 0}, {1, 0, 0}, {0, 1, 0}  } ],
   (*RGBColor[0.8,0.8,0.8,0.8],
      Cone[ {{1,1,0},{0,0,0}},Sqrt[2]
   ],*)
   {Thickness[0.025], Red, Line[{{-1, 0, 0}, {1, 0, 0}}]},
   {Thickness[0.025], Green, Line[{{0, -1, 0}, {0, 1, 0}}]},
   {Thickness[0.025], Blue, Line[{{0, 0, -1}, {0, 0, 1}}]},
   {PointSize[Large], Black, Point[{0, 0, 0}]}
   },
  Axes -> True,
  AxesLabel -> {
    Style["x", Bold, Black],
    Style["y", Bold, Black],
    Style["z", Bold, Black]
    },
  AxesOrigin -> {0, 0, 0},
  AxesEdge -> {{0, 0}, {0, 0}, {0, 0}},
  Boxed -> True,
  ViewProjection -> "Orthographic",
  ViewCenter -> {0, 0, 0},
  ViewPoint -> {-0.25, 0.25, 2},
  ViewVertical -> {0, 1, 0}
  ]
 ]

enter image description here

Is this what you get for a view when entering the code I just added? Should bounding box and geometry coordinate systems be the same for this case? Is this last image what I should expect from a view point of {0,0,-2}? Are you using Mathematica under Linux?

POSTED BY: Dan Stimits
Posted 5 years ago

Prior to adding the Cone the view point was as expected. After adding and removing the Cone, the view point never went back...the bounding box was now wrong.

Dan, I have 11.3 and 12 installed side by side. And in 11.3 I can not reproduce what you report about the bounding box not contracting when the Cone is commented out. Using your original code example.

  • No Cone: View centered at graphics origin
  • Add Cone: View center shifts to right and above the graphics origin
  • Remove Cone: View center returns to the graphics origin
POSTED BY: Hans Milton
Posted 5 years ago

Ok, I should have thought about the bounding box. Unfortunately though, it seems that I've also found a bug. It turns out that if I edit and then display where everything starts with just lines along the axes going from -1 to 1 (all graphics centered on 0,0,0), the ViewCenter and ViewPoint are honored. As soon as I add the Cone in a way that the bounding box shifts, then if I edit back to the original without the Cone, Mathematica's idea of the bounding box stays at the center of where the Cone had placed the center. Basically, Mathematica is failing to update/refresh the bounding box center after an edit; everything else updates correctly.

So this is also why I had the image of my first sample without a Cone display wrong (which is why I made the edit comment). Prior to adding the Cone the view point was as expected. After adding and removing the Cone, the view point never went back...the bounding box was now wrong.

I'm using 11.3, and don't have an update subscription, so I guess I'll have to live with the bug. I'm grateful though that you pointed out the use of bounding box! I think I need to research more on ways to control this or I won't be able to place two graphics side by side for a proper comparison.

Btw, the reason I had Show[] is because originally I had Manipulate[]. I'd removed Manipulate[] because I only wanted one view.

POSTED BY: Dan Stimits
Posted 5 years ago

Both ViewCenter and ViewPoint relates to a coordinate system that has its origin in the center of the bounding box, not the graphics coordinate system origin.

One, rather rough, way to get around it is to add invisible points. To force the bounding box to be centered around the graphics origin (or wherever you want the box center to be).

Graphics3D[
    {
     RGBColor[1, 1, 0, 0.8], InfinitePlane[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}],
     RGBColor[0.8, 0.8, 0.8, 0.8], Cone[{{1, 1, 0}, {0, 0, 0}}, Sqrt[2]],
     Thickness[0.025], Red, InfiniteLine[{0, 0, 0}, {1, 0, 0}],
     Green, InfiniteLine[{0, 0, 0}, {0, 1, 0}],
     Blue, InfiniteLine[{0, 0, 0}, {0, 0, 1}],
     PointSize[Large], Black, Point[{0, 0, 0}],
     Opacity[0], Point[Tuples[{-2, 2}, {3}]]
    },
    Axes -> True,
    AxesLabel -> {Style["x", Bold, Black], Style["y", Bold, Black], Style["z", Bold, Black]},
    AxesOrigin -> {0, 0, 0},
    AxesEdge -> {{0, 0}, {0, 0}, {0, 0}}, Boxed -> False,
    ViewProjection -> "Orthographic",
    ViewCenter -> {0, 0, 0},
    ViewPoint -> {-0.25, 0.25, 2},
    ViewVertical -> {0, 1, 0}
 ]

By the way, there is no need to wrap a single Graphics3D in Show

POSTED BY: Hans Milton
Posted 5 years ago

EDIT: I noticed that my original view which should be from slightly above and left is now not what I thought it was. View should be from {-0.25,0.25,2} pointed directly at {0,0,0}. For a while the "plane only" demo was viewing this correctly. Now this is viewing from above and right (not left, which it should).

Even with AxesOrigin I'm still running into some related issues. At this point I'm trying to get that AxesOrigin to be viewed from a particular angle regardless of the graphics present. I'll illustrate, where this draws the axis as I want it to be, and emphasizes the X/Y/Z via thick Red/Green/Blue lines on the axes. The other content is a plane with XY orientation. Then I'll add a cone to this by uncommenting the Cone in the code listed below, and you'll see the orientation change despite specifying both ViewPoint and ViewCenter. The first image is from leaving the Cone commented out, the second image is after uncommenting. The view changes when it should not.

The code, with Cone commented out which does what I expect:

Show[
 Graphics3D[
   {
    RGBColor[1, 1, 0, 0.8],
    InfinitePlane [  {  {0, 0, 0}, {1, 0, 0}, {0, 1, 0}  } ],
    (*RGBColor[0.8,0.8,0.8,0.8],
   Cone[ {{1,1,0},{0,0,0}},Sqrt[
   2] ],*)
    {Thickness[0.025], Red, 
    InfiniteLine[{0, 0, 0}, {1, 0, 0}]},
    {Thickness[0.025], Green, InfiniteLine[{0, 0, 0}, {0, 1, 0}]},
    {Thickness[0.025], Blue, InfiniteLine[{0, 0, 0}, {0, 0, 1}]},
    {PointSize[Large], Black, Point[{0, 0, 0}]}
   },
  Axes -> True,
  AxesLabel -> {
    Style["x", Bold, Black],
    Style["y", Bold, Black],
    Style["z", Bold, Black]
    },
  AxesOrigin -> {0, 0, 0},
  AxesEdge -> {{0, 0}, {0, 0}, {0, 0}},
  Boxed -> False,
  ViewProjection -> "Orthographic",
  ViewCenter -> {0, 0, 0},
  ViewPoint -> {-0.25, 0.25, 2},
  ViewVertical -> {0, 1, 0}
  ]
 ]

What this produces when Cone is not shown:

enter image description here


After uncommenting the Cone, the view point changes and should not:

enter image description here

Notice that ViewCenter is told to look directly at {0,0,0}, and ViewPoint should always be from slightly above and left with positive Z going into the screen/paper. Instead, the ViewPoint is altered and forced away from explicitly set coordinates. My earlier failures seem to be partly related to this. Setting AxesOrigin was failing in some cases, and apparently this may be why (the view was changing in ways the AxesOrigin couldn't accomodate). For this case AxesOrigin is now closer to doing as expected, but the view changes.

View used to contain an approximate volume bounded by a bit more than one unit left/right/up/down/in/out from {0,0,0}, but adding the cone changed the viewing volume and shifted everything. Can I force view to about 1.1 units left/right/up/down/in/out from center so that my ViewPoint won't be forced somewhere other than where I specified? I think if I can force the viewed volume to stay constant, then I can add or remove components without everything shifting around.

POSTED BY: Dan Stimits

Try the option:

AxesOrigin -> {0, 0, 0}
POSTED BY: Henrik Schachner
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