Coordinate Systems for Three-Dimensional Graphics

Whenever the Wolfram Language draws a three-dimensional object, it always effectively puts a cuboidal box around the object. With the default option setting (RefLink[Boxed, paclet:ref/Boxed])->(RefLink[True, paclet:ref/True]), the Wolfram Language in fact draws the edges of this box explicitly. But in general, the Wolfram Language automatically "clips" any parts of your object that extend outside of the cuboidal box.

The option (RefLink[PlotRange, paclet:ref/PlotRange]) specifies the range of x, y, and z coordinates that the Wolfram Language should include in the box. As in two dimensions the default setting is (RefLink[PlotRange, paclet:ref/PlotRange])->(RefLink[Automatic, paclet:ref/Automatic]), which makes the Wolfram Language use an internal algorithm to try and include the "interesting parts" of a plot, but drop outlying parts. With (RefLink[PlotRange, paclet:ref/PlotRange])->(RefLink[All, paclet:ref/All]), the Wolfram Language will include all parts.

This loads a package defining polyhedron operations:

<<PolyhedronOperations`

This creates a stellated icosahedron:

stel=Stellate[PolyhedronData["Icosahedron","GraphicsComplex"]];

This shows the stellated icosahedron, drawn in a box:

Graphics3D[stel,Axes->True]

With this setting for (RefLink[PlotRange, paclet:ref/PlotRange]), many parts of the stellated icosahedron lie outside the box, and are clipped:

Show[%,PlotRange->{-1,1}]

Much as in two dimensions, you can use either "original" or "scaled" coordinates to specify the positions of elements in three-dimensional objects. Scaled coordinates, specified as (RefLink[Scaled, paclet:ref/Scaled])[{sx,sy,sz}], are taken to run from 0 to 1 in each dimension. The coordinates are set up to define a right-handed coordinate system on the box.

Coordinate systems for three-dimensional objects.

This puts a cuboid in one corner of the box:

Graphics3D[{stel,Cuboid[Scaled[{0,0,0}],Scaled[{0.2,0.2,0.2}]]}]

Once you have specified where various graphical elements go inside a three-dimensional box, you must then tell the Wolfram Language how to draw the box. The first step is to specify what shape the box should be. This is analogous to specifying the aspect ratio of a two-dimensional plot. In three dimensions, you can use the option (RefLink[BoxRatios, paclet:ref/BoxRatios]) to specify the ratio of side lengths for the box. For (RefLink[Graphics3D, paclet:ref/Graphics3D]) objects, the default is (RefLink[BoxRatios, paclet:ref/BoxRatios])->(RefLink[Automatic, paclet:ref/Automatic]), specifying that the shape of the box should be determined from the ranges of actual coordinates for its contents.

Specifying the shape of the bounding box for three-dimensional objects.

This displays the stellated icosahedron in a tall box:

Graphics3D[stel,BoxRatios->{1,1,5}]

To produce an image of a three-dimensional object, you have to tell the Wolfram Language from what view point you want to look at the object. You can do this using the option (RefLink[ViewPoint, paclet:ref/ViewPoint]).

Some common settings for this option were given in "Three-Dimensional Surface Plots". In general, however, you can tell the Wolfram Language to use any view point.

View points are specified in the form (RefLink[ViewPoint, paclet:ref/ViewPoint])->{sx,sy,sz}. The values si are given in a special coordinate system, in which the center of the box is {0,0,0}. The special coordinates are scaled so that the longest side of the box corresponds to one unit. The lengths of the other sides of the box in this coordinate system are determined by the setting for the (RefLink[BoxRatios, paclet:ref/BoxRatios]) option. For a cubical box, therefore, each of the special coordinates runs from -1/2 to 1/2 across the box. Note that the view point must always lie outside the box.

This generates a picture using the default view point {1.3,-2.4,2}:

surf=Plot3D[(2+Sin[x]) Cos[2 y],{x,-2,2},{y,-3,3},AxesLabel->{"x","y","z"}]

This is what you get with a view point close to one of the corners of the box:

Show[surf,ViewPoint->{1.2,1.2,1.2}]

As you move away from the box, the perspective effect gets smaller:

Show[surf,ViewPoint->{5,5,5}]

Specifying the position and orientation of three-dimensional objects.

In making a picture of a three-dimensional object, you have to specify more than just where you want to look at the object from. You also have to specify how you want to "frame" the object in your final image. You can do this using the additional options (RefLink[ViewCenter, paclet:ref/ViewCenter]), (RefLink[ViewVertical, paclet:ref/ViewVertical]), and (RefLink[ViewAngle, paclet:ref/ViewAngle]).

(RefLink[ViewCenter, paclet:ref/ViewCenter]) allows you to tell the Wolfram Language what point in the object should appear at the center of your final image. The point is specified by giving its scaled coordinates, running from 0 to 1 in each direction across the box. With the setting (RefLink[ViewCenter, paclet:ref/ViewCenter])->{1/2,1/2,1/2}, the center of the box will therefore appear at the center of your final image. With many choices of view point, however, the box will not appear symmetrical, so this setting for (RefLink[ViewCenter, paclet:ref/ViewCenter]) will not center the whole box in the final image area. You can do this by setting (RefLink[ViewCenter, paclet:ref/ViewCenter])->(RefLink[Automatic, paclet:ref/Automatic]).

(RefLink[ViewVertical, paclet:ref/ViewVertical]) specifies which way up the object should appear in your final image. The setting for (RefLink[ViewVertical, paclet:ref/ViewVertical]) gives the direction in scaled coordinates that ends up vertical in the final image. With the default setting (RefLink[ViewVertical, paclet:ref/ViewVertical])->{0,0,1}, the z direction in your original coordinate system always ends up vertical in the final image.

The Wolfram Language uses the properties of a simulated camera to visualize the final image. The position, orientation, and facing of the camera are determined by the (RefLink[ViewCenter, paclet:ref/ViewCenter]), (RefLink[ViewVertical, paclet:ref/ViewVertical]), and (RefLink[ViewPoint, paclet:ref/ViewPoint]) options. The (RefLink[ViewAngle, paclet:ref/ViewAngle]) option specifies the width of the opening of the camera lens. The (RefLink[ViewAngle, paclet:ref/ViewAngle]) specifies, in radians, twice of the maximum angle from the line stretching from the (RefLink[ViewPoint, paclet:ref/ViewPoint]) to the (RefLink[ViewCenter, paclet:ref/ViewCenter]) that can be viewed by the camera. This means that (RefLink[ViewAngle, paclet:ref/ViewAngle]) can effectively be used to zoom in on a part of the image. The default value of (RefLink[ViewAngle, paclet:ref/ViewAngle]) resolves to 35°, which is the typical viewing angle for the human eye.

This setting for (RefLink[ViewVertical, paclet:ref/ViewVertical]) makes the x axis of the box appear vertical in your image:

Show[surf,ViewVertical->{1,0,0}]

This uses (RefLink[ViewAngle, paclet:ref/ViewAngle]) to effectively zoom in on the center of the image:

Show[surf,ViewAngle->10Degree]

When you set the options (RefLink[ViewPoint, paclet:ref/ViewPoint]), (RefLink[ViewCenter, paclet:ref/ViewCenter]), and (RefLink[ViewVertical, paclet:ref/ViewVertical]), you can think about it as specifying how you would look at a physical object. (RefLink[ViewPoint, paclet:ref/ViewPoint]) specifies where your head is relative to the object. (RefLink[ViewCenter, paclet:ref/ViewCenter]) specifies where you are looking (the center of your gaze). And (RefLink[ViewVertical, paclet:ref/ViewVertical]) specifies which way up your head is.

In terms of coordinate systems, settings for (RefLink[ViewPoint, paclet:ref/ViewPoint]), (RefLink[ViewCenter, paclet:ref/ViewCenter]), and (RefLink[ViewVertical, paclet:ref/ViewVertical]) specify how coordinates in the three-dimensional box should be transformed into coordinates for your image in the final display area.

Possible values of the (RefLink[ViewVector, paclet:ref/ViewVector]) option.

The position and facing of the camera can be fully determined by the (RefLink[ViewPoint, paclet:ref/ViewPoint]) and (RefLink[ViewCenter, paclet:ref/ViewCenter]) options, but the (RefLink[ViewVector, paclet:ref/ViewVector]) option offers a useful generalization. Instead of specifying the position and facing of the camera using scaled coordinates, (RefLink[ViewVector, paclet:ref/ViewVector]) provides the ability to position the camera using the same coordinate system used to position objects within the graphic.

This specifies that the camera should be placed on the negative x axis and facing toward the center of the graphic:

Show[surf,ViewVector->{-5,0,0}]

The camera is in the same position but pointing in a different direction. In combination with (RefLink[ViewAngle, paclet:ref/ViewAngle]), this zooms in on a particular section of the graphic:

Show[surf,ViewVector->{{-5,0,0},{2,-3,2}},ViewAngle->20 Degree]

Once you have obtained a two-dimensional image of a three-dimensional object, there are still some issues about how this image should be rendered. The issues, however, are identical to those that occur for two-dimensional graphics. Thus, for example, you can modify the final shape of your image by changing the (RefLink[AspectRatio, paclet:ref/AspectRatio]) option. And you specify what region of your whole display area your image should take up by setting the (RefLink[PlotRegion, paclet:ref/PlotRegion]) option.

Mouse gestures used for interacting with three-dimensional graphics.

When interactively modifying graphics, the Wolfram Language makes changes to the view options. If you have specified the position of the camera using (RefLink[ViewPoint, paclet:ref/ViewPoint]), then rotating the graphic causes the Wolfram Language to change the value of the (RefLink[ViewPoint, paclet:ref/ViewPoint]) option. If the position of the camera is specified using (RefLink[ViewVector, paclet:ref/ViewVector]), interactive rotation will instead change the value of that option. In both cases, interactive rotation can also affect the value of the (RefLink[ViewVertical, paclet:ref/ViewVertical]) option. Interactive zooming of the graphic corresponds directly to changing the (RefLink[ViewAngle, paclet:ref/ViewAngle]) option. Interactively panning the graphic changes values of the (RefLink[ViewCenter, paclet:ref/ViewCenter]) option.

This modifies the aspect ratio of the final image:

Show[surf,Axes->False,AspectRatio->0.3]

The Wolfram Language usually scales the images of three-dimensional objects to be as large as possible, given the display area you specify. Although in most cases this scaling is what you want, it does have the consequence that the size at which a particular three-dimensional object is drawn may vary with the orientation of the object. You can set the option (RefLink[SphericalRegion, paclet:ref/SphericalRegion])->(RefLink[True, paclet:ref/True]) to avoid such variation. With this option setting, the Wolfram Language effectively puts a sphere around the three-dimensional bounding box, and scales the final image so that the whole of this sphere fits inside the display area you specify. The sphere has its center at the center of the bounding box, and is drawn so that the bounding box just fits inside it.

This draws a rather elongated version of the plot:

Framed[Show[surf,BoxRatios->{1,5,1}]]

With (RefLink[SphericalRegion, paclet:ref/SphericalRegion])->(RefLink[True, paclet:ref/True]), the final image is scaled so that a sphere placed around the bounding box would fit in the display area:

Framed[Show[surf,BoxRatios->{1,5,1},SphericalRegion->True]]

By setting (RefLink[SphericalRegion, paclet:ref/SphericalRegion])->(RefLink[True, paclet:ref/True]), you can make the scaling of an object consistent for all orientations of the object. This is useful if you create animated sequences that show a particular object in several different orientations.

Changing the magnification of three-dimensional images.