Worksheet: Graphing Parametric Surfaces
Introduction
As we have done before with worksheets:
Please work through all the code and examples in this worksheet.
Things in this font are Octave commands — don't cut and
paste them, type the commands yourself. Trust me, this is the better way to
learn these commands.
Please do the following to show your work:
- Start a diary.
- Type all the commands.
- Also start a separate .m file in which you put all the commands
which work, in their best forms. (So this will be basically an edited diary,
with only the good stuff.)
- Wherever there is a plot you are to make, save off a copy of it. Make sure
the plot has some title and is saved in a file name which is (part of) that
title.
Parametric Surfaces in Octave
Example 1: A Cone
Let's think about a surface defined mathematically by parameters $r$ and
$\theta$ in the ranges $0\le r\le1$ and $\le\theta\le2\pi$ with equations
$$\begin{eqnarray*}x&=&r\cos\theta\\y&=&r\sin\theta\\z&=&r\end{eqnarray*}$$
To get a reasonable set of values in those ranges for the parameters, do
rv=linspace(0,1,30);
thetav=linspace(0,2*pi,30);
(the v on the end of the variable names is to indicate that they are
vectors. We now need to match all pairs of one of the rvs with one of
the thetavs, which is done by
[r,theta]=meshgrid(rv,thetav);
You might look at the vectors (actually, they're matrices) of values we've just
created to see what's going on. (To look at them, maybe make smaller versions
with 5 values instead of 30, above. But you will want the 30 for the 3-D plot
to look nice.)
Next we must use the parametric equations to get the corresponding values in the
Cartesian coordinate system:
x=r.*cos(theta);
y=r.*sin(theta);
z=r;
Now simply plot the surface with
mesh(x,y,z);
Here are a couple of commands which make the plot look a little better:
axis tight
box on
Left-click and hold in the graphics window and move the mouse around to get used
to how to manipulate the 3-D image.
Particularly after mousing around like that, it is easy to loose track of which
axis is which, so add some labels with:
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
Click and mouse some more.
That was a cone in what are called cylindrical coordinates.
Example 2: A Sphere
Now let's make a sphere using spherical coordinates as the parameters.
For this, the variables will be $\phi$ and $\theta$ in the ranges
$0\le\phi\le\pi$ and $0\le\theta\le2\pi$, and $r$ will have the fixed value
2. The surface will then be given by the equations
$$\begin{eqnarray*}x&=&r\sin(\phi)\cos(\theta)\\y&=&r\sin(\phi)\sin(\theta)\\z&=&r\cos(\phi)\end{eqnarray*}$$
We know how to create the matrix of pairs of parameter values:
phiv=linspace(0,pi,30);
thetav=linspace(0,2*pi,30);
[phi,theta]=meshgrid(phiv,thetav);
and then the corresponding Cartesian coordinates:
x=2*sin(phi).*cos(theta);
y=2*sin(phi).*sin(theta);
z=2*cos(phi);
and the graph, made a little prettier
mesh(x,y,z)
axis equal
view(135,30)
box on
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
Example 3: A Snail Shell
The surface given by equations
$$\begin{eqnarray*}x&=&2\left(1-e^{u/(6\pi)}\right)\cos(u)\cos^2\left(\frac{v}{2}\right)\\y&=&2\left(-1+e^{u/(6\pi)}\right)\sin(u)\cos^2\left(\frac{v}{2}\right)\\z&=&1-e^{u/(3\pi)}-\sin(v)+e^{u/(6\pi)}\sin(v)\end{eqnarray*}$$
with parameters $u$ and $v$ in ranges $0\le u\le6\pi$ and $0\le v\le2\pi$.
Make a nice plot yourself using these equations, following the above
models. You might use a linspace with 60 steps in it for this,
it will look smoother.
When you have a nice mesh 3-D plot, try plotting it a second time instead with
surf(x,y,z);
Unfortunately, surf makes the edges of the facets of the surfaces
black (or a different color, at least, depending upon various color choices),
which can be ugly. So try again with
surf(x,y,z,'EdgeColor','none');
You might also see what happens with
axis equal
axis off
Exercises
Now do at least ten of the following graphs. Flip a coin or make a deal with
another student sitting near you so you are sure that together you cover all
the surfaces.
Experiment with the number of steps to use in your linspace
commands, to get something nice for surfaces you particularly like.
Also try in the surf command the options 'FaceColor' and
'FaceLighting', and try different colormaps. See the
help pages for suggested values. Or here are some possible
values to use for the colors, via a command like colormap("autumn"):
- autumn
- bone
- colorcube
- cool
- copper
- flag
- gray
- hot
- hsv
- jet
- ocean
- pink
- prism
- rainbow
- spring
- summer
- white
- winter
- The Möbius Strip: Parametric equations
$$\begin{eqnarray*}x&=&\frac{v}{2}\sin\frac{u}{2}\\y&=&\left(1+\frac{v}{2}\cos\frac{u}{2}\right)\sin u\\z&=&\left(1+\frac{v}{2}\cos\frac{u}{2}\right)\cos u\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $-1\le v\le1$.
- The Klein Bottle: Parametric equations
$$\begin{eqnarray*}x&=&\left(r+\cos\frac{u}{2}\sin v-\sin\frac{u}{2}\sin2v\right)\cos u\\y&=&\left(r+\cos\frac{u}{2}\sin v-\sin\frac{u}{2}\sin2v\right)\sin u\\z&=&\sin\frac{u}{2}\sin v+\cos\frac{u}{2}\sin2v\end{eqnarray*}$$ with parameters $r=1$, and $u$ and $v$ having ranges $0\le u,v\le2\pi$.
(Try colormap('hot').)
- Enneper's Surface: Parametric equations
$$\begin{eqnarray*}x&=&u-u^3/3+uv^2\\y&=&v-v^3/3+u^2v\\z&=&u^2-v^2\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-1.5\le u,v\le1.5$.
- Ellipsoids: Parametric equations
$$\begin{eqnarray*}x&=&a\cos u\sin v\\y&=&b\sin u\sin v\\z&=&c\cos v\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $0\le v\le\pi$. Try $a=3$, $b=4$, and $c=5$. See what happens
when you vary $a$, $b$, and $c$ — can you explain why? (Use axis equal.)
- Hyperboloids of One Sheet: Parametric equations
$$\begin{eqnarray*}x&=&a\cosh(u)\cos(v)\\y&=&b\cosh(u)\sin(v)\\z&=&c\sinh(u)\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-2\le u\le2$ and $0\le v\le2\pi$. Try $a=b=c=1$, then vary them. Again,
use axis equal.
- Hyperboloids of Two Sheets: Parametric equations
$$\begin{eqnarray*}x&=&a\sinh(u)\cos(v)\\y&=&b\sinh(u)\sin(v)\\z&=&c\cosh(u)\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-2\le u\le2$ and $0\le v\le2\pi$. Try $a=b=c=1$, then $a=b=1$ but $c=-1$.
Again, use axis equal.
- The Lissajous Surface: Parametric equations
$$\begin{eqnarray*}x&=&\sin u\\y&=&\sin v\\z&=&\sin((d-au-bv)/c)\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-\pi\le u,v\le\pi$. Start with $a=b=c=1$ and $d=0$, then vary these.
Again, use axis equal.
- Whiney Umbrella: Parametric equations
$$\begin{eqnarray*}x&=&uv\\y&=&u\\z&=&v^2\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-1\le u,v\le1$.
Use axis equal.
- Steiner's Surface: Parametric equations
$$\begin{eqnarray*}x&=&\sin(2u)\cos^2(v)\\y&=&\sin(u)\sin(2v)\\z&=&\cos(u)\sin(2v)\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le\pi$ and $-\pi/2\le v\le\pi/2$.
Use axis equal.
- The Pseudosphere: Parametric equations
$$\begin{eqnarray*}x&=&\cos(u)\sin(v)\\y&=&\sin(u)\sin(v)\\z&=&\cos(v)+\ln(\tan(v/2))\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $0<v<\pi$. Be careful in your choices of grid
points since as $v$ gets close to 0 or $\pi$, $\ln(\tan(v/2))$ goes to
$\pm\infty$.
- Dini's Surface: Parametric equations
$$\begin{eqnarray*}x&=&\cos(u)\sin(v)\\y&=&\sin(u)\sin(v)\\z&=&\cos(v)+\ln(\tan(v/2))+au\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $0<v<\pi$. Again, the $\ln$ term has
problems as $v$ gets close to 0 or $\pi$.
- The Helicoid: Parametric equations
$$\begin{eqnarray*}x&=&av\cos(u)\\y&=&av\sin(u)\\z&=&bu\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$
and $-d<v<d$. Try different values of $a$, $b$, and $d$, and describe in
words what you see.
- Catenoid: Parametric equations
$$\begin{eqnarray*}x&=&a\cos(u)\cosh(v/a)\\y&=&a\sin(u)\cosh(v/a)\\z&=&v\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $-c<v<c$. Try different values of $a$ and $c$, and
describe what you see.
- The Torus: Parametric equations
$$\begin{eqnarray*}x&=&(a+b\cos(v))\cos(u)\\y&=&(a+b\cos(v))\sin(u)\\z&=&b\sin(v)\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $0\le u\le2\pi$ and $0\le v\le2\pi$. Try varying $a$ and $b$, describe.
- Alien Space Ship: Let $a=.4$ and $w=\sqrt{1-a^2}$. Use the
parametric equations
$$\begin{eqnarray*}x&=&-u+2w^2\cosh(au)\sinh(au)/d\\y&=&2w\cosh(au)\left(-w\cos(v)\cos(wv)-\sin(v)\sin(wv)\right)/d\\z&=&2w\cosh(au)\left(-w\sin(v)\cos(wv)+\cos(v)\sin(wv)\right)/d\end{eqnarray*}$$ with parameters $u$ and $v$ having ranges $-13.4\le u\le13.4$ and $-37.2\le v\le37.2$,
where $d=a\left((w\cosh(au))^2+(a\sin(wv))^2\right)$.