Sketching Level Surfaces with MATHEMATICA


The ContourPlot3D command provides one means to sketch the 3-dimensional graph of an equation of three variables. However, it is (necessarily) based on a cumbersome and slow procedure and so its preferable to use a different approach to sketching the surface when possible. If the equation can be solved for one of its variables ( for example, as z = f(x,y) ) then its better to use the Plot3D command. Or, if the surface can be described with a two-dimensional parametrization then the ParametricPlot3D command is better.

The ContourPlot3D command is in a special package which is not automatically loaded by MATHEMATICA. To use it you must first load the package by entering the command

<<Graphics`ContourPlot3D`

(Warning: in this command the word ContourPlot3D is immediately preceded and immediately followed by a left quotation mark ` which does not show up very clearly in the HTML font used here.)   If you try to implement the ContourPlot3D command before loading this graphics package with the << command, MATHEMATICA tends to get very confused. If this happens it may be necessary to exit and start a new MATHEMATICA session.   Once the package is loaded, enter the command

ContourPlot3D[ f(x,y,z), {x,xmin,xmax}, {y,ymin,ymax}, {z,zmin,zmax} ]

This will draw the graph of   f(x,y,z) = 0   ( which is the level surface for f(x,y,z) at C = 0 ) in the rectangular box [xmin,xmax] × [ymin,ymax] × [zmin,zmax] in 3-space. For example the output of

ContourPlot3D[ x^2 + y^2 + z^2 - 1, {x,-1,1}, {y,-1,1}, {z,-1,1}]

is the unit sphere centered at the origin:

To take control of the output we might add some modifiers such as

ContourPlot3D[ x^2+y^2+z^2, {x,-1,1}, {y,-1,1}, {z,-1,1}, Contours -> {1,2}, Lighting -> False, Boxed -> False, ContourStyle -> {{RGBColor[0,1,0]},{RGBColor[1,0,0]}} ]

obtaining two concentric spheres:

The green ( or RGBColor[0,1,0] ) sphere is the level surface at C = 2. Notice that the portions of it which lie outside of the box [-1,1] × [-1,1] × [-1,1] have been chopped off, and this allows us to see the inner sphere.

Here is a table of some modifiers which can be used.

AmbientLight -> RGBColor[NN,NN,NN] change the color of the surface
Axes -> BB include or omit axes
AxesLabel -> {"text","text","text"} label the axes
Background -> RGBColor[NN,NN,NN] create a colored background
Boxed -> BB include or omit box around figure
BoxRatios -> {NN, NN, NN} specify the ratios of side lengths of the box (like setting the aspect ratio for a window)
Contours -> {NN, NN, ....} specify NN, NN, .... as the precise level surfaces to graph
ContourStyle -> {{RGBColor[NN,NN,NN]}, {RGBColor[NN,NN,NN]}, ....} specify the colors of the different level surfaces. This must be used with Lighting -> False
Lighting -> BB use simulated lighting or not
PlotLabel -> "TEXT" create a label for the contour plot
PlotPoints -> NN number of points to sample.
SphericalRegion -> BB this will keep the size of box constant when you change viewpoint
ViewPoint -> {NN,NN,NN} coordinates of point from which to view box

In this table, NN denotes a numerical value which must be between 0 and 1 in RGBColor. The symbol BB takes one of the values True or False .

Here's one more example:

ContourPlot3D[ x+2y+3z, {x,-1,1}, {y,-1,1}, {z,-1,1}, Background -> RGBColor[1,.5,.2], Contours -> {-2,1,4}, ContourStyle -> {{RGBColor[1,0,0]},{RGBColor[0,1,0]}, {RGBColor[0,0,1]}}, Lighting -> False, ViewPoint -> {2,-1,2.5}, Boxed -> False, PlotLabel->"Some parallel planes" ]

gives three parallel planes:




back to the table of contents

URL: http://math.ou.edu/~amiller/math/cplot3d.htm

August, 1999