> # Plotting a sphere Math II 18 September 1996 # # # We plot a sphere x**2+y**2+z**2=1 in three different manners. # -------------------------------------------------------------------------------- > with(plots): -------------------------------------------------------------------------------- # First, we express z as a function of x and y # The first argument in plot3d gives the value of z. # We look at both the positive and negative values of z. # Notice that we need to restrict the range of y to depend on x. # > top:=plot3d(sqrt(1-x*x-y*y),x=-1..1,y=-sqrt(1-x*x)..sqrt(1-x*x),color=blue): > bottom:=plot3d(-sqrt(1-x*x-y*y),x=-1..1,y=-sqrt(1-x*x)..sqrt(1-x*x),color=blue): > display3d({top,bottom},title=`Sphere using z=...`); -------------------------------------------------------------------------------- # # Now, we parametrize. We still use rectangular coordinates. # > x1 := cos(t); y1:= sin(t)*sin(s); z1:= sin(t)*cos(s); x1 := cos(t) y1 := sin(t) sin(s) z1 := sin(t) cos(s) -------------------------------------------------------------------------------- > plot3d([x1,y1,z1],t=0..2*Pi,s=0..Pi,title=`Sphere using parametrization`,color=blue); -------------------------------------------------------------------------------- # # We now represent the sphere using spherical coordinates # > sphereplot(1,theta=0..2*Pi,phi=0..Pi,title=`Plot in spherical coordinates`,color=blue); -------------------------------------------------------------------------------- > \ # # Notice that the first representation is far worse than the other # two. # # # # # # # # # -------------------------------------------------------------------------------- >