topic:  parameterizations of lines and circles
description:  introduces the ParametricPlot command.  Distinguishes between a given parameterization and the underlying curve through animation.
file name:  parametric.nb
directions:  Read the text cells for background information.  Execute any existing input cells as you come to them.  Answer questions or work exercises as you come to them.  Modify the existing input cells as needed to work exercises requiring the use of Mathematica.

Needs["Graphics`Colors`"]
Off[General::spell];
Off[General::spell1];
Off[ParametricPlot3D::ppcom];
Off[ParametricPlot::ppcom];
Off[Plot::plnr];
SetOptions[Limit,Analytic->True];

CMView = {2.7, 1.6, 1.2};

ThreeAxes[u,v]

ThreeAxes[u_,v_] := 
      Graphics3D[{
            {Blue,Line[{{-u,0,0},{u,0,0}}]},
                    Text["x",{u + v,0,0}],
            {Blue,Line[{{0,-u,0},{0,u,0}}]},
                    Text["y",{0, u + v,0}],
            {Blue,Line[{{0,0,0},{0,0,u}}]},
                    Text["z",{0,0,u + v}]}]; 
ThreeAxes[u_] := ThreeAxes[u,u/8];
ThreeAxes::usage = "ThreeAxes[a,b] makes a standard cartesian axis graphics object
	with x, y, and z running from -a to a, and with axis
	labels b units beyond the tips of the axes.  ThreeAxes[a]
	is ThreeAxes[a,a/8].";

Vector Drawers

(* :Title:  VectorDraw.m  *)

(* :Author: Bill Davis, for Calculus&Mathematica *)

(* :Summary:  Construct 2 and 3 dimensional vectors,
     arrows, pointers and arrowheads as graphics 
     objects.
*)

(* :Dates:  The original package was written in 1991.
     After messing it up several times, I rewrote it
     in July, 1994. I made an attempt at readability,
     so some things aren't slick.
*)

(*  :Drawbacks:  Since the vectors are drawn out of 
     context, the shapes of the arrowheads are only 
     correct with AspectRatio set to Automatic.  See 
     the Package, "Graphics`Vectors`".
*)

BeginPackage["Vectors3D`","Graphics`Colors`"];

Perp::usage = "Perp[expr] returns a single 3-d vector which is 
		perpendicular to the vector, 'expr'.";
		
Cross::usage = "Cross[a,b] returns the cross product of a and b.";

Norm::usage = "Norm[expr] returns the Euclidean length of the
		vector, 'expr'.";
		
Arrow::usage = "Arrow[expr] produces a 2 or 3 dimensional 
	vector from the origin to expr. Arrow[expr,Tail->tail] gives a 
	vector from tail to expr.  RGBColor and Thickness may be added as 
	options";
	
Vector::usage = "Vector[a,b] gives a vector from a to b. 
			RGBColor and Thickness may be added as options";

Arrowhead::usage = "Arrowhead[at,toward,options] produces an
		arrowhead to be placed on a curve at the point 'at',
		pointing in the direction of the vector 'toward'. The
		size of the arrowhead is .17*Norm[toward], or can be
		set by the options HeadRatio->, or HeadSize->";

DirectedSegment::usage = "DirectedSegment[from,to,opts] 
		produces a line segment from 'from' to 'to' with a 
		direction arrow on the segment.";

HeadRatio::usage = "HeadRatio->num makes the length of the
		vector's head num*vectorLength.";
		
HeadSize::usage = "HeadRatio->num sets the length of the
		arrowhead to num.";

Tail::usage = "Tail->point puts the tail of the vector at
		the point.";

Aperture::usage = "Aperture is an option for arrowheads 
		which sets the ratio of the diameter of its base to the 
		length of the head to the value of Aperture. The default
		value is .6";
		

Vector::notnum = "The vectors `1` and `2` aren't numeric.";

		
Begin["`Private`"];

SetOptions[ParametricPlot,AspectRatio->Automatic];
SetOptions[Plot,AspectRatio->Automatic];
SetOptions[Graphics,AspectRatio->Automatic];

colorQ[a_] := Head[a] === RGBColor;
grayQ[a_]  := Head[a] === GrayLevel;
thickQ[a_] := Head[a] === Thickness;

Perp[a_?VectorQ] := Which[a[[1]]==0,{1,0,0},
			 a[[2]]==0,{0,1,0},
			 True,{-a[[2]],a[[1]],0}];
			
Cross[a_?VectorQ,b_?VectorQ]:={a[[2]]b[[3]]-a[[3]]b[[2]], 
				a[[3]]b[[1]]-a[[1]]b[[3]],
				a[[1]]b[[2]]-a[[2]]b[[1]]};
				
Norm[a_?VectorQ]:=Sqrt[a.a];

Turn[a_?VectorQ] := Module[{A,B,b = Norm[a],
		dim = Length[a]},
		A = a/b;
		Which[dim==3,B = Perp[A];Transpose[{B,A~Cross~B,A}],
			dim ==2,Transpose[{Reverse[A]{-1,1},A}],
			True,Null]
			];

Base3D = Table[N[{.3 Cos[2 k Pi/7],.3 Sin[2 k Pi/7],-1}],
	{k,8}]; 

UnitHead3D = Flatten[
		Join[
		Table[{{0,0,0},Base3D[[j]],Base3D[[j+1]]},{j,7}],
		Table[{{0,0,-.75},Base3D[[j]],Base3D[[j+1]]},{j,7}]
			],1];

UnitHead2D = {{0,0},{-.3,-1},{0,-.75},{.3,-1}};

VecHead[a_,b_,c_] := Module[{A,len,dim=Length[a]},
		len = Norm[b-a];
		If[len == 0,A = b-a,A = Turn[(b-a)/len]];
		Which[dim==2,Dot[A,#]&/@(Times[{c/.6,1},#]&/@ UnitHead2D),
			dim==3,Dot[A,#]&/@(Times[{c/.6,c/.6,1},#]&/@ UnitHead3D),
			True,Null]];

HeadColorOpts[a_] := Join[Select[a,colorQ],Select[a,grayQ]];

ColorOpts[a_] := Join[Select[a,colorQ],Select[a,grayQ],
	Select[a,thickQ]];

SelectOptions[a_] := Select[a,(Head[#] == Rule)&];

BasicVector[type_?NumberQ,a_,b_,opts___] := 
	Module[{B,aa=N[a],bb=N[b],headColor,len,
			dim=Length[a],aaa,bbb,ccc,AP,HR,HS},
		
		len=Norm[bb-aa];
		aaa = Which[type==1,0,type==2,.25,type==3,1,True,Null];
		bbb = Which[type==1,1,type==2,.75,type==3,0,True,Null];
		ccc = Which[type==1,1,type==2,1,type==3,0,True,Null];
		
		If[!NumberQ[aa.aa+bb.bb],
				Message[Vector::notnum,a,b];Null,

		AP = Aperture/.SelectOptions[{opts}]/.Aperture->.6;
		
		B = VecHead[aa,bb,AP];
		
		HR = HeadRatio/.SelectOptions[{opts}]/.{HeadRatio->.17};
		
		HS = With[{B=HeadSize/.SelectOptions[{opts}]/.{HeadSize->"Nope"}},
			If[NumberQ[B],B,len HR]];
			
				headColor = If[Length[HeadColorOpts[{opts}]]==0,
				Black,First[HeadColorOpts[{opts}]]];
				
		Which[dim==2,
			Graphics[{Append[ColorOpts[{opts}],Line[{aa,ccc bb + (1-ccc)aa}]],
				{headColor,Polygon[Plus[(aaa aa + bbb bb),#]&/@(HS B)]}}],
			dim==3,
			Graphics3D[{Append[ColorOpts[{opts}],
				Line[{aa,ccc bb + (1-ccc)aa}]],
				{SurfaceColor[headColor],
				Polygon[Plus[(aaa aa+bbb bb),#]&/@(HS B)]}}],
			True,Null]]
			];

Vector[from_?VectorQ,to_?VectorQ,opts___]:=
	BasicVector[1,from,to,opts];
		
Vector[to_?VectorQ,opts___] := With[{dim=Length[to]},
				BasicVector[1,Table[0,{dim}],to,opts]];

Arrow[vec_,start_Rule,opts___]:= With[{a=Tail/.{start}},
	BasicVector[1,a,a+vec,opts]];

Arrow[vec_,opts___]:= With[{a=Table[0,{Length[vec]}]},
	BasicVector[1,a,a+vec,opts]];
		
Arrowhead[at_,toward_,opts___] := 
		BasicVector[3,at,toward+at,opts];

DirectedSegment[from_,to_,opts___] :=
		BasicVector[2,from,to,opts];

(*Protect[Perp,Cross,Turn,Vector,Arrow,
		Arrowhead,DirectedSegment];*)

End[];


EndPackage[];
Null

Spherical Setup

Clear[polar]
polar[{x_,y_,z_}]:=
{Sqrt[x^2+y^2+z^2],ArcTan[y/x],ArcCos[z/Sqrt[x^2+y^2+z^2]]};
Clear[X]
length[X_]:=Sqrt[X.X];
rr=3;
R=5;
scale=0.8;
red=RGBColor[1,0,0];
blue=RGBColor[0,0,1];
color1=RGBColor[0.8,0.2,0.8];
color2=RGBColor[0.2,0.8,0.2];
black=RGBColor[0,0,0];
Clear[axes]
axes:=Graphics3D[{
Line[{X,{1.5rr,0,0}}],
Line[{X,{0,1.5rr,0}}],
Line[{X,{0,0,2rr}}]}
];
Clear[xyplane]
xyplane:=Graphics3D[Polygon[
{
{-2rr,-2rr,0},
{-2rr, 2rr,0},
{ 2rr, 2rr,0},
{ 2rr,-2rr,0}
}]];
X={0,0,0};
origin=Graphics3D[{black,Point[X]}];
Z={2,3,5};
Clear[point]
point:=Graphics3D[{red,PointSize[0.03],Point[scale Z]}];
Z0={0,0,length[0.8 Z]};
Clear[zpoint]
zpoint=Graphics3D[{black,Point[Z0]}];
XY=scale Z {1,1,0};
Clear[xypoint]
xypoint:=Graphics3D[{black,Point[XY]}];
X0={length[scale Z {1,1,0}],0,0};
xpoint=Graphics3D[{black,Point[X0]}];
Y0={0,length[scale Z {1,1,0}],0};
ypoint=Graphics3D[{black,Point[Y0]}];
Clear[ray]
ray:=Graphics3D[{blue,Line[{X,scale Z}]}];
Clear[ray1]
ray1:=Graphics3D[{color1,Line[{scale Z,Z}]}];
Clear[xyray]
xyray:=Graphics3D[{red,Line[{X, Z {1,1,0}}]}];
rays:={ray,xyray};
xyaux=
length[0.8 Z](0.8 Z {1,1,0})/length[0.8 Z {1,1,0}];
Clear[zarc]
zarc=Graphics3D[{blue,Line[
Table[Cos[t]{0,0,length[0.8 Z]} + Sin[t]xyaux,
{t,0,polar[0.8 Z][[3]],.1}]
]}];
Clear[zarc1]
zarc1=Graphics3D[{color1,Line[
Table[Cos[t]{0,0,length[0.8 Z]} + Sin[t]xyaux,
{t,polar[0.8 Z][[3]],1,.1}]
]}];
Clear[zarc2]
zarc2=Graphics3D[{color1,Line[
Table[Cos[t]{0,0,length[0.8 Z]} + Sin[t]xyaux,
{t,-.8,0,.1}]
]}];
Clear[xyarc]
xyarc=Graphics3D[{blue,Line[
Table[Cos[t] X0 + Sin[t] Y0,
{t,0,polar[XY][[2]],.1}]
]}];
Clear[xyarc1]
xyarc1=Graphics3D[{color1,Line[
Table[Cos[t] X0 + Sin[t] Y0,
{t,-.5,0,.1}]
]}];
Clear[xyarc2]
xyarc2=Graphics3D[{color1,Line[
Table[Cos[t] X0 + Sin[t] Y0,
{t,polar[XY][[2]],polar[XY][[2]]+0.3,.1}]
]}];
Clear[stick]
stick=Graphics3D[{red,Line[{scale Z,XY}]}];

xaxislabel=Text["x",{0.363,0.26}];
yaxislabel = Text["y",{0.73, 0.30}];
zaxislabel = Text["z",{0.50, 0.67}];

stickplot =
Show[xyplane,axes,ray,point,Boxed->False,
ViewPoint->{2.747, 1.594, 1.168},
Epilog->{xaxislabel,yaxislabel,zaxislabel},
DisplayFunction->Identity];

rho=Text["r",{0.53, 0.45}];
rlabel = Show[xyplane,axes,ray,point,
Boxed->False,ViewPoint->{2.747, 1.594, 1.168},
Epilog->{rho,xaxislabel,yaxislabel,zaxislabel},
DisplayFunction->Identity];

phi=Text["s",{0.55, 0.57}];
slabel =
Show[xyplane,zpoint,axes,ray,point,zarc,zarc1,zarc2,Boxed->False,ViewPoint->{2.747, 1.594, 1.168},
Epilog->{phi,xaxislabel,yaxislabel,zaxislabel},DisplayFunction->Identity];

theta=Text["t",{0.5, 0.3}];

tlabel=Show[xyplane,axes,xypoint,xpoint,ray,stick,point,xyarc,xyarc1,xyarc2,Boxed->False,ViewPoint->{2.747, 1.594, 1.168},
Epilog->{theta,xaxislabel,yaxislabel,zaxislabel},
DisplayFunction->Identity];

all =
Show[xyplane,axes,ray,stick,point,zpoint,xpoint,xypoint,xyarc,xyarc1,xyarc2,zarc,zarc1,zarc2,Boxed->False,ViewPoint->{2.747, 1.594, 1.168},
Epilog->{theta,phi,rho,xaxislabel,yaxislabel,zaxislabel},DisplayFunction->Identity];

Crisscross

Clear[x]
crisscross = Plot[{Cos[x],Sin[x]},{x,Pi/8,3 Pi/8},
    PlotStyle->{{RGBColor[1,0,0],Thickness[0.02]}},
    Axes->None,AspectRatio->1/3,
    DisplayFunction->Identity];

Computer Assignment #5
Parameterizations

Special thanks to Calculus&Mathematica (Addison-Wesley, 1994) for their support of these assignments.  Each is very much in the style of C&M, and some problems and commands are adaptations of C&M problems and commands.  In particular, the initialization cells were borrowed from Calculus&Mathematica with permission from Jerry Uhl.

Why should I have to do this computer assignment anyway?

This assignment is meant to provide you with a short introduction to the world of parameterizations. When you're done with this, you should understand what a parametric plot is and why adding a parameter can be useful when describing curves.  It is important to have this conceptual understanding BEFORE you start computing by hand.

Introduction

Mathematica's "Plot" command is very useful when it comes to plotting functions in the xy-plane.  By simply executing the following cell, you get a nice graph of a fairly nasty function.

Plot[x Sin[x^2],{x,-2Pi,4Pi}];

Unfortunately, not all curves define y as a function of x, and we cannot always use the Plot command so easily to get the graph wanted.  
	The matter of describing 2-D curves in 3-D space presents further complications.  A simple line in 3-D space cannot be described simply by expressing z in terms of x and y:  z = f(x,y).  (Recall what type of graph we get for a function of the form z = f(x,y)!)
	The most common way to describe a 2-D curve in 3-D space is with the use of a parameter t.  We define a particular x-, y-, and z-coordinate on the curve in terms of the parameter t, which we usually think of as time.  We think of the parameterized x-, y-, and z-coordinates as describing the location of some particle or object at time t.  By allowing t to vary, we trace the full path of the particle for all time.

Problem 1  -- Parameterizing Portions of Lines

Part A -- Your basic line in the xy-plane.

For simplicity, we will work in 2-dimensional space.  Everything we discuss here can be generalized to 3-space by adding a third component to our vectors.

Let's first parameterize a line passing through the two points P(1,2) and Q(3,3).  We will be working with vectors, so we'll define two position vectors:

positionP = {1,2};
positionQ = {3,3};
Show[Arrow[positionP,Tail->{0,0},Red],
		Arrow[positionQ,Tail->{0,0},Red],
		Axes->True];

These position vectors point from the origin to the points P and Q, respectively.

a.  Find the components of the displacement vector, vectorPQ, which takes us from the point P to the point Q.  Then, execute the cells below to plot positionP, positionQ, and vectorPQ.

vectorPQ = <<VECTOR HERE>>

Be sure you execute the cell above.  Then, use the following cell to plot vectorPQ together with positionP and positionQ.

positionP = {1,2};
positionQ = {3,3};
Show[Arrow[positionP,Tail->{0,0},Red],
		Arrow[positionQ,Tail->{0,0},Red],
		Arrow[vectorPQ,Tail->positionP,Blue],
		Axes->True];

b.  Give the coordinates of the point where we end up if we travel from the tail to the tip of vector positionP and then travel from the tail to the tip of vector vectorPQ.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

c.  Give the coordinates of the point where we end up if we travel from the tail to the tip of vector positionP and then travel halfway from the tail to the tip of vector vectorPQ.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

d.  Give the coordinates of the point where we end up if we travel from the tail to the tip of vector positionP and then travel three times from the tail to the tip of vector vectorPQ (in the direction of vectorPQ).

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

All three of the points you found in Parts b through d lie (should lie!) on a line parallel to the displacement vector vectorPQ.  By generalizing your answers to the previous three questions, we can write down formulas which describe ALL of the points on this particular line:

e.  Give formulas in terms of t for the coordinates of the point where we end up if we travel from the tail to the tip of vector positionP and then travel some proportion t from the tail to the tip of vector vectorPQ (in the direction of vectorPQ).

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Part B -- Variations on the line theme.

Here is the definition of a certain line:

{x1[t_],y1[t_]} = {2 + 3 t,1 - 2 t};

Here is a plot of the portion of the line defined for parameter values t between -3 and 3:

ParametricPlot[{x1[t],y1[t]},{t,-3,3},
		AxesLabel->{"x","y"}];

f.  Modify the above command so that only the portion of the line between the positive y-axis and the positive x-axis is traced.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Sometimes it's helpful to see how a path is traced by a moving particle.  To see how the above path is traced, animate the following graphics:

lineplot = ParametricPlot[{x1[t],y1[t]},{t,-3,3},
		AxesLabel->{"x","y"},
		DisplayFunction->Identity];
Needs["Graphics`Animation`"];
Animate[
	Show[lineplot,
		Graphics[{PointSize[.05],Point[{x1[s],y1[s]}]}]],
	{s,-3,3,1}];

Here is another parameterization of a line:

{x2[t_],y2[t_]} = {2 - 3 t,1 + 2 t};

Check out the line segment for t between -3 and 3:

ParametricPlot[{x2[t],y2[t]},{t,-3,3},
		AxesLabel->{"x","y"}];

Hmmm...the plot looks the same as the one above.

g.  What is the difference between the motion of a particle traveling down this line segment, parameterized by {x2[t],y2[t]}, and the motion of a particle traveling down the first line segment, parameterized by {x1[t],y1[t]}?  (Hint:  Try the following animation.)

{x2[t_],y2[t_]} = {2 - 3 t,1 + 2 t};
lineplot = ParametricPlot[{x2[t],y2[t]},{t,-3,3},
		AxesLabel->{"x","y"},
		DisplayFunction->Identity];
Needs["Graphics`Animation`"];
Animate[
	Show[lineplot,
		Graphics[{PointSize[.05],Point[{x2[s],y2[s]}]}]],
	{s,-3,3,1}];

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Here is yet another line:

{x3[t_],y3[t_]} = {2 + 3 t^3,1 - 2 t^3};

And a portion of it:

ParametricPlot[{x3[t],y3[t]},{t,-1.4425,1.4425},
		AxesLabel->{"x","y"}];

h.  How does the motion of a particle down this line segment, parameterized by {x3[t],y3[t]}, differ from the motion down the FIRST line segment, parameterized by {x1[t],y1[t]}?

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

i.  Describe the motion of a particle parameterized by
{x4[t_],y4[t_]} = {2 + 3 t^2,1 - 2 t^2}.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Problem 2  -- Parameterizing Circles

A handy way to to plot the circle x^2 + y^2 = 1 is to write 
             x[t] = Cos[t]     and    y[t] = Sin[t]
and then to plot the points
             {x[t], y[t]} = {Cos[t], Sin[t]}
as t advances from 0 to 2Pi.

{x1[t_],y1[t_]} = {Cos[t], Sin[t]};
circleplot = 
     ParametricPlot[{x1[t],y1[t]},{t,0,2 Pi},
        AspectRatio->Automatic,
        PlotRange->{{-2,2},{-2,2}}];

Here is an animation:

Needs["Graphics`Animation`"];
Animate[
	Show[circleplot,
		Graphics[{PointSize[.05],Point[{x1[s],y1[s]}]}]],
	{s,0,2Pi,Pi/4}];

a.  Using a parametric plot, plot the right half of the unit circle.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

b.  Using a parametric plot, plot a full circle of radius 1.5.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Here is a different way to parameterize the circle:

{x2[t_],y2[t_]} = {Cos[t/3], Sin[t/3]};

c.  How does the parameterization {x2[t],y2[t]} compare with the parameterization {x1[t],y1[t]} above?  State an interval of t-values which defines exactly one full tracing of the circle under the parameterization {x2[t],y2[t]}.

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>

Let's see what happens when we swap sine and cosine:

{x3[t_],y3[t_]} = {Sin[t],Cos[t]};

d.  How does the parameterization {x3[t],y3[t]} compare with the parameterization {x1[t],y1[t]} above?

<<ANSWER QUESTION IN YOUR COPY OF THE FILE COMP5ANS.MA>>