# Untitled

## 962 days ago by pub

Options for parametric_plot.  My wikispaces page: http://sagemath.wikispaces.com/parametric_plot

This command does both 2d and 3d plots and both curves and surfaces.  Click and drag the 3d graphs to rotate!

parametric_plot( vector-parametric function , (t,tmin,tmax) ) for curve in 2D or 3D

parametric_plot( vector-parametric function , (u,umin,umax), (v,vmin,vmax ) for surface in 3D

Special Options for Curves: thickness

Usual Options: color, opacity, figsize, aspect_ratio, frame, mesh, dots, plot_points, axes, adaptive   (see also: plot3d - OPTIONS)

Here is a simple 2d parametric plot using a vector function r with 1 parameter t (curve) and 2 components (2D).

var ('t') r=vector((t,t^2)) parametric_plot(r,(t,-2,2), figsize=2)

Notice that parametric_plot is 2d or 3d depending on what it is plotting. (No separate command for 3d plot.)

The thickness of curves depends on the plot size and type. You may need to experiment.

Here is a plot of the basic helix; it is a curve in 3d so a parametric plot of a vector function with 3 components in 1 variable.

var ('t') r=vector((sin(t),cos(t),t)) parametric_plot(r,(t,-2*pi,2*pi),color='purple',thickness=5, aspect_ratio=(pi,pi,1))

Here is a parametric plot of a surface by parametric function with 2 parameters, (vector function with 3 components in 2 variables).

Notice the 2 ranges of the variables.  (This is a piece of the paraboloid: $x^2+y^2=2z$ where $1 \le z \le 2$.)

var ('u v') Sf=vector((sqrt(2*v)*cos(u),sqrt(2*v)*sin(u),v)) para=parametric_plot(Sf,(v,1,2),(u,0,2*pi),color='red', opacity=.7) show(para)

One problem with parametric plots is you cannot "see" the direction of parameters (as you can see e.g. the positive x-axis).

I often split my plots, coloring them from blue (min) to red (max). Increase/decrease num for more or less splits.

When I am lazy I simply break the interval into several separate plots (first 2 plots below); when I am ambitious I use the sum function (next 2).

var ('t') r=vector((sin(t),cos(t),t)) p1=parametric_plot(r,(t,-2*pi,-pi),color='blue',thickness=5, aspect_ratio=(pi,pi,1)) p2=parametric_plot(r,(t,-pi,0),color='green',thickness=5, aspect_ratio=(pi,pi,1)) p3=parametric_plot(r,(t,0,pi),color='orange',thickness=5, aspect_ratio=(pi,pi,1)) p4=parametric_plot(r,(t,pi,2*pi),color='red',thickness=5, aspect_ratio=(pi,pi,1)) show(p1+p2+p3+p4)
var ('u v') Sf=vector((sqrt(2*v)*cos(u),sqrt(2*v)*sin(u),v)) para1=parametric_plot(Sf,(v,1,2),(u,0,pi/2),color='blue', opacity=.7) para2=parametric_plot(Sf,(v,1,2),(u,pi/2,pi),color='green', opacity=.7) para3=parametric_plot(Sf,(v,1,2),(u,pi,3*pi/2),color='orange', opacity=.7) para4=parametric_plot(Sf,(v,1,2),(u,3*pi/2,2*pi),color='red', opacity=.7) show(para1+para2+para3+para4)
var ('u v') Sf=vector((sqrt(2*v)*cos(u),sqrt(2*v)*sin(u),v)) #Here is the split algorithm for u. num=8; umin=0; umax=2*pi; stepper=(umax-umin)/num Pu=sum([parametric_plot(Sf,(v,0,3),(u,umin+(j-1)*stepper,umin+j*stepper),rgbcolor=(j/num,0,1-j/num), opacity=.7) for j in [1..num,step=1]]) show(Pu)
var ('u v') Sf=vector((sqrt(2*v)*cos(u),sqrt(2*v)*sin(u),v)) #Here is same algorithm but on v. num=8; vmin=0; vmax=3; stepper=(vmax-vmin)/num Pv=sum([parametric_plot(Sf,(v,vmin+(j-1)*stepper,vmin+j*stepper),(u,0,2*pi),rgbcolor=(j/num,0,1-j/num), opacity=.7) for j in [1..num,step=1]]) show(Pv)

To plot a 2d curve in 3d (with z==0), you can add a component or add a plot of an actual 3d curve with opacity=0.

var ('t') r=vector((sin(t),cos(t),t)) #Because opacity=0, this is an invisible 3d curve so we get the 3d plot. p3=parametric_plot(r,(t,-2*pi,2*pi),opacity=0) #This is the projection of the 3d curve onto the x0y plane r2=vector((r[0],r[1])) #It will plot at z==0. p2_3=parametric_plot(r2,(t,-2*pi,2*pi),color='red',thickness=5) show(p3+p2_3, aspect_ratio=(pi,pi,1))

You can combine plot types as long as you obey the rules of each plot.

Click and drag to rotate this to see that we have projected the helix onto the circle.

#We define the helix curve var ('t') r=vector((sin(t),cos(t),t)) p3 = parametric_plot(r,(t,-2*pi,2*pi),opacity=0.5,thickness=3,aspect_ratio=(3,3,1)) #We project the curve onto the x0y plane r2=vector((r[0],r[1])) p2_3 = parametric_plot(r2,(t,-2*pi,2*pi),color='red',thickness=3) #We graph the x0y plane using implicit_plot3d var ('x y z') px0y= implicit_plot3d(z==0,(x,-1,1),(y,-1,1),(z,-2*pi,2*pi), color='grey', opacity=0.3) show(p3+p2_3+px0y)
# We did this plot as part of solving a surface integral of flux type over an ellipse: #3 http://sagemath.wikispaces.com/Surface+integral+flux+type var('u v'); a=2; b=3; c=4 Sf=vector((a*cos(u)*sin(v),b*sin(u)*sin(v),c*cos(v))) S=parametric_plot(Sf,(u,0,2*pi),(v,0,pi), color='purple', opacity=.5, aspect_ratio=(1,1,1)) # vs is the vector scale; notice again the use of sum to make multiple plots (here 3d arrows) vs=4 vf=sum([sum([arrow3d((a*cos(j)*sin(k),b*sin(j)*sin(k),c*cos(k)),(a*cos(j)*sin(k)+a*cos(j)*sin(k)*(1.0/(a*b)*(c^2+b^2*(sin(j))^2)*sin(k)+b/a*sin(k)*(cos(j))^2+a*b*sin(k))/vs,b*sin(j)*sin(k)+b*sin(j)*sin(k)*(1.0/(a*b)*(c^2+b^2*(sin(j))^2)*sin(k)+b/a*sin(k)*(cos(j))^2+a*b*sin(k))/vs,c*cos(k)+c*cos(k)*(1.0/(a*b)*(c^2+b^2*(sin(j))^2)*sin(k)+b/a*sin(k)*(cos(j))^2+a*b*sin(k))/vs), color=hue((j+8)/8), width=8) for k in [0..pi,step=pi/4]]) for j in [0..2*pi,step=pi/4]]) # We draw the axes var ('t') Ax=parametric_plot(vector((t,0,0)),(t,-a,a), color='yellow', thickness=3) Ay=parametric_plot(vector((0,t,0)),(t,-b,b), color='pink', thickness=3) Az=parametric_plot(vector((0,0,t)),(t,-c,c), color='lightgreen', thickness=3) # Hang in there, it takes forever to plot but it is cool. show(S+Ax+Ay+Az+vf, aspect_ratio=(1,1,1))
var('t'); parametric_plot((cos(t),sin(-1.7*t), cos(-1.7*t)),(t,0,10), thickness=8, figsize=4)
 t t
var('u v'); parametric_plot((u+5*cos(v),5*sin(v),u),(u,0,10), (v,0,2*pi), opacity=0.7, figsize=4)
 (u, v) (u, v)