Three-Dimensional Mathematica Graphics (Section 5.1)

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.1 Coordinate Specification

{x, y} two-dimensional coordinates
Scaled[{x, y}]  
Scaled[{dx, dy}, {x, y}]  
{x, y, z} three-dimensional coordinates
Scaled[{x, y, z}]  
Scaled[{dx, dy, dz}, {x, y, z}]  
Types of coordinates for two and three dimensions.

The coordinates for a primitive such as Line or Polygon can be given in a number of ways. The simplest and most obvious is to give pairs of numbers for two-dimensional graphics and triples for three-dimensional graphics. These are called user coordinates; they are the initial points which we wish to represent. An alternative way to represent points, in a particular part of the picture, is to use Scaled coordinates. These refer to display coordinates. For example, they allow us to draw something in the middle of the image without having to know anything about the user coordinates being displayed.

5.1.1 PlotRange

As an object is rendered the list of primitives and directives is scanned to determine the extent of the coordinates which are shown. This is controlled by the option PlotRange which provides considerable control of the range which will be seen.

PlotRange -> Automatic only the most interesting part
PlotRange -> All the full range of coordinates
PlotRange -> {min, max} the range from min to max
Settings for the PlotRange option.
This shows a plot with the default value PlotRange -> Automatic. In[1]:= plot = ParametricPlot3D[{x, Tan[x] Sin[1.5 x], Tan[x] Cos[1.5 x]}, {x, 0, 10}]
Out[1]= - Graphics3D -
 
This shows the actual numbers which were used. In[2]:= FullOptions[%, PlotRange]

Out[2]= {{-0.25, 10.25}, {-3.81988, 3.13889}, {-3.48307, 4.05394}}
 
This plots all the primitives. Notice that this shows less about the function than the previous plot. In[3]:= Show[plot, PlotRange -> All]
Out[3]= - Graphics3D -
 
This applies to the z direction only. The x and y PlotRange is determined by the default. In[4]:= Show[plot, PlotRange -> {-2, 4}]
Out[4]= - Graphics3D -
 
This works on all three dimensions. In[5]:= Show[plot, PlotRange -> {{0, Pi}, {-4, 4}, {-4, 4}}]
Out[5]= - Graphics3D -
 

In general, a wide range of settings and combinations for the PlotRange option can be used.

PlotRange -> {Automatic, All} two dimensions
PlotRange -> {All, {5., 10.}} two dimensions
PlotRange -> {Automatic, {3., 5.}, All} three dimensions
Example settings for PlotRange.

5.1.2 Scaled

The examples of primitives which we have seen all showed the coordinates being given in one system, the original or user coordinate system. Sometimes you wish to choose points described in the final or display coordinate system. This is done with the Scaled command. Here I describe the three-dimensional form. There is an equivalent two-dimensional version.

{x, y, z} {x, y, z} in user coordinates
Scaled[{sx, sy, sz}] {sx, sy, sz} in display coordinates
Scaled[{dx, dy, dz}, {x, y, z}] {dx, dy, dz} in display coordinates relative to {x, y, z} in user coordinates
Coordinates which can be used to build three-dimensional primitives.

Scaled coordinates are chosen to run from 0 to 1 in all three dimensions and have their origin at the corner of the bounding box with the minimal user coordinates. Thus Scaled[{0, 0, 0}] refers to the minimum of the PlotRange and Scaled[{1, 1, 1}] to the maximum.

This always draws lines from corner to corner of the bounding box. In[6]:= Show[Graphics3D[{Line[{Scaled[{0, 0, 0}], Scaled[{1, 1, 1}]}], Line[{Scaled[{0, 0, 1}], Scaled[{1, 1, 0}]}], Line[{Scaled[{1, 0, 0}], Scaled[{0, 1, 1}]}], Line[{Scaled[{1, 0, 1}], Scaled[{0, 1, 0}]}]}]]
Out[6]= - Graphics3D -
 
This is a Mathematica function which uses the offset version of Scaled. In[7]:= cross[{x_, y_, z_}] := {Line[{Scaled[{-0.02, 0, 0}, {x, y, z}], Scaled[{+0.02, 0, 0}, {x, y, z}]}], Line[{Scaled[{0, -0.02, 0}, {x, y, z}], Scaled[{0, +0.02, 0}, {x, y, z}]}], Line[{Scaled[{0, 0, -0.02}, {x, y, z}], Scaled[{0, 0, +0.02}, {x, y, z}]}]}
 
In[8]:= Show[Graphics3D[{cross[{0, 0, 0}], cross[{1, 1, 0.5}], cross[{0.5, 0.5, 1}]}]]
Out[8]= - Graphics3D -
 

5.1.3 AspectRatio

The aspect ratio of the graphics object is set by the option AspectRatio.

AspectRatio -> num show picture with a height / width = num
AspectRatio -> Automatic show picture with ratio taken from data
Settings for the AspectRatio option.

Even though AspectRatio -> Automatic maintains the x to y scaling, this is often not very useful. An example is Plot[Tan[x], {x, 0, 2 Pi}, AspectRatio -> Automatic].


next page: 5.2 Three-Dimensional Coordinates back to table of contents