0% found this document useful (0 votes)
46 views20 pages

3.4 Parametric Surfaces in Matlab: Sketch The Surface Defined by The Parametric Equations

Uploaded by

ARJUN SIKKA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views20 pages

3.4 Parametric Surfaces in Matlab: Sketch The Surface Defined by The Parametric Equations

Uploaded by

ARJUN SIKKA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Section 3.

4 Parametric Surfaces in Matlab 219

3.4 Parametric Surfaces in Matlab


In this section we will again examine surfaces in three-space. However, the
position of a point on the surface will be defined in terms of parameters. In this
way we open a fascinating world of surfaces that you may never have seen before,
in much the same way that parametric equatins opened a whole new world of
curves in the plane.
Let’s get started.

I Example 1. Sketch the surface defined by the parametric equations


x = r cos θ
y = r sin θ (3.1)
z = r,

where 0 ≤ r ≤ 1 and 0 ≤ θ ≤ 2π.

Note that x, y, and z are defined in terms of two parameters, r and θ, which
are restriced to 0 ≤ r ≤ 1 and 0 ≤ θ ≤ 2π. The first task is to create a grid of
(r, θ) pairs, after which each pair (r, θ) will be mapped to a triplet (x, y, z) on the
surface via the parametric equations (3.1).
First, use the linspace commands to create vectors r and θ.

r=linspace(0,1,30);
theta=linspace(0,2*pi,30);

When using Matlab’s mesh command, too few grid points will create a surface
with the “Jaggies,” but too many grid points will create a mesh that appears
to be a solid mass of color, and you’ll be unable to distinguish grid lines on the
surface. The number 30 usually provides a nice number of grid points to start
your exploration, then you can adjust upward or downward from there.
The next step is to create the grid of (r, θ) pairs with Matlab’s meshgrid
command.

[r,theta]=meshgrid(r,theta);

1 Copyrighted material. See: http://msenux.redwoods.edu/Math4Textbook/


220 Chapter 3 Plotting in Matlab

If you remove the semicolons in each of the previous commands, you’ll note that
r and θ were first vectors, but after the meshgrid command, r and θ are matri-
ces. If your find this overwriting using the same variable distasteful, you can try
something like [R,THETA]=meshgrid(r,theta) instead. However, we have no
further use of the vectors r and θ, so we are perfectly happy overwriting r and θ
with the matrix output of the meshgrid command.
At this point, each row of the matrix r contains the contents of the former
vector r, and each column of the matrix θ contains the contents of the vector θ. If
you mentally superimpose the matrix θ atop the matrix r, you can imagine a two
dimensional grid of (r, θ) pairs. We now use the parametric equations (3.1) to
compute the triplets (x, y, z) at each pair (r, θ) in the grid. Note that this requires
the use of array operators, as one would expect.

x=r.*cos(theta);
y=r.*sin(theta);
z=r;

Each triplet (x, y, z) is a point on the surface. We can use the mesh command
to connect neighboring points with line segments.

mesh(x,y,z)

We orient the axis, “tighten” the plot, and turn the box on to provided some
depth to the visualization.

view(135,30)
axis tight
box on

Finally, labeling the axes helps us to visualize the orientation, as we can clearly
see in Figure 3.1.

xlabel(’x-axis’)
ylabel(’y-axis’)
zlabel(’z-axis’)
Section 3.4 Parametric Surfaces in Matlab 221

Figure 3.1. The surface defined by the parametric equations (3.1)


is a cone.

Let’s look at another example.

I Example 2. Sketch the surface defined by the equations


x = sin φ cos θ
y = sin φ sin θ (3.2)
z = cos φ,

where 0 ≤ φ ≤ π and 0 ≤ θ ≤ 2π.

First, create vectors φ and θ so that 0 ≤ φ ≤ π and 0 ≤ θ ≤ 2π.

phi=linspace(0,pi,30);
theta=linspace(0,2*pi,30);

Now, create a grid of (φ, θ) pairs.

[phi,theta]=meshgrid(phi,theta);

Use the parametric equations (3.2) to calculate surface triplets (x, y, z) at each
grid pair (φ, θ). Again, array operators are required.
222 Chapter 3 Plotting in Matlab

x=sin(phi).*cos(theta);
y=sin(phi).*sin(theta);
z=cos(phi);

We can now create a mesh of the surface with Matlab’s mesh command.

mesh(x,y,z)

We adjust the orientation, turn the box on to add depth of visualization, then
issue axis equal command to show that the surface is actually a sphere, and not
an ellipsoid.

axis equal
view(135,30)
box on

Finally, we annotate the axes to produce the final image in Figure 3.2.

xlabel(’x-axis’)
ylabel(’y-axis’)
zlabel(’z-axis’)T

Let’s look at another example. It’s time to have some fun!

I Example 3. Sketch the graph of the surface defined by the parametric


equations
h i v 
x = 2 1 − eu/(6π) cos u cos2
2 
2 v
h i 
u/(6π) (3.3)
y = 2 −1 + e sin u cos
2
u/(3π) u/(6π)
z =1−e − sin v + e sin v,

where 0 ≤ u ≤ 6π and 0 ≤ v ≤ 2π.

First, create vectors u and v so that 0 ≤ u ≤ 6π and 0 ≤ v ≤ 2π.


Section 3.4 Parametric Surfaces in Matlab 223

Figure 3.2. The surface defined by the parametric equations (3.2)


is a sphere.

u=linspace(0,6*pi,60);
v=linspace(0,2*pi,60);

Use the vectors u and v to create a grid of (u, v) pairs.

[u,v]=meshgrid(u,v);

Use the parametric equations (3.3) to compute (x, y, z) triplets at each (u, v)
pair in the grid. Again, array operators are expected.

x=2*(1-exp(u/(6*pi))).*cos(u).*cos(v/2).^2;
y=2*(-1+exp(u/(6*pi))).*sin(u).*cos(v/2).^2;
z=1-exp(u/(3*pi))-sin(v)+exp(u/(6*pi)).*sin(v);

Create a mesh of the surface with Matlab’s mesh command.

mesh(x,y,z)
224 Chapter 3 Plotting in Matlab

Adjust the orientation, set axis equal, and turn the box on to add depth to the
visualization.

view(160,10)
axis equal
box on

Annotate the axes in the usual manner to produce the final “seashell” in Figure 3.3.

Figure 3.3. Can you hear the sound of the ocean?

Matlab also offers a surf command which colors the patches between the gridlines.
We need only execute surf(x,y,z) to see the effect in Figure 3.4(a).

surf(x,y,z)

You might want to turn off hidden line removal and use the rotation tool on the
figure toolbar to turn and twist the figure.

hidden off

Finally, Matlab offers truly stunning graphics capabilities. We can use the surf
command in combination with edge and face coloring techniques, add lighting,
and turn the axes off to produce an image in Figure 3.4(b) that is quite beautiful.
Section 3.4 Parametric Surfaces in Matlab 225

surf(x,y,z,...
’FaceColor’,’interp’,...
’EdgeColor’,’none’,...
’FaceLighting’,’phong’)
camlight left
view(160,10)
axis equal
axis off

(a) (b)
Figure 3.4. A surface plot instead of a mesh colors the patches between meshlines on
the surface. Adding lighting makes for a beautiful image.

Parametric surfaces are just too much fun! Let’s look at another example.

I Example 4. Sketch the surface defined by the parametric equations


v u
x = sin
2 2
v u
y = 1 + cos sin u (3.4)
2 2
 v u
z = 1 + cos cos u,
2 2
where 0 ≤ u ≤ 2π and −1 ≤ v ≤ 1.
226 Chapter 3 Plotting in Matlab

Create the grid with the constraints 0 ≤ u ≤ 2π and −1 ≤ v ≤ 1.

u=linspace(0,2*pi,30);
v=linspace(-1,1,15);
[u,v]=meshgrid(u,v);

Use the parametric equations (3.4) to compute surface triplete (x, y, z) at each
(u, v) in the grid.

z=(r+v/2.*cos(u/2)).*cos(u);
y=(r+v/2.*cos(u/2)).*sin(u);
x=v/2.*sin(u/2);

Draw the surface.

surf(x,y,z)

Choose the pink colormap 2 set the axis equal, and add box on to help with
the depth of the visualization.

box on
axis equal
colormap pink

Finally, we set the orientation in order to compare our result in Figure 3.5(a)
with the famous Mobius Strip drawn by Escher in Figure 3.5(b).
You can create a Mobius strip on your own. Simply take a long strip of paper,
maybe 1-2 inches wide by 12-24 inches in length. Twist the strip once, then glue
the ends together to match what you see in Figures 3.5(a) and (b). As the ants
walk along the strip, they quickly learn that the strip has only one side, not two.
The Mobius Strip is an important example that is closely studied in a subject
called differential geometry.

2 For information on the available colormaps in Matlab, type help graph3d at the command
prompt.
Section 3.4 Parametric Surfaces in Matlab 227

(a) (b)
Figure 3.5. The classic Mobius Strip has only one side.

Let’s look at one final example, the Klein Bottle.

I Example 5. Sketch the surface defined by the parametric equations


 u u 
x = r + cos sin v − sin sin 2v cos u
2 2
 u u 
y = r + cos sin v − sin sin 2v sin u (3.5)
2 2
u u
z = sin sin v + cos sin 2v,
2 2
with r = 1 and 0 ≤ u, v ≤ 2π.

Set r = 1, then create the grid with constraints 0 ≤ u, v ≤ 2π.

r=1;
u=linspace(0,2*pi,60);
v=linspace(0,2*pi,60);
[u,v]=meshgrid(u,v);

Calculate surface triplets (x, y, z) at each grid pair (u, v), using equations (3.5).
228 Chapter 3 Plotting in Matlab

x=(r+cos(u/2).*sin(v)-sin(u/2).*sin(2*v)).*cos(u);
y=(r+cos(u/2).*sin(v)-sin(u/2).*sin(2*v)).*sin(u);
z=sin(u/2).*sin(v)+cos(u/2).*sin(2*v);

Use the surf command to draw the surface, a Klein Bottle. We’ll use the default
view. The result is shown in Figure 3.6(a).

surf(x,y,z)

Let the creative juices flow! Do some interpretation of edge and face color, add
some lighting, and voila! You obtain the beautiful image shown in Figure 3.6(b).

(a) (b)
Figure 3.6. A Klein Bottle, one plain, one pretty! Both fascinating!

Here is the code used to do the fancy shading and lighting seen in Figure 3.6(b).
Section 3.4 Parametric Surfaces in Matlab 229

surf(x,y,z,...
’FaceColor’,’interp’,...
’EdgeColor’,’none’,...
’FaceLighting’,’phong’)
camlight left
colormap(hot)
axis off

Note the new choice of colormap, the “hot” colormap, which adds a “heated look”
to the surface of our Klein Bottle. Click the rotate icon on the toolbar, then use
the mouse to twist and turn and explore this fascinating surface!
Finally, check out the hand-made Klein Bottle in Figure 3.7 crafted by an
artist.

Figure 3.7. An artist’s


rendering of a Klein Bottle.
230 Chapter 3 Plotting in Matlab

3.4 Exercises

1. Sketch the Enneper’s Surface de- 4. Sketch the Hyperboloid of One Sheet
fined by the parametric equations defined by the parametric equations
x = u − u3 /3 + uv 2 x = a cosh(u) cos v
3 2 y = b cosh u sin v
y = v − v /3 + u v
z = u2 − v 2 , z = c sinh u,

where −1.5 ≤ u, v ≤ 1.5. where −2 ≤ u ≤ 2 and 0 ≤ v ≤ 2π.


Start with a = 1, b = 1, and c = 1,
2. Sketch the Ellipsoid defined by the then experiment by varying the values
parametric equations of a, b, and c. Explain the effect of
varying a, b, and c. You will want to
x = a cos u sin v use axis equal on this exercise.
y = b sin u sin v
z = c cos v, 5. Sketch the Hyperboloid of Two Sheets
defined by the parametric equations
where 0 ≤ u ≤ 2π and 0 ≤ v ≤ π.
Start with a = 3, b = 4, and c = 5, x = a sinh u cos v
then experiment by varying the values y = b sinh u sin v
of a, b, and c. Explain the effect of z = c cosh u,
varying a, b, and c. You will want to
use axis equal on this exercise. where −2 ≤ u ≤ 2 and 0 ≤ v ≤ 2π.
Start with a = 1, b = 1, and c = 1,
3. Sketch the Hyperboloid of One Sheet then hold the graph and plot again
defined by the parametric equations with a = 1, b = 1, and c = −1 to
see why this is called a Hyperboloid
x = a cosh(u) cos v of Two Sheets.
y = b cosh u sin v
z = c sinh u, 6. Sketch the Lissajous Surface de-
fined by the parametric equations
where −2 ≤ u ≤ 2 and 0 ≤ v ≤ 2π.
Start with a = 1, b = 1, and c = 1, x = sin u
then experiment by varying the values y = sin v
of a, b, and c. Explain the effect of z = sin((d − au − bv)/c),
varying a, b, and c. You will want to
use axis equal on this exercise. where −π ≤ u, v ≤ π. Set a = 1,
b = 1, c = 1 and d = 0. You will want
to use axis equal on this exercise.
Section 3.4 Parametric Surfaces in Matlab 231

7. Sketch the Whitney Umbrella de- minus or positive infinity. Keep this
fined by the parametric equations in mind when selecting a vector v to
be used in an eventual grid of (u, v)
x = uv
pairs. Experiment with different val-
y=u ues of the constant a.
z = v2,
11. Sketch Helicoid defined by the
where −1 ≤ u, v ≤ 1. You will want parametric equations
to use axis equal on this exercise.
x = av cos u
8. Sketch the Steiner Surface defined y = av sin u
by the parametric equations
z = bu,
x = sin 2u cos2 v
where 0 ≤ u ≤ 2π and −d < v < d,
y = sin u sin 2v d > 0. Experiment with different val-
z = cos u sin 2v, ues of the constants a, b, and d, then
write a short description explaining
where 0 ≤ u ≤ π and −π/2 ≤ v ≤
how varying each of the constants a,
π/2. You will want to use axis equal
b, and d affects the surface.
on this exercise.
12. Sketch Catenoid defined by the
9. Sketch the Pseudosphere defined
parametric equations
by the parametric equations
x = cos u sin v x = a cos u cosh(v/a)
y = sin u sin v y = a sin u cosh(v/a)
z = cos v + ln(tan(v/2)), z = v,

where 0 ≤ u ≤ 2π and 0 < v < π. where 0 ≤ u ≤ 2π and −c < v <


Note that when v nears zero or π, the c, c > 0. Experiment with different
term ln(tan(v/2) “leaks” to either mi- values of the constants a and c, then
nus or positive infinity. Keep this in write a short description explaining
mind when selecting a vector v to be how varying each of the constants a
used in an eventual grid of (u, v) pairs. and c affects the surface.

10. Sketch Dini’s Surface defined by 13. Sketch Torus defined by the para-
the parametric equations metric equations

x = cos u sin v x = (a + b cos v) cos u


y = sin u sin v y = (a + b cos v) sin u
z = cos v + ln(tan(v/2)) + au, z = b sin v,

where 0 ≤ u ≤ 2π and 0 < v < where 0 ≤ u ≤ 2π and 0 ≤ v ≤


π. Note that when v nears zero or π, 2π. Experiment with different values
the term ln(tan(v/2) “leaks” to either of the constants a and b, then write a
232 Chapter 3 Plotting in Matlab

short description explaining how vary-


ing each of the constants a and b af-
fects the surface.

14. Sketch the Alien Space


√ Ship. Set
a = 0.4 and define w = 1 − a2 . De-
fine

d = a (w cosh(au))2 + (a sin(wv))2 .
 

Now, define the parametric equations


x = −u + 2w2 cosh(au) sinh(au)/d
 
y = 2w cosh(au) − w cos v cos(wv) − sin v sin(wv) /d
 
z = 2w cosh(au) − w sin v cos(wv) + cos v sin(wv) /d,

where −13.4 ≤ u ≤ 13.4 and −37.2 ≤


v ≤ 37.2. Blast off!
Section 3.4 Parametric Surfaces in Matlab 233

3.4 Answers

1. Create the grid and calculate x, 3. Set some constants and create the
y, and z at each (u, v) pair of the grid. grid.

u=linspace(-1.5,1.5,40); a=1; b=1; c=1;


v=u; u=linspace(-2,2,40);
[u,v]=meshgrid(u,v); v=linspace(0,2*pi,40);
x=u-u.^3/3+u.*v.^2; [u,v]=meshgrid(u,v);
y=v-v.^3/3+u.^2.*v;
z=u.^2-v.^2;
Calculate x, y,a dn z at each pair
(u, v) in the grid.
Draw the surface, add some an-
notations, and adjust the view.
x=a*cosh(u).*cos(v);
y=b*cosh(u).*sin(v);
mesh(x,y,z) z=c*sinh(u);
xlabel(’x-axis’)
ylabel(’y-axis’)
zlabel(’z-axis’) Draw the surface, add some an-
title(’Enneper’’s Surface’) notations, and adjust the view.
view(160,30)
mesh(x,y,z)
xlabel(’x-axis’)
ylabel(’y-axis’)
zlabel(’z-axis’)
title(’Hyperboloid of One Sheet’)
view(160,30)
234 Chapter 3 Plotting in Matlab

mesh(x,y,z)

Now, hold the graph, set c = −1,


and repeat.

hold on
c=-1;
x=a*sinh(u).*cos(v);
y=b*sinh(u).*sin(v);
z=c*cosh(u);
mesh(x,y,z)

Annotate the plot.


After some experimentation with
values of a, b, and c, both a and b
xlabel(’x-axis’)
control the elliptical nature of cross
ylabel(’y-axis’)
sections parallel to the xy-plane, and
zlabel(’z-axis’)
c contols the height of the cone. The
title(’Hyperboloid of Two Sheets’)
command axis equal will help in this
exploration.

5. Set some constants and create the


grid.

a=1; b=1; c=1;


u=linspace(-2,2,40);
v=linspace(0,2*pi,40);
[u,v]=meshgrid(u,v);

Calculate x, y, and z at each (u, v)


in the grid.

x=a*sinh(u).*cos(v);
y=b*sinh(u).*sin(v);
z=c*cosh(u);
7. Set up the grid.

Draw the mesh.


Section 3.4 Parametric Surfaces in Matlab 235

fairly close to 0 and π in computing


u=linspace(-1,1,40); v.
v=u;
[u,v]=meshgrid(u,v);
u=linspace(0,2*pi,40);
v=linspace(pi/48,47*pi/48,40);
Compute x, y, and z at each pair [u,v]=meshgrid(u,v);
(u, v) in the grid.

Use the parametric equations to


x=u.*v; determine x, y, and z at each (u, v)
y=u; pair of the grid.
z=v.^2;

x=cos(u).*sin(v);
Draw and orient the surface, then y=sin(u).*sin(v);
annotate the plot. z=cos(v)+log(tan(v/2));

mesh(x,y,z) We use the surf command with


view(130,30) some shading and lighting. For fun,
xlabel(’x-axis’) we use a different colormap.
ylabel(’y-axis’)
zlabel(’z-axis’)
title(’Whitney Umbrella’) surf(x,y,z,...
’FaceColor’,’interp’,...
’EdgeColor’,’none’,...
’FaceLighting’,’phong’)
camlight left
colormap(copper)

We set axis equal, then axis off,


orient the view, and add a title.

axis equal
axis off
view(160,10)
title(’Pseudosphere.’)

9. Set up the grid. We chose to get


236 Chapter 3 Plotting in Matlab

surf(x,y,z,...
’FaceColor’,’interp’,...
’EdgeColor’,’none’,...
’FaceLighting’,’phong’)
camlight left
colormap(hot)

We set axis equal, orient the


view, and add a title.

axis equal
view(160,10)
title(’Helicoid.’)

11. Set up some constants.

a=1; b=1; d=2;

Set up the grid.

u=linspace(0,2*pi,40);
v=linspace(-d,d,40);
[u,v]=meshgrid(u,v);

Use the parametric equations to


determine x, y, and z at each (u, v)
pair of the grid.

13. Set up some constants.


x=a*v.*cos(u);
y=a*v.*sin(u);
z=b*u; a=5; b=1;

We use the surf command with Set up the grid.


some shading and lighting. For fun,
we use a different colormap.
Section 3.4 Parametric Surfaces in Matlab 237

u=linspace(0,2*pi,40);
v=u;
[u,v]=meshgrid(u,v);

Use the parametric equations to


determine x, y, and z at each (u, v)
pair of the grid.

x=(a+b*cos(v)).*cos(u);
y=(a+b*cos(v)).*sin(u);
z=b*sin(v);

We use the surf command with


some shading and lighting. For fun,
we use a different colormap.

surf(x,y,z,...
’FaceColor’,’interp’,...
’EdgeColor’,’none’,...
’FaceLighting’,’phong’)
camlight left
colormap(winter)

We set axis equal, turn the axes


off, orient the view, and add a title.

axis equal
axis off
view(150,20)
title(’Torus.’)

You might also like