Plotting in other coordinate systemsWorksheet by Mike May, S.J.- maymk@slu.eduRevised by Russell Blyth - blythrd@slu.edurestart;We look at how we can plot with Maple in other coordinate systems. The trick is that Maple has a coords option in its plot commands.Functions of one variableCartesian CoordinatesWe start with the standard Cartesian coordinate system. Maple assumes that we write y as a function of x. We can also plot curves parametrically using [x(t), y(t), t=trange].plot((x-1)^2-2, x=-1..3);
plot([t, (t-1)^2-2,t=-1..3]);Polar CoordinatesTo use polar coordinates, note that Maple expects r to be a function of theta. If we are plotting parametrically, then Maple expects the form [r(t), theta(t), t=trange]. plot(1+2*cos(theta), theta=0..2*Pi, coords=polar);
plot([1+2*cos(t), t, t=0..2*Pi], coords=polar);Mixed CoordinatesWe can put plots in different coordinate systems together with the display command. Note that we end the commands of the named plots with a colon rather than a semicolon (otherwise we get an ugly list of the postscript commands that make up the plot structures). To use display we first need to load it using the with(plots) command.with(plots):
plota:= plot((x-1)^2-2, x=-1..3, color=red):
plotb:= plot(1+2*cos(theta), theta=0..2*Pi, coords=polar, color=blue):
display({plota, plotb});Exercises1. Plot the graph of a 5 petal rose of radius 2 with a petal cut by the positive x-axis. (You should remember the formula for this from pre-calculus.)2. Plot the cardioid defined by r=1-sin(theta) on the same axes as the graph of y=1+sin(Pi*(x+0.5)) to create a picture of a heart with a hat.Functions of two variablesCartesian CoordinatesWe start with surfaces that are the plots of functions in two variables with Cartesian coordinates. In a parallel fashion, Maple assumes that we write z as a function of x and y. If we parameterize a surface, it is assumed to be in the form ([x(u,v), y(u, v), z(u, v)], u=urange, v=vrange).plot3d(sin(x^2+y^2), x=-3..3, y=-3..3, style=patch, axes=boxed);
plot3d([u, v, sin(u^2+v^2)], u=-3..3, v=-3..3, style=patch, axes=boxed);Cylindrical CoordinatesIn cylindrical coordinates Maple assumes that we express r as a function of theta and z. (By contrast, in class we typically express z as a function of r and theta.) This means that we have to use the parametric form if we want to graph the sombrero surface above. (The graph above has many r values corresponding to a single value of theta and z, so r is not a function of theta and z.) Interestingly, the parametric description in Maple arranges the variables in the more familiar (r, theta, z) pattern so the form is ([r(u,v), theta(u,v), z(u,v)], u=urange, v=vrange).plot3d([r, theta, sin(r^2)], r=0..4, theta=0..2*Pi, coords=cylindrical, style=patch, axes=boxed);The cylindrical form is useful for plotting surfaces obtained by rotating curves around the z axis. Cylinders are the easiest example of this. They are obtained by rotating vertical lines about the z-axis. We show such a cylinder together with another surface of rotation.plot3d({1, 3+sin(z)}, theta=0..2*Pi, z=-4..4, style=patch, axes=boxed, coords=cylindrical);Spherical coordinatesMaple assumes that surfaces described in spherical coordinates express the radial distance rho as a function of theta and phi. The easiest surface to graph is, as the name of the system suggests, a sphere centered at the origin.plot3d(2, theta=0..2*Pi, phi=0..Pi, coords=spherical, style=patch, axes=boxed);If we are graphing a more complicated surface we may want to use the parametric form. In that case Maple assumes that the form is ([rho(u,v), theta(u,v), phi(u,v)], u=urange, v=vrange).plot3d(4+5*cos(2*phi)+3*sin(3*theta), theta=0..2*Pi, phi=0..Pi, coords=spherical, style=patch, axes=boxed);
plot3d([4+5*cos(2*phi)+3*sin(3*theta), theta, phi], theta=0..2*Pi, phi=0..Pi, coords=spherical, style=patch, axes=boxed);Mixed coordinatesOnce again, a nice trick is to use display3d to put together surfaces that are easy to describe in different coordinate systems. The code below puts together the plane z=x+y (Cartesian coordinates), the cylinder r=2 (cylindrical coordinates), and the sphere rho = 3 (spherical coordinates).plotplane := plot3d(x+y, x=-4..4, y=-4..4, style=patch, color=red, axes=boxed):
plotcyl := plot3d(2, theta=0..2*Pi, z=-8..8, style=patch, color=blue, axes=boxed, coords=cylindrical):
plotsph := plot3d(3, theta=0..2*Pi, phi=0..Pi, style=patch, color=green, axes=boxed, coords=spherical):
display3d({plotplane, plotcyl, plotsph});Exercises3. Plot a sphere of radius 3 centered at the origin in each of the three coordinate systems we have discussed. Which is easiest?4. Plot a cone with point at the origin, height 4 and radius 3 using the coordinate system of your choice.