This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.

Density and Contour PlotsThree-Dimensional Graphics Directives

2.9.8 Three-Dimensional Graphics Primitives

One of the most powerful aspects of graphics in Mathematica is the availability of three-dimensional as well as two-dimensional graphics primitives. By combining three-dimensional graphics primitives, you can represent and render three-dimensional objects in Mathematica.

Three-dimensional graphics elements.

Every time you evaluate rcoord, it generates a random coordinate in three dimensions.

In[1]:= rcoord := {Random[ ], Random[ ], Random[ ]}

This generates a list of 20 random points in three-dimensional space.

In[2]:= pts = Table[Point[rcoord], {20}] ;

Here is a plot of the points.

In[3]:= Show[ Graphics3D[ pts ] ]


This gives a plot showing a line through 10 random points in three dimensions.

In[4]:= Show[ Graphics3D[ Line[ Table[rcoord, {10}] ] ] ]


If you give a list of graphics elements in two dimensions, Mathematica simply draws each element in turn, with later elements obscuring earlier ones. In three dimensions, however, Mathematica collects together all the graphics elements you specify, then displays them as three-dimensional objects, with the ones in front in three-dimensional space obscuring those behind.

Every time you evaluate rantri, it generates a random triangle in three-dimensional space.

In[5]:= rantri := Polygon[ Table[ rcoord, {3} ] ]

This draws a single random triangle.

In[6]:= Show[ Graphics3D[ rantri ] ]


This draws a collection of 5 random triangles. The triangles in front obscure those behind.

In[7]:= Show[ Graphics3D[ Table[rantri, {5}] ] ]


By creating an appropriate list of polygons, you can build up any three-dimensional object in Mathematica. Thus, for example, all the surfaces produced by ParametricPlot3D are represented simply as lists of polygons.

The package Graphics`Polyhedra` contains examples of lists of polygons which correspond to polyhedra in three dimensions.

This loads a package which defines various polyhedra.

In[8]:= <<Graphics`Polyhedra`

Here is the list of polygons corresponding to a tetrahedron centered at the origin.

In[9]:= Tetrahedron[ ]


This displays the tetrahedron as a three-dimensional object.

In[10]:= Show[ Graphics3D[ % ] ]


Dodecahedron[ ] is another three-dimensional object defined in the polyhedra package.

In[11]:= Show[ Graphics3D[ Dodecahedron[ ] ] ]


This shows four intersecting dodecahedra.

In[12]:= Show[ Graphics3D[

Table[Dodecahedron[0.8 {k, k, k}], {k, 0, 3}] ] ]


Mathematica allows polygons in three dimensions to have any number of vertices. However, these vertices should lie in a plane, and should form a convex figure. If they do not, then Mathematica will break the polygon into triangles, which are planar by definition, before rendering it.

Cuboid graphics elements.

This draws 20 random unit cubes in three-dimensional space.

In[13]:= Show[Graphics3D[ Table[Cuboid[10 rcoord], {20}] ]]


Density and Contour PlotsThree-Dimensional Graphics Directives