Three-Dimensional Mathematica Graphics (Section 5.2)

Extract from Mathematica Graphics: An Intensive Tutorial

by Tom Wickham-Jones

This HTML document is based on Mathematica Graphics: An Intensive Tutorial by Tom Wickham-Jones. It was adapted by Martin Kraus for non-commercial use.

Mathematica and MathLink are registered trademarks, and MathReader, MathSource and 3-Script are trademarks of Wolfram Research, Inc.

All other product names mentioned are trademarks of their producers.

Copyright 1992 by Wolfram Research, Inc.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder.

5.2 Three-Dimensional Coordinates

Now we shall look at the parts of the coordinate system transformation which are particular to rendering of three-dimensional objects.

5.2.1 BoxRatios

The PlotRange is determined as the first stage of processing a list of primitives. This determines the box into which the primitives will be drawn. This also is the box drawn with the Boxed option. The ratios of the lengths of the sides of this box are controlled with the option BoxRatios. This is the three-dimensional analog of the AspectRatio.

This shows a cubical image since the ratios of the box are all the same. In[9]:= Show[Graphics3D[Cuboid[{0, 0, 0}, {1, 2, 5}], BoxRatios -> {1, 1, 1}]]
Out[9]= - Graphics3D -
This shows the actual ratios of the Cuboid dimensions. In[10]:= Show[%, BoxRatios -> Automatic]
Out[10]= - Graphics3D -

5.2.2 Projection

The process by which a coordinate system of dimension n is transformed into one of dimension less than n is called a projection. In order to view a three-dimensional object on a computer screen or a printed page it is necessary to project it from three to two dimensions.

Projection of a line.

The components which define a projection are a projection plane, which defines the two-dimensional space to which we wish to move, and a projection point. The projection is made by forming the straight line from the projection point to the object we wish to project. Where this line cuts the projection plane is the projection of that object.

In Mathematica the projection point is given by the option ViewPoint and the projection plane is defined by the plane which contains the ViewCenter and is perpendicular to the vector from the ViewPoint to the ViewCenter, the line-of-sight vector.

In[11]:= Plot3D[Sin[x Cos[y]], {x, 0, 2 Pi}, {y, 0, Pi}]
Out[11]= - SurfaceGraphics -
This is the default ViewPoint which was used. In[12]:= FullOptions[%, ViewPoint]

Out[12]= {1.3, -2.4, 2.}
This reflects the viewpoint in the z direction to show us the underside of the surface. In[13]:= Show[%%, ViewPoint -> {1, 1, -1}]
Out[13]= - SurfaceGraphics -

ViewPoint is given in a special scaled coordinate system in which the origin is the center of the box. The units are scaled so that the longest side of the box is unity and the other dimensions follow their BoxRatios. Note that the ViewPoint must be outside of the box. This choice of coordinate system allows us to gain an interesting view of a wide variety of three-dimensional objects from one default ViewPoint.

ViewCenter is used to set the projection plane as is specified above. It is also used to specify which part of the projected image will appear in the center of the window. The coordinate system of ViewCenter is Scaled coordinates, the lower-left corner of the box is {0, 0, 0} the upper-right corner is {1, 1, 1}. With the default setting ViewCenter -> Automatic Mathematica chooses the projection plane to pass through the center of the box but places the center of the projection so that the image is as large as possible. ViewCenter -> {0.5, 0.5, 0.5} uses the same projection plane but puts the point Scaled[{0.5, 0.5, 0.5}] at the center of the drawing region.


With the default setting of SphericalRegion -> False the image is scaled so that the projection of the box fits into the window. Setting SphericalRegion -> True scales so that the sphere which can be transcribed around the box fits the window. This is desirable if one wishes to animate the rotation of a graphic by changing the ViewPoint.


The option ViewVertical is provided to allow the user to specify which direction in the image will point up in the projected image. The default value of this is ViewVertical -> {0, 0, 1} so the z direction (at the ViewCenter) points up.

The Z points up here. In[14]:= Show[Graphics3D[{PointSize[0.02], Thickness[0.008], Line[{{0, 0, 0}, {1, 0, 0}}], Point[{1, 0, 0}], Text["X", {1.2, 0, 0}], Line[{{0, 0, 0}, {0, 1, 0}}], Point[{0, 1, 0}], Text["Y", {0, 1.2, 0}], Line[{{0, 0, 0}, {0, 0, 1}}], Point[{0, 0, 1}], Text["Z", {0, 0, 1.2}]}, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1.5, 1.5}}]]
Out[14]= - Graphics3D -
This makes Y point up. In[15]:= Show[%, ViewVertical -> {0, 1, 0}]
Out[15]= - Graphics3D -


With the specification of BoxRatios, ViewPoint, ViewCenter, ViewVertical and SphericalRegion the projection from three-dimensional coordinates is complete. However, the relative scaling of x and y in the projection plane can be altered with the option AspectRatio, which maintains the relative proportions which were initially present. Under most circumstances this is desirable.

next page: 6 Graphics Programming back to table of contents