\(\(\( (*\ \(:\)\(Title : Arrow\ 3  D\)*) \)\( (*\ \(:\)\(Context : 
          Graphics`Arrow3D`\)*) \)\( (*\ \(:\)\(Author : 
          John\ M . Novak\)*) \)\( (*\ \(:\)\(Summary : 
          crude\ 3  D\ arrow\ primitive\)*) \)\( (*\ \(\(:\)\(Copyright : 
          Copyright\ 1996\ Wolfram\ Research\)\), \(\(Inc\)\(.\)\)*) \)\( (*\ \(:\)\(Package\ \(Version : 
            1.0\)\)*) \)\( (*\ \(:\)\(Mathematica\ \(Version : 
            3.0\)\)*) \)\( (*\ \(:\)\(History : 
          V1 \( .0--\)\ March\ 1996\ by\ John\ M . 
              Novak\)*) \)\( (*\ \(\(:\)\(Keywords : arrow\)\), 
      Graphics3D*) \)\( (*\ \(\(:\)\(Sources : 
          Tom\ Wickham - 
            Jones\)\), "Mathematica Graphics"*) \)\( (*\ \(\(:\)\(Discussion : 
          This\ is\ a\ package\ to\ add\ crude\ 3  D\ arrows\ by\ using\ 3  
            D\ graphics\ primitives . 
              The\ main\ problem\ with\ this\ approach\ is\ that\ arrows\ don' t\ have\ an\ optimal\ appearance\)\), 
      and\ distinction\ between\ \((e . g . )\)\ arrows\ point\ toward\ vs . 
          away\ from\ the\ user\ is\ difficult\ to\ make . 
          On\ the\ other\ hand, it\ is\ readily\ implementable, 
      which\ is\ far\ superior\ to\ any\ other\ approach\ available\ at\ this\ time . \((The\ PostScript\ used\ in\ 2  D\ arrows\ won' 
              t\ layer\ correctly\ in\ 3  D, nor\ would\ 2  D\ primitives; 
            placing\ 3  
              D\ planar\ primitives\ with\ the\ correct\ orientation\ has\ problems\ with\ perspective\ transforms\ as\ well\ as\ design\ problems\ with\ things\ like\ arrows\ with\ a\ small\ angle\ w . r . t . 
                the\ \(\(user\)\(.\)\))\)\ Because\ of\ the\ essentially\ different\ approach\ from\ 2  D\ arrows, 
      the\ package\ is\ being\ made\ independent\ of\ the\ 2  
        D\ package\ for\ the\ time\ \(\(being\)\(.\)\)*) \)\(BeginPackage["Graphics`Arrow3D`"]


    \(Arrow3D::usage = "Arrow3D[start, end] is a 3D graphics primitive representing an arrow in
space. The start point and the end point are given as {x, y, z}
triplets.
Options controlling the length and width of the arrowhead are
available.";\)


    Begin["`Private`"]

 (*The\ following\ routine\ is\ based\ on\ OrthogonalVectors\ from\ Tom\ Wickham - 
        Jones'\ Mathematica\ Graphics\ \(\(book\)\(.\)\)*) 


    anOrthogonalVector[norm : {_, _, _}] := 
      Block[{pos, a, b, v1}, 
        pos = If[VectorQ[norm, NumberQ], Abs[N[norm]], 
            norm]; 
pos = 
          Sort[Transpose[{pos, Range[3]}]]; 
{pos, a, b} = 
          Map[Last, pos]; 
v1 = 
          ReplacePart[{0, 0, 0}, \(-Part[norm, a]\), 
            b]; 
ReplacePart[v1, Part[norm, b], 
          a]]


    normalize[vec_] := 
      vec/Sqrt[vec . 
            vec]

 (*The\ following\ routine' rotationmatrix'\ was\ borrowed\ from\ the\ standard\ package\ \(\(Graphics`SurfaceOfRevolution`\)\(.\)\)*) 


    rotationmatrix[axis_, theta_] := 
      Module[{n1, n2, n3}, {n1, n2, n3} = 
          normalize[axis] // 
            N; 
{{n1^2 + \((1 - n1^2)\)\ Cos[theta], 
              n1\ n2\ \((1 - Cos[theta])\) + n3\ Sin[theta], 
              n1\ n3\ \((1 - Cos[theta])\) - 
                n2\ Sin[theta]}, {n1\ n2\ \((1 - Cos[theta])\) - 
                n3\ Sin[theta], n2^2 + \((1 - n2^2)\)\ Cos[theta], 
              n2\ n3\ \((1 - Cos[theta])\) + 
                n1\ Sin[theta]}, {n1\ n3\ \((1 - Cos[theta])\) + 
                n2\ Sin[theta], 
              n2\ n3\ \((1 - Cos[theta])\) - n1\ Sin[theta], 
              n3^2 + \((1 - n3^2)\)\ Cos[theta]}} // N]


    Arrow3D[base : {_, _, _}, tip : {_, _, _}, polys_:  10, 
        len_:  0.8] := {Line[{base, tip}], 
        mycone[tip - base, base, tip, polys, len]}


    Arrow3D[base : {_, _, _}, tip : {_, _, _}, ___] := 
      Point[base] /; base == tip


    mycone[vec_, base_, tip_, polys_, len_] := 
      Block[{norm = anOrthogonalVector[vec], theta}, 
        Map[Polygon[Append[#, tip]] &, 
          Partition[
            Table[base + 
                  len\ vec + \((1 - len)\)/2\ norm . 
                      rotationmatrix[vec, theta], {theta, 0, 2\ Pi, 
                  2\ Pi/polys}] // N, 2, 1]]]


    End[]


    EndPackage[]



    \("Graphics`Arrow3D`";\)

    \("Arrow3D[start, end] is a 3D graphics primitive representing an arrow in space. The start point and the end point are given as {x, y, z} triplets. Options controlling the length and width of the arrowhead are available.";\)

    \("Graphics`Arrow3D`Private`";\)

    \("Graphics`Arrow3D`Private`";\)

    \)\)\)

\(MATH\ 257\ Calculus\ III					Week\ of\ May\ 5, \ 2003\)
Lab 6 :  Wectors
Name 1
Name 2
Section:

Before you begin, execute the following command.  YOU WILL BE ASKED if you want to execute any initialization cells.  CLICK YES.

<< Graphics`Arrow`;

I.  Laboratory Objectives
	Use Mathematica to explore
		3D graphics and Vectors.  Yeah!

II.  Formatting and Syntax Information

Show[Graphics[ ] 	These make Mathematica render whatever
	Show[Graphics3D[ ]]		2D or 3D graphics you've conconcted (which
					you have to put in the brackets [  ]).
	Arrow[{x1,y1}, {x2,y2}]	Draws an Arrow from {x1,y1} to {x2,y2}.
	   					You need to do <<Graphics`Arrow` first
	   					to load the Arrow package.
	Arrow3D[ pt1, pt2 ]	Same thing as Arrow, but for 3D vectors.  Here
					pt1 must have three coordinates, {x1,y1,z1}.  Ditto
					for pt2.  This is NOT a standard Mathematica command.
					But the secret initialization cells in this lab will define it...
					
	v.u				The Dot Product of two vectors v and u.  
					Don't know what this is?  You'll see below...

Vectors (or Wectors) in 2D

In class (and in the book), we denote a vector like this:  v = <1, 3>.  In Mathematica, we express vectors as LISTS:

v = {1, 3}

If we wanted to draw this vector centered at the origin, we can use the "Arrow" command.  (If this does NOT work, you didn't do the <<Graphics`Arrow` command above.  Go do it!)

Show[
      Graphics[{Thickness[ .01], Arrow[{0, 0}, v]}]]

OK.  That doesn't picture doesn't say much.  Try it again, this time adding axes, and making them scaled the same:

Show[Graphics[{Thickness[ .01], Arrow[{0, 0}, v]}],  
      Axes -> True,  AspectRatio -> Automatic]

Therefore, the Arrow[{x1, y1}, {x2, y2}] command will draw an arrow starting at (x1,y1) and ending at (x2,y2).

Question 1: Make a picture of 5 vectors that form a nice pentagon.  (It doesn't have to be perfectly regular, but try your best.)

Vectors in 3D

To make vectors in 3D space, we need to use the Arrow3D[ ] command. This is NOT a standard Mathematica command; it was loaded when you clicked "yes" to the initialization cells.  Clever, eh?

Let's define a 3D vector and draw it centered at the origin.

a = {1, 3, 3}

    Show[Graphics3D[{Thickness[ .01], Arrow3D[{0, 0, 0}, a]}],  
      Axes -> True,  AspectRatio -> Automatic,  
      PlotRange -> {{0, 3}, {0, 3}, {0, 3}}]

Cute, eh?

Question 2a: Make a picture of a bunch of vectors that form a perfect cube.  This is FUN!  Both people in your group should do this to get the experience.  (Race to see who gets it first.)  
Do it this way:  let one corner of the cube be at {0,0,0}, and let the opposite corner be {1,1,1}.  Let o={0,0,0} be the origin, and label your other corners c1, c2, ..., c7.  That way you won't have to keep typing them in.  Here, I'll get you started...

o = {0, 0, 0};

    c1  =  {1, 0, 0};

Question 2b: Now that you've done question 2a, do the below command and explain what you see in a sentance or two:

Show[
      Graphics3D[{Thickness[ .01], Arrow3D[o, c1],  Arrow3D[o, c2], 
          Arrow3D[o, c3],  Arrow3D[o, c4],  Arrow3D[o, c5],  
          Arrow3D[o, c6],  Arrow3D[o, c7]}],  Axes -> True,  
      AspectRatio -> Automatic]

Vectors do Work

(READ THIS.  You're gonna learn something! (Though you may have seen this before in a physics class...))
One of the big uses of vectors is to solve physics Work problems that are more complicated than the ones you saw last quarter.  Recall that the Work done when applying a Force over a Distance is:
				Work = Force * Distance
This assumes that the force is acting in the same direction as the distance being travelled.  remember that.

So suppose we have a heavy box sitting at the origin in the x-y plane.  We tie a rope to it and, while standing on the x-axis, pull on the rope with a force of 20 Newtons.  The situation can be viewed as in the below picture:

\(Show[
          Graphics[{Thickness[ .01], 
              Arrow[{0, 0}, {3, 1}], 
Arrow[{0, 0}, {4, 
                  0}], RGBColor[1, 0, 0], 
              Arrow[{ .01,  .05}, {3,  .05}], 
Text[
                FontForm["P", {"Courier-Bold", 
                    14}], \ {1.5, \(- .15\)}], \ 
              RGBColor[0, 0, 0], 
Text[
                FontForm["F", {"Courier-Bold", 
                    14}], {1.5,  .75}], 
Text[
                FontForm["D", {"Courier-Bold", 
                    14}], {3.25, \(- .25\)}], 
Text[
                FontForm["F", {"Courier-Bold", 
                    14}], {1.5,  .75}], 
Text[
                FontForm["θ", {"Times", 
                    14}], { .85,  .15}], 
Dashing[{ .02,  .02}], \ Line[{{3, 1}, {3, 0}}]}], \ AspectRatio -> Automatic]\)

In the picture, the force F should be a vector with magnitude 20, or |F|=20.  (That's just a fancy way of saying the length of F is 20.)  But the work being done will be determined by the P vector, which is F projected down onto the x-axis.  Then we'll get
				Work = |P|*|D|
But notice:  Cos[θ] = ((|P|)/(|F|)), so |P| = |F|Cos[θ].  In other words,

				Work = \(TraditionalForm\`\(\(|\)\(F\)\(|\)\(\(*\)\(\(|\)\(D\)\(|\)\(\(*\)\(\ \)\(Cos[θ]\)\)\)\)\)\)

Question 3a: If the angle the rope is making with the ground is 45°, and we drag the box 30 meters, how much work has been done (you still have |F| = 20)? (Use Mathematica to get an EXACT answer.)

There's a better way we can do this:  with vectors!  It turns out there is a vector operation, the Dot Product, which will compute this "work quantity" for us.  Mathematica uses a period "." to denote the dot product, and the official formula for the dot product of a vector v with another vector u is:
			v.u = |v|*|u|*Cos[θ]
where θ is the angle between the vectors.  Don't worry about this formula right now;  Mathematica will do it for you!

Question 3b: Use the dot product to re-do Question 3a.  That is, define a vector F with magniture 20 that makes a 45° angle with the x-axis.  Then define a vector Dvec along the x-axis with magnitude 30.  Then use the dot product to calculate the work done.

Question 4: Use Mathematica and the dot product to find the angle between the vectors a=<3,4> and b=<5,12>.  (Your answer can be in either radians or degrees.)

Now that you're done, 
	(1) 	Clean up your work by deleting everything that's not needed.  
		There should only be the title, your names, section number, and the questions and your answers
		(with any needed explanations, graphs, etc.).
	(2) 	Save this to your disk.
	(3)	Go back to Blackboard and upload your final lab report to the Digital Drop Box, located
		in the User Tools area.  Remember that you have to first ADD your file to your digital drop box and 
		then SEND it to me!