Spherical-Coordinate Plotting with Maple

Copyright © 2001 by James F. Hurley, University of Connecticut Department of Mathematics, Unit 3009, Storrs CT 06269-3009. All rights reserved.

The interactive version of this worksheet is in the Math 210 folder in the Workspace volume in MSB 203 (g3server). For instructions on accessing the class folder remotely, see the Space Curves worksheet.

1. Using the basic sphereplot command . Maple's plots library has a command sphereplot to plot surfaces whose spherical-coordinate equations have the form rho = f ( phi , theta ) . The syntax of the basic command is

sphereplot( f( phi , theta ), theta = alpha .. beta , phi = gamma .. delta ) ;


As was true of
cylinderplot , this basic command handles spherical-coordinate equations that are solvable for the radial variable Ñ in this case, rho Ñ and are swept out as the angles theta and phi vary over a "spherical-coordinate rectangle" [ alpha , beta ] ´ [ gamma , delta ] in the theta phi -plane. It thus can plot only one of the three basic equations coordinate variable = constant , namely the sphere rho = k. The next routine illustrates this for the case k = 4 . (The condition scaling = constrained appears because on most monitors the default plot of the sphere appears squashed.) As usual, execute the routine by placing the cursor after the last semicolon and hitting the Enter key.

> with (plots):
sphereplot (4, theta = 0..2*Pi, phi = 0..Pi, axes = boxed, scaling = constrained);


Unlike the cylindrical-coordinate system Ñ one of whose coordinates is the standard Cartesian
z Ñ the spherical-coordinate system is completely non-rectangular. Even so, it is often helpful to include plots of the three Cartesian coordinate axes in spherical-coordinate figures. The following routine generates such a figure for the sphere rho = 4. Execute it to see what the coordinate axes add.

> with (plots):
surf := sphereplot (4, theta = 0..2*Pi, phi = 0..Pi, axes = boxed, scaling = constrained):
xaxis := spacecurve([t, 0, 0, t = -5..6, color = magenta]) :
yaxis := spacecurve([0, t, 0, t = -5..6, color = magenta]) :
zaxis := spacecurve([0, 0, t, t = -5..6, color = magenta]) :
labx := textplot3d([6.1, 0, -.2, `x`], color = magenta):
laby := textplot3d([0,6.1, -.2, `y`], color = magenta):
labz := textplot3d([0, 0, 6.1, `z`], color = magenta):
display(surf, xaxis, yaxis, zaxis, labx, laby,labz);

[Maple Plot]


The basic version of
sphereplot is powerful enough to give useful plots of many simple regions.

Example 1 . Plot the region E between the two spheres x^2+y^2+z^2 = 4 and x^2+y^2+z^2 = 9 .

Solution. The region is easy to visualize, and to plot if we restrict the angle theta t o the range [0, ¹], so that removal of the (hidden) sphere of smaller radius does not eliminate it from view! The following routine is just a slight modification of the last one.

> with (plots):
surf1 := sphereplot (2, theta = 0..Pi, phi = 0..Pi, axes = boxed, scaling = constrained, color = red):
surf2 := sphereplot (3, theta = 0..Pi, phi = 0..Pi, axes = boxed, scaling = constrained):
xaxis := spacecurve([t, 0, 0, t = -2..3.5, color = magenta]) :
yaxis := spacecurve([0, t, 0, t = -2..3.5, color = magenta]) :
zaxis := spacecurve([0, 0, t, t = -2..3.5, color = magenta]) :
labx := textplot3d([3.6, 0, -.2, `x`], color = magenta):
laby := textplot3d([0,3.6, -.2, `y`], color = magenta):
labz := textplot3d([0, 0, 3.6, `z`], color = magenta):
display(surf1, surf2, xaxis, yaxis, zaxis, labx, laby,labz);

[Maple Plot]

Note that an arrow (like the x -axis) shot radially outward from the origin enters the region E by passing through the red sphere of radius 2, and then exits E through the sphere of radius 3. (This kind of observation later leads immediately to correct limits of integration!)

2. More general regions . Again just as for the cylinderplot command, Maple's sphereplot command Ñ in a more general form Ñ can plot surfaces whose equations are not of the basic form rho = f ( phi , theta ) . Once again, the syntax of the extended sphereplot command requires specifying the formulas for all three variables rho , phi and theta . [ Aside : Unfortunately, like Mathematica, Maple has a non-standard aspect to this: it expects those variables to appear in an order that reverses the normal order of phi and theta : rho , theta , phi . This amounts to a decision by Maple's programmers to prefer the Jacobian determinant of the spherical-coordinate transformation to be -rho^2*sin*phi rather than the standard rho^2*sin*phi ; the reasons for such a choice are not clear. In anticipation of this, notice that above in the basic command, the ranges occur in the order first of theta and then of phi .] With u and v as generic symbols for the independent spherical-coordinate variables, the syntax for the extended sphereplot command takes the form

sphereplot( [ rho , theta , phi ], u = alpha .. beta , v = gamma .. delta ) ;


The next example illustrates the usefulness of the extended
sphereplot command by revisiting the first example of the Cylindrical Coordinate document.


Example 2
. Plot the region E above the graph of z = sqrt(x^2+y^2) and below the graph of x^2+y^2+z^2 = 4.

Solution
. The sphere of course has the simple spherical-coordinate equation rho = 2. What is the spherical-coordinate equation of the upper half of the cone z = sqrt(x^2+y^2) ? Recall that


z = rho cos phi


and
sqrt(x^2+y^2) = r (of cylindrical Ñ or polar Ñ coordinates). In deriving the formulas for changing coordinates from spherical to rectangular coordinates, a key relation is


r = rho sin phi .


The equation
z = r of the cone thus transforms to

rho cos phi = rho sin phi Þ 1 = tan phi Þ phi = Pi/4 .

The following routine generates a plot of the region E without the need Ñ which arose in plotting E via cylindrical coordiantes Ñ to determine algebraically the curve of intersection of the sphere rho = 2 and the cone phi = Pi/4 . Experiment by rotating the default plot to produce a good view.

> with (plots):
surf1 := sphereplot (2, theta = 0..Pi, phi = 0..Pi/2, axes = boxed, color = red):
surf2 := sphereplot ([rho, theta, Pi/4], rho = 0..2, theta = 0..Pi):
xaxis := spacecurve([t, 0, 0, t = -2..2.5, color = magenta]) :
yaxis := spacecurve([0, t, 0, t = -2..2.5, color = magenta]) :
zaxis := spacecurve([0, 0, t, t = -1..2.5, color = magenta]) :
labx := textplot3d([2.6, 0, -.2, `x`], color = magenta):
laby := textplot3d([0,2.6, -.2, `y`], color = magenta):
labz := textplot3d([0, 0, 2.6, `z`], color = magenta):
display(surf1, surf2, xaxis, yaxis, zaxis, labx, laby,labz, scaling = constrained);

[Maple Plot]

>


An arrow shot radially outward from the origin through
E emerges from the sphere rho = 2 . As with cylindrical coordinates, such observations later are the key to determining correct limits in evaluating multiple integrals over regions like E that have convenient spherical-coordinate descriptions.