Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168769
Image: ubuntu2004

Cylinders

A "cylinder" is a 2d curve that is extruded perpendicular to the plane it's in.  For example, a circle becomes a cylinder.  To visualize this, imagine lots of copies of the curve stacked on top of each other.

c=circle((0,0), 1,thickness=3,rgbcolor='red') c.plot3d(z=0)+c.plot3d(z=1)+c.plot3d(z=2)

The equation for the circle is x2+y2=1x^2+y^2=1.  However, if we just consider the points in 3d, the zz-coordinate can be anything.  So the point (1,0,0)(1,0,0) and the points (1,0,z)(1,0,z) for any zz satisfy the equation x2+y2=1x^2+y^2=1.  So the equation of the cylinder is x2+y2=1x^2+y^2=1.

var('x,y,z') implicit_plot3d(x^2+y^2==1,(x,-2,2), (y,-2,2), (z,-2,2))+sum(c.plot3d(z=i) for i in [-2,-1.5..2])

Another example:

p=plot(sin(x), (x, -pi, pi),thickness=3,color='red') p
sum(p.plot3d(z=i) for i in [-2,-1.5..2])
var('x,y,z') implicit_plot3d(y==sin(x),(x,-pi,pi), (y,-1,1), (z,-2,2))+sum(p.plot3d(z=i) for i in [-2,-1.5..2])

Those were examples of cylinders that were extruded along the zz-axis.  We can also extrude along other axes.

p1=implicit_plot3d(y==sin(z), (x,-1,1), (y, -pi,pi),(z,-pi,pi)) p1
p2=implicit_plot3d(x==sin(z), (x,-pi,pi), (y, -1,1),(z,-pi,pi)) p2

Parametric curves (2d and 3d space curves): r(t)=x,y\vec r(t) = \langle x,y\rangle or r(t)=x,y,z\vec r(t)=\langle x,y,z\rangle

Parametric curves are most often used to model motion.  As things move through the plane or space, these two types of curves give an excellent way to keep track of motion.

Parametric curves in the plane are graphed as follows.

var('t') parametric_plot( (2*cos(t), sin(t)), (t, 0, 3*pi/2), axes_labels=('x', 'y'))

The following code separates rr and the bounds from the parametric_plot code, so that you can quickly find the things you wish to change right up front.  I generally place variables you wish to change at the top of my code, and then put the functions underneath (so that making changes can be done rapidly).

r=(2*cos(t), sin(t)) tbounds=(t,0,3*pi/2) parametric_plot(r, tbounds, axes_labels=('x','y'))
var('t') r=(2*cos(t), sin(t)) tbounds=(0, 3*pi/2) tmin,tmax=tbounds @interact def myplot(tt=slider(tmin.n(), tmax.n(),default=((tmin+tmax)/2).n())): p=parametric_plot(r, (t, tmin, tmax),alpha=0.5) background=parametric_plot(r, (t, tmin, tt),thickness=3) show(p+background)

To get a 3d parametric curve (i.e., a space curve), just add a third coordinate to r(t)\vec r(t).

var('t') r=(2*cos(t), sin(t), t) tbounds=(t,0,3*pi/2) parametric_plot(r, tbounds)

This section will use the derivative of a parametric curve to compute the vector equation of the tangent line. We’ll first do it using a static example, and then make it interactive.

var('x,y,t') r=vector((cos(t), sin(t),t)) tbounds=(t, 0, 2*pi) c=pi/4

Next, we compute the derivative of r\vec r.

rprime=diff(r, t) rprime
(-sin(t), cos(t), 1)

A point on the curve:

pt = r(t=c) pt
(1/2*sqrt(2), 1/2*sqrt(2), 1/4*pi)

A direction vector for the tangent line.  We get this by evaluating the derivative at a point, just like we would get a slope in 2d.

dirvec = rprime(t=c) dirvec
(-1/2*sqrt(2), 1/2*sqrt(2), 1)
tangent_line= dirvec*t+pt tangent_line
(-1/2*sqrt(2)*t + 1/2*sqrt(2), 1/2*sqrt(2)*t + 1/2*sqrt(2), 1/4*pi + t)
parametric_plot(list(tangent_line), (t,-2,2), color='red')+parametric_plot(list(r), tbounds,aspect_ratio=1)

Here is an interact that lets you see the tangent line at various points on the curve.

var('x,y,t') r=vector((cos(t), sin(t),t)) tbounds=(t, 0, 2*pi) rprime=diff(r, t) tmin,tmax=tbounds[1:] @interact def plot_tangent(c=(tmin,tmax)): pt=r(t=c) dirvec=rprime(t=c) tangent_line= dirvec*t+pt pline=parametric_plot(list(tangent_line), (t,-2,2), color='red') pcurve=parametric_plot(list(r), tbounds,aspect_ratio=1) show(pline+pcurve+point(list(pt), size=5))