Cartesian Coordinate Position Vectors
in
2 and 3 Dimensions

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Special Mathematica Functions used in this NoteBook

We told you not to look.  This horrible stuff sets various defaults and defines some functions needed to draw the geometric side of the lexicon.  Ignore the details here and go on to the lesson.

Off[General::spell];
Off[General::spell1];
Off[ParametricPlot3D::ppcom]
Needs["Graphics`Colors`"]

SetOptions[Graphics,Axes->False,AxesOrigin->{0,0},AspectRatio->Automatic];
SetOptions[Graphics3D,ViewPoint->{5,2,1},Boxed->False,AspectRatio->Automatic];
SetOptions[ParametricPlot3D,ViewPoint->{5,2,1},AspectRatio->Automatic];
SetOptions[Plot3D,ViewPoint->{5,2,1},AspectRatio->Automatic];
SetOptions[ParametricPlot,AspectRatio->Automatic];
SetOptions[Plot,AspectRatio->Automatic];

colorQ[a_]:=(Head[a]===RGBColor);
grayQ[a_]:=(Head[a]===GrayLevel);
thickQ[a_]:=(Head[a]===Thickness);
absthickQ[a_]:=(Head[a]===AbsoluteThickness);
notruleQ[u_] := !(Head[u]===Rule);
ruleQ[u_] := (Head[u]===Rule);

Norm::usage = "Norm[expr] returns the Euclidean length of the
		vector, 'expr'.";

Norm[a_?VectorQ] := Sqrt[a.a];

Angle[a_?VectorQ,b_?VectorQ] := ArcCos[(a.b)/(Norm[a] Norm[b])]

Proj[a_?VectorQ,b_?VectorQ] := ((a.b)/(b.b))b

tol = .5*10^-6;

OrthUp[a_?VectorQ] :=
	Module[{b,c,d,f},
		d = N[a/Norm[a]];
		If[Chop[d[[3]]^2 - 1,tol] == 0, b={1,0,0} ,
		b = {0,0,1} - d[[3]] d; b = b/Norm[b];];
	Return[b]];
	
OrthSet[a_?VectorQ] :=
	Module[{b,c,d},
		d = N[a/Norm[a]];
		If[Chop[d[[1]],tol]==0,b={1,0,0},
			 If[Chop[d[[2]],tol]==0,b={0,1,0},
			  b={-d[[2]],d[[1]],0}]];
			b=b/Norm[b];c = Cross[d,b];
	Return[{b,c/Norm[c],d}]];

				
Rotate[a_?VectorQ,theta_] :=
	Module[{u,v,r},
		u = OrthSet[a];
		v = Transpose[u];
		r = N[{{Cos[theta],-Sin[theta],0},{Sin[theta],Cos[theta],0},{0,0,1}}];
	Return[v.r.u]];

Vector2D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics[Point[{0,0}]]];
	,						
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (.075 Norm[ntip-ntail]/Norm[ntip-ntail]) (ntip-ntail) ;
	up = 0.15 {-Punit[[2]],Punit[[1]]};
	arrow = Line[{ntail,ntip,ntip-Punit+up,ntip,ntip-Punit-up}];
	]];
Return[Graphics[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

Vector3D[tail_,tip_,opts___]:=
	Module[{ntail,ntip,sopts,Punit,up,u2,u3,u4,rotmat,arrow},
	ntail = N[tail];
	ntip = N[tip];
	
	sopts = Join[Select[{opts},colorQ],Select[{opts},
				thickQ],Select[{opts},absthickQ],Select[{opts},grayQ]];

If[Chop[ntail.ntail+ntip.ntip,tol] == 0,
			(*too small to plot or not number*)
			Return[Graphics3D[Point[{0,0,0}]]];					
	,		
If[Chop[(ntip-ntail).(ntip-ntail),tol] == 0,
		Return[Graphics3D[{Join[sopts,{Line[{ntail,ntip}]}]}]];
	,
	Punit = (ntip-ntail);
	rotmat = Rotate[Punit,N[Pi/2]];
	up = OrthUp[Punit];
	Punit = .075 Punit;
	up = .15 Norm[Punit] up;
	u2 = rotmat.up;
	u3 = rotmat.u2;
	u4 = rotmat.u3;
	arrow = Line[{ntail,ntip,
				ntip - Punit + up,ntip,
				ntip - Punit + u2,ntip,
				ntip - Punit + u3,ntip,
				ntip - Punit + u4}];
	]];
Return[Graphics3D[{Join[{AbsoluteThickness[2]},Join[sopts,{arrow}]]}]];
];

aRCtAN[y_,x_] := Module[{v},
	If[ Chop[N[x],tol] == 0 ,If[ N[y] < 0, v = -N[Pi/2], v = N[Pi/2]],
		v = N[ArcTan[y/x]];
		If[ x < 0 && y < 0, v = N[Pi -  v],v]];
	Return[v]];

Arc2D[X_,Y_,opts___] := Graphics[{opts,
		Disk[{0,0},1,{Min[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]
						,
					Max[
							aRCtAN[
						N[X[[2]]],N[X[[1]]]
								]
							,
							aRCtAN[
							N[Y[[2]]],N[Y[[1]]]
								]
						]}
				]}
				];
Arc3D[X_,Y_] := 
	Module[{t,U,V},
		U[V_]:= N[(1/Sqrt[V.V]) V];
		Return[Graphics3D[
		Polygon[Append[Table[U[t X + (1-t) Y],{t,0,1,0.1}],{0,0,0}]]
				]
		]
	];

(*Zero Arrow causes trouble. Put in Vector?*)

Vector[tail_,tip_,opts___]:=
	If[Length[N[tail]]==2,Return[Vector2D[tail,tip,opts]],
		Return[Vector3D[tail,tip,opts]]];
		
Arrow[vec_,opts___]:= 
	Module[{a,b},
				If[Length[N[vec]]==2,
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0}};
				Return[Vector2D[a,a+vec,opts]],
				a=ToExpression["Tail"]/.Select[{opts},ruleQ]/.
					{ToExpression["Tail"]->{0,0,0}};
				Return[Vector3D[a,a+vec,opts]]]
				];

Frame2D[delta_] := 
      Graphics[{
            {Green,Line[{{-delta/4,0},{delta,0}}]},
                    Text["x",{1.01 delta,0}],
            {Green,Line[{{0,-delta/4},{0,delta}}]},
                    Text["y",{0, 1.01 delta}]}];

Frame3D[delta_] := 
      Graphics3D[{
            {Green,Line[{{-delta/4,0,0},{delta,0,0}}]},
                    Text["x",{1.01 delta,0,0}],
            {Green,Line[{{0,-delta/4,0},{0,delta,0}}]},
                    Text["y",{0, 1.01 delta,0}],
            {Green,Line[{{0,0,-delta/4},{0,0,delta}}]},
                    Text["z",{0,0,1.01 delta}]}];

View2D[stuff_] := Show[stuff,Frame2D[1]];
View3D[stuff_] := Show[stuff,Frame3D[1]];

Notebook Overview

This NoteBook shows how coordinates are measured on a position vector.

A "position vector" in 2 or 3 dimensions is an arrow that points from a reference origin to another point in space.  More generally, you could say, "A vector is a quantity with magnitude and direction."  We could specify vectors by measuring "magnitudes" and "directions", but it is usually easier to begin with cartesian coordinates.

Vectors can be measured by perpendicular cartesian coordinates, 2 coordinates in 2 dimensions, 3 coordinates in 3D.  These coordinates can then be used to calculate geometric quantities such as length and direction.  These calculations are called "analytical geometry."  The calculations link the algebra of the coordinates to the geometry of the vectors.

References to the Text

Section 15.1

This text section reviews cartesian coordinates in 1, 2 and 3 dimensions.

Section 15.2

Cartesian coordinates can be viewed as vectors in 1, 2 and 3 dimensions.

Coordinates for Vectors

In Mathematica a vector is a list of numbers, for example,

X = {2, -3}     or     Y = {4,-3, 8}

<Enter> the computations below to see examples.

2-D

Measuring a Vector

To plot the 2-D vector  X = {4,3}, we first measure  4  units out along the positive x-axis and then measure  3  units up parallel to the y-axis.  <Enter> the next computation to see the result.

X = {4, 3}; View2D[Arrow[X, Blue]]; View2D[{Arrow[X, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {X[[1]], 0}, 
                X}]}], Graphics[
          Text[X[[1
              ]], { .6 
                X[[1]],  .1 
                X[[2]]}]], 
        Graphics[
          Text[X[[2
              ]], { .9 
                X[[1]],  .5 
                X[[2]]}]]}];

Practice Exercise

1)  Copy and paste the computation above and modify it to draw the vector
X = {-3,-2}.
2)  Copy and paste the computation above and modify it to draw the vector  
X = {-2,6}.
3)  Copy and paste the computation above and modify it to draw the vector  
X = {4.1,2.7}.

Several 2D Vectors

X = {4, 3}; Y = {2, -3}; View2D[{Arrow[Y, Blue], Arrow[X, Red]}];

Practice Exercise

Copy the computation above and modify it to draw the all the vectors on one plot:

X = {-3,-2} (Blue)
		Y = {-2,6} (Red)
		Z = {5,-3} (Brown) 
		W = {-3.5,1} (Yellow)

3-D

Measuring a 3D Vector

To plot the 3-D vector  X = {1,-2,3}, we first measure  1  units out along the positive x-axis, then measure  2  units parallel to the y-axis, but in the negative direction, and finally, measure up 3 units in the z direction.

<Enter> the next computation to see the result.

X = {1, -2, 3}; View3D[Arrow[X, Blue]]; View3D[{Arrow[X, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {X[[1]], 0, 
                  0}, {X[[1]], 
                  X[[2]], 0}, X}]}], 
        Graphics3D[
          Text[X[[1
              ]], { .5 
                X[[1]],  .1 
                X[[2]], 
              0 X[[3]]}]], 
        Graphics3D[
          Text[X[[2
              ]], { .8 
                X[[1]],  .5 
                X[[2]], 
              0 X[[3]]}]], 
        Graphics3D[
          Text[X[[3
              ]], { .8 
                X[[1]],  .8 
                X[[2]],  .5 
                X[[3]]}]]}];

Practice Exercise

1)  Copy and paste the computation above and modify it to draw  X = {-3,4,2}.
2)  Copy and paste the computation above and modify it to draw  X = {-2,-4,-1}.
3)  Copy and paste the computation above and modify it to draw  X = {3.25,2.1,-6.5}.

Several 3D Vectors

X = {1, 2, 3}; Y = {2, -4, -1}; View3D[{Arrow[X, Red], Arrow[Y, Blue]}];

Practice Exercise

Copy and paste the computation above and modify it to draw the vectors:
		X = {-3,4,2} (Red)
		Y =  {-2,-4,-1} (Blue)
		W = {2,1,5} (Brown)

Lengths or Norms of Vectors

In Mathematica a vector is a list of numbers, for example,

X = {2, -3}     or     Y = {4,-3, 8}

The length of a vector is given by the sum of the squares of its components, for example,

|X| = (Sqrt[(2^2) + (((-3))^2)])  =  (Sqrt[13])
or
|Y| =  (Sqrt[(2^2) + (((-3))^2) +  (8^2)])  =  (Sqrt[89])

Another name for the geometric length is "norm."  We use this name for our geometric length function, because "Length[ X ]" is used by Mathematica  for the number of elements in the list.  Norm[.]  is defined in the Initialization Cell at the begining of this NoteBook in a compact form.  The definition is equivalent to:

Norm[ X_ ] :=  \(TraditionalForm
      \`\@\(∑\+\(j = 1\)\%\(Length[X]\)X[\([j]\)]\^2\)\)

<Enter> the computations below to see examples.

Clear[x, y, z, W]; W = {x, y, z}Norm[W]X = {2, -3}Norm[X]Y = {4, -3, 8}Norm[Y]

2-D

Measuring a 2-D Vector Norm

Plot the 2-D vector  X = {4,3} and show its length.

<Enter> the next computation to see the result.

X = {4, 3}; View2D[{Arrow[X, Blue], 
        Graphics[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0}, {X[[1]], 0}, 
                X}]}], Graphics[
          Text[X[[1
              ]], { .6 
                X[[1]],  .1 
                X[[2]]}]], 
        Graphics[
          Text[X[[2
              ]], { .9 
                X[[1]],  .5 
                X[[2]]}]], 
        Graphics[Text[Norm[X] " =|X|",  .5 X]]}];

Practice Exercise

1)  Copy and paste the computation above to show the length of the vector  X = {-3,-2}.
2)  Copy and paste the computation above to show the length of the vector  X = {-2,6}.
3)  Copy and paste the computation above to show the length of the vector  X = {4.1,2.7}.

3-D

Measuring a 3-D Vector Norm

To plot the 2-D vector  X = {4,3}, we first measure  4  units out along the positive x-axis and then measure  3  units up parallel to the y-axis.

<Enter> the next computation to see the result.

X = {-4, 3, 8}; View3D[{Arrow[X, Blue], 
        Graphics3D[{Blue, AbsoluteThickness[2], AbsoluteDashing[{5, 5}], 
            Line[{{0, 0, 0}, {X[[1]], 0, 
                  0}, {X[[1]], 
                  X[[2]], 0}, X}]}], 
        Graphics3D[
          Text[X[[1
              ]], { .5 
                X[[1]],  .1 
                X[[2]], 
              0 X[[3]]}]], 
        Graphics3D[
          Text[X[[2
              ]], { .8 
                X[[1]],  .5 
                X[[2]], 
              0 X[[3]]}]], 
        Graphics3D[
          Text[X[[3
              ]], { .8 
                X[[1]], 
              1.2 X[[2]],  .3 
                X[[3]]}]], 
        Graphics3D[Text[Norm[X] " =|X|",  .5 X]]}];

Practice Exercise (See Text Exercise 15.2.2)

1)  Copy and paste the computation above to show the norm of  X = {-3,4,2}.
2)  Copy and paste the computation above to show the norm of  X = {-2,-4,-1}.
3)  Copy and paste the computation above to show the norm of  X = {3.25,2.1,-6.5}.

Exercises

Exercise 15.2.1

Use the program above to draw the 2-D vectors and compute their lengths:

A(3,4)
			B(-3,-2)
			C(-2,6)
			D(5,-3)
			E(4.1,2.7)
			F(-3.5,1)

Use the program above to draw the 3-D vectors and compute their lengths:

A(2,1,5)
			B(-3,4,2)
			C(-2,-4,-1)
			D(3,-2,-5)
			E(3.25,2.1,-6.5)
			F(8.3,0,7)

Exercise 15.2.2

Draw the following 2-D vectors and compute their geometric lengths or norms:

{4,2}
	{-5,-2}
	{-3,7}
	{6,-2}

Draw the following 3-D vectors and compute their geometric lengths or norms:

{4,6,5}
	{-4,7,-2}
	{6,8,-10}
	{-6,-9,-1}

Exercise 15.2.3

Copy the following commands in an input cell and add more points on the line in the commands

Clear[X];
X = {1,3,2};
View3D[{
	Arrow[X,Blue],
	Graphics3D[{Blue,AbsoluteThickness[2],AbsoluteDashing[{5,5}],
			Line[{{0,0,0},{X[[1]],0,0},{X[[1]],X[[2]],0},X}]}]
			}]
			
to make a dashed 3D rectangular box with the vector  X  along its diagonal.  Test your program on the vector X(1,3,2).