Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168737
Image: ubuntu2004

Plotting Planar Curves

In MATH 161 you worked a great deal with scalar functions of one variable y=f(x)y = f(x).  There is a straightforward method for plotting the graph of such a function.  We illustrate this for the "sinc" function (that is, sin(x)/xsin(x)/x) below.

var('x') f(x) = sin(x)/x plot(f(x), (x, -6*pi, 6*pi))

Plotting planar curves using parametrization

Another way to plot this same curve is using the parametric_plot() command, whose syntax is only mildly different than the plot() command in the previous cell.

var('x') parametric_plot((x, sin(x)/x), (x, -6*pi, 6*pi))

The idea for a (planar) parametric curve is that there is a single parameter which runs through some interval of numbers and, as it does so, xx and yy both change.  In the above cell, xx itself was the parameter.  It is equally valid to use yy as the parameter.  But parametric curves become even more useful when we introduce a third variable, say tt, as the parameter.  Both variables (xx and yy) become dependent upon the parameter.  We do not have to give any explicit relationship between xx and yy and, indeed, the relation between them may not be a function at all.  The cell below employs this technique in order to produce a plot of the unit circle.

var('t') x(t) = cos(t) y(t) = sin(t) # Note we are not using any formula of the form y = f(x) parametric_plot((x(t), y(t)), (t, -pi, pi), aspect_ratio=1)

The parameter tt in the previous cell ran through the interval [π,π][-\pi, \pi] in producing this curve.  Any interval of length 2π2\pi would have produced the same curve.  A shorter interval would have yielded only a partial circle, while a longer interval would have yielded a curve that wraps over onto itself.

No doubt, if you own a graphing calculator, what we have done thus far may be duplicated on it using the calculators parametric mode for graphing.

Parametric Curves in 3D

There is nothing particularly difficult about plotting curves in 3-dimensional space, once we are familiar with parametric curves in two dimensions.  There is still only one parameter which roams through some interval of values.  The only difference (besides the slight change in the name of the command) is that we need to express how the third (zz) coordinate relies on that parameter.  The parametric equations

   x(t)=cos(t)x(t) = cos(t),         y(t)=2sin(t)y(t) = 2 sin(t),         z(t)=t/5z(t) = t / 5,

describe a helical coil in space, as the next cell demonstrates.

parametric_plot3d((cos(t), 2*sin(t), t/5), (t, 0, 25), aspect_ratio=[1,1,1])

Parametrized Surfaces

Up to this point we have been plotting parametrized curves.  For such curves, the parameter runs through some interval II of numbers, and the parameter functions x(t)x(t), y(t)y(t), z(t)z(t) describe how that interval is morphed into some space curve.

We may now ask, what if there are two parameters -- call them uu and vv -- and xx, yy, zz each depend on both of these parameters?  We get a rich collection of examples when we consider the conversions between rectangular, cylindrical and spherical coordinates.  For instance, the equations describing the conversion between spherical coordinates (ρ,ϕ,θ)(\rho, \phi, \theta) and rectangular coordinates (x,y,z)(x,y,z) are

     x=ρsinϕcosθx = \rho\sin\phi\cos\theta,         y=ρsinϕsinθy = \rho\sin\phi\sin\theta,        z=ρcosϕz = \rho\cos\phi.

Spherical coordinates with ρ\rho fixed (so ϕ\phi and θ\theta are parameters)

If we fix the value of ρ\rho at 1, and allow ϕ\phi to roam in the interval [0,π][0, \pi], θ\theta in [π,π][-\pi, \pi], the result should be a sphere of radius 1.  The next cell (in which we use uu and vv in place of ϕ\phi and θ\theta) illustrates this.

var('u v') parametric_plot3d((sin(u)*cos(v), sin(u)*sin(v), cos(u)), (u,0,pi), (v,-pi,pi))

By changing to a smaller interval for ϕ\phi or θ\theta, you can get various parts of this same sphere.  Changing the value of ρ\rho to 2 has a predictable effect on the radius.  These ideas are illustrated next.

var('u v') r = 2 parametric_plot3d((r*sin(u)*cos(v), r*sin(u)*sin(v), r*cos(u)), (u,0,pi/2), (v,-pi,0), aspect_ratio=[1,1,1])

Spherical coordinates with ϕ\phi fixed

If, on the other hand, we fix the value of some other one of the spherical coordinates -- say, ϕ\phi -- and let ρ\rho and θ\theta roam through intervals, the resulting surface changes.  In the next cell, we fix ρ=π/6\rho = \pi/6, and let ρ\rho roam through the interval [2,10][2, 10], θ\theta through [0,2π][0, 2\pi].  (Recall that sin(π/6)=1/2\sin(\pi/6) = 1/2 and cos(π/6)=3/2\cos(\pi/6) = \sqrt 3/2.  These values have been used below.)

var('r v') parametric_plot((r*cos(v)/2, r*sin(v)/2, r*sqrt(3)/2), (r,2,10), (v,0,2*pi))

Cylindrical coordinates with rr fixed

As with spherical coordinates, there are three cylindrical coordinates (r,θ,z)(r, \theta, z). If we fix the value of any one of them while letting the other two roam through intervals of the real line, the result is a parametrized surface. The transformations from cylindrical to rectangular coordinates are

     x=rcosθx = r\cos\theta        and        y=rsinθy = r\sin\theta.

(The zz-coordinate is the same in both.) In the cell below, we fix the value of rr at 2, and allow θ\theta to roam in [0,3π/2][0, 3\pi/2], zz in [0,5][0,5], resulting in a portion of a right circular cylinder.

var('u v') parametric_plot3d((2*cos(u), 2*sin(u), v), (u,0,3*pi/2), (v,0,5))

You should play around with these methods for employing spherical and cylindrical coordinates to produce different types of surfaces until you feel quite comfortable with them.  In particular, you should explore what happens when you fix the value of θ\theta in spherical coordinates and use ρ\rho, ϕ\phi as parameters in various intervals.  You should also explore cylindrical coordinates further, fixing zz (i.e., rr and θ\theta are the parameters) and then θ\theta.

Other surfaces

Finally, you should not walk away from this lesson thinking the only value parametrized surfaces arise from spherical and cylindrical coordinates.  Here are a couple more interesting examples that have nothing to do with either.

Torus:

var('u v t') a = 3 # distance from z-axis to circle at center of tube b = 2 # radius of torus = parametric_plot3d(((a+b*cos(u))*cos(v), (a+b*cos(u))*sin(v), b*sin(u)), \ (u,0,2*pi), (v,0,2*pi), aspect_ratio=[1,1,1], opacity=.5) # extra stuff to explain the role of 'a' and 'b' innerCircle = parametric_plot((a*cos(t), a*sin(t), 0), (t,-pi,pi), \ color='red', thickness=2) radii = line([(0,0,0),(a,0,0)], color='red', thickness=2) radii += line([(a,0,0),(a+b*sqrt(2)/2,0,b*sqrt(2)/2)], color='red', thickness=2) radii += line([(a,0,0),(a+b*sqrt(2)/2,0,-b*sqrt(2)/2)], color='red', thickness=2) labels = text3d('a', (a/2, 0, .3), color='red') labels += text3d('b', (a+b*sqrt(2)/4,0,b*sqrt(2)/4+.4), color='red') labels += text3d('b', (a+b*sqrt(2)/4,0,-b*sqrt(2)/4-.4), color='red') show(torus + innerCircle + radii + labels)

Surface of rotation

Next, we take an initial curve in the xyxy-plane, and rotate it around the xx-axis to produce a surface of rotation.  The initial curve is y=1+cosxy = 1 + |\cos x|, for xx in the interval [0,4π][0, 4\pi].

var('x u v') r(x) = 1 + abs(cos(x)) # first plot the curve itself in the xy-plane plot(r(x), (x,0,4*pi)).show() parametric_plot3d((u, r(u)*cos(v), r(u)*sin(v)), (u,0,4*pi), (v,-pi,pi))

Mobius band

This is an interesting type of surface, as it is non-orientable.  Said another way, it has just one side.  You can actually make one of these out of a strip of paper and tape or glue.

var('u v') parametric_plot3d(((1+v*cos(u/2))*cos(u), (1+v*cos(u/2))*sin(u), v*sin(u/2)), \ (u,0,2*pi), (v,-.8,.8), aspect_ratio=[1,1,1])