3.5 Space Curves in Matlab
3.5 Space Curves in Matlab
3.5 Space Curves in Matlab
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
246 Chapter 3 Plott<strong>in</strong>g <strong>in</strong> <strong>Matlab</strong><br />
mhndl1=mesh(x,y,z)<br />
set(mhndl1,...<br />
’EdgeColor’,[0.6,0.6,0.6])<br />
axis equal<br />
axis off<br />
A circle of radius r centered at the orig<strong>in</strong> has equation x 2 + y 2 = r 2 . If we plot<br />
the set of all (x, y, z) such that x 2 + y 2 = r 2 , the result is a right-circular cyl<strong>in</strong>der<br />
of radius r. Replace x with x − r to get (x − r) 2 + y 2 = r 2 , which will shift<br />
the cyl<strong>in</strong>der r units <strong>in</strong> the x-direction. One f<strong>in</strong>al question rema<strong>in</strong>s. How can we<br />
parametrize the cyl<strong>in</strong>der (x − r) 2 + y 2 = r 2 ?<br />
It’s fairly straightforward to show that the parametric equations<br />
x = r cos t<br />
y = r s<strong>in</strong> t<br />
(<strong>3.5</strong>)<br />
produce a circle of radius r centered at the orig<strong>in</strong> 3 . This can be verified with<br />
<strong>Matlab</strong>’s comet or plot command 4 . To shift this r units <strong>in</strong> the x-direction add<br />
r to the equation for x to obta<strong>in</strong><br />
x = r + r cos t<br />
y = r s<strong>in</strong> t.<br />
Thus, the parametric equations of the right-circular cyl<strong>in</strong>der (x − r) 2 + y 2 = r 2<br />
are<br />
x = r + r cos t<br />
y = r s<strong>in</strong> t<br />
z = z.<br />
The key to plott<strong>in</strong>g the cyl<strong>in</strong>der <strong>in</strong> <strong>Matlab</strong> is to realize that x, y, and z are<br />
functions of both t and z. That is,<br />
x(t, z) = r + r cos t<br />
y(t, z) = r s<strong>in</strong> t<br />
z(t, z) = z.<br />
Therefore, the first task is to create a grid of (t, z) pairs.<br />
(3.6)<br />
It will suffice to let 0 ≤ t ≤ 2π. That should trace out the circle. If we hope<br />
to see the <strong>in</strong>tersection of the sphere (radius 2r) and the cyl<strong>in</strong>der, we will need to<br />
x2 + y2 = r2 cos2 t + r2 s<strong>in</strong> 2 t = r2 (cos2 t + s<strong>in</strong> 2 t) = r2 3<br />
.<br />
4<br />
And axis equal.