Advanced Topics

Building up Graphics from Primitives

Mathematica has several graphics primitives which allow you to plot points, draw lines, draw and shade polygons, etc. If you look at all the graphics thusfar in this lab, they consist primarily of points, lines, and shaded polygons. By using high-level Mathematica functions like Plot3D and ParametricPlot3D, we never have to worry about the details of the construction of the graphics at, for example, the shaded polygon level.

If you need to build up a graphic image using primitive graphic objects, you can do so as illustrated in the following example.

[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr50.gif]
[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr51.gif]
[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr52.gif]

You can specify colors for the objects, or you can let Mathematica compute the colors based on the lighting model it uses. This lighting model is discussed briefly in the next subsection.

An example of an animation of two cubes connected by a bar rotating in 3-space is contained in the auxilary notebook dumbbell animation. There are some minor difficulties which have to be overcome to do this rotation, so the code in that notebook is more subltle than in the other animations.

Lighting and Color

Mathematica provides a lot of flexability in the way the colors of the polygons are computed when graphing surfaces. You can specify the color of the background light (AmbientLight), you can specify the color and locations of point sources of light (LightSources), and you can specify how matted or shiny you want the surface to be (SurfaceColor). Mathematica combines all of this information using the Phong lighting model to determine the color of each polygon in a 3-dimensional graphic. Alternatively, you can turn off the simulated lighting model using Lighting -> False. You can also specify colors for the polygons using the ColorFunction option. For details on these specifications, you can consult the reference book Mathematica (pp. 455 -- 459). A brief description of the Phong lighting model used by Mathematica is contained there, but for a complete description, you will need to consult a text on computer graphics.

The Structure of SurfaceGraphics and Graphics3D Objects

You may have noticed that the Plot3D function produces a SufaceGraphics object, whereas the ParametricPlot3D function produces a Graphics3D object. The reason for the difference is that when the one coordinate is a function of the other two, an efficient description of the polygons which model the surface can be empoyed. To see how Mathematica does this, we can look at the actual structure of the output from Plot3D, compressing the result to 2 lines of information using the Short command.

[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr53.gif]
[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr54.gif]

So the z values are neatly stored in a PlotPoints by PlotPoints array followed by the list of options. We can compare this to a Graphics3D description of a surface obatined, for example, using ParametricPlot3D.

[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr55.gif]
[Graphics:3dgraphinggr2.gif][Graphics:3dgraphinggr56.gif]

So what we get is a polygon by polygon description of the surface.