Vectors, Lines, and Planes in Maple
This worksheet explores basic vector commands in Maple as well as dealing with lines and planes.
Maple worksheet: vectors.mw
First, we must load the VectorCalculus package to compute with vectors and the plots package for some of our plots.
> | restart;
with(VectorCalculus): with(plots): |
The VectorCalculus package allows us to easily perform various vector operations. A vector is denoted "<1, 2, 3>" and Maple prints out: "" where "" is the i = (1,0,0) unit vector and so forth.
To compute a dot product use "." and to compute a cross product use "&x".
> | <1,2,3> . <4,5,6>; |
(1) |
> | <1,2,3> &x <4,5,6>; |
(2) |
Example: Consider the following vectors: v and w (defined below).
> | u := <-3, 3,-6>;
v := <-1, 4, 1>; w := < 1,-1, 2>; |
(3) |
Let's find the angle between u and v.
> | arccos(u.v/(Norm(u)*Norm(v))); |
(4) |
> | # Decimal approximation in radians.
evalf(arccos(u.v/(Norm(u)*Norm(v)))); |
(5) |
> | # Decimal approximation in degrees.
evalf(arccos(u.v/(Norm(u)*Norm(v)))*180/Pi); |
(6) |
Now let's show that u and v are not parallel, but u and w are. [Recall that two vectors are parallel if and only if there cross product is the zero vector.]
> | u &x v;
u &x w; |
(7) |
Three vectors are coplanar if and only if there triple scalar product is zero, so these vectors are coplanar.
> | u.(v &x w); |
(8) |
Example: Let's compute 3v - 2w, v·w, and v×w where and .
> | v := < 2, 4, -2>;
w := < 3, 0, -2>; 3*v-2*w; v.w; v &x w; |
(9) |
Let's find a unit vector pointing in the same direction as w (in other words, let's normalize w).
> | Normalize(w); |
(10) |
Alternate ways of normalizing w:
[Be careful. "Norm" computes the Euclidean (usual) length of a vector. "norm" does not.
> | w/Norm(w);
w/sqrt(w.w); |
(11) |
Now let's compute the projection of w onto v: and call this vector p. Then we will let q be the vector perpendicular to p so that p + q = w. Finally, we will plot all four of these vectors together.
> | p := (w.v)/(v.v)*v;
q := w-p; |
(12) |
The "arrow" command allows us to plot vector arrows. We give this command a point and a vector and it plots the vector based at that point. Sometimes we need to plot several things together. If we can't get a single command to produce all the plots at once, we can instead plot each part assigning it a name and then use the "display" command to show them all together.
The vector w is black, v is red, is green, and q is blue. Notice that and q are perpendicular, , and p and v are parallel.
> | vA := arrow(v, shape=arrow, color=red, thickness=3):
wA := arrow(w, shape=arrow, color=black, thickness=3): pA := arrow(p, shape=arrow, color=green, thickness=5): qA := arrow(p,q, shape=arrow, color=blue, thickness=5): display({vA,wA,pA,qA}, scaling=constrained, axes=boxed,orientation=[-170,-20,-120],viewpoint=circleleft); |
Example: A parallelogram has vertices: (1, 1), (4, 2), (3, 6), and (0,5). Let's plot two vectors which span this parallelogram together with the parallelogram and then find its area.
Let's make (1,1) our base point and draw vectors to (4,2) and (0,5). After plotting these things, we'll see that (3,6) is the vertex opposite (1,1).
> | a := <4,2> - <1,1>;
b := <0,5> - <1,1>; |
(13) |
Notice the remaining point will give you the diagonal a+b:
> | <3,6> - <1,1> = a+b; |
(14) |
> | aA := arrow(a, shape=arrow, color=green, thickness=3):
bA := arrow(b, shape=arrow, color=red, thickness=3): abPar := polygonplot([convert(<0,0>,list), convert(a,list),convert(a+b,list),convert(b,list)],color=grey): display({aA,bA,abPar}, scaling=constrained, axes=none); Area := Norm(<3,1,0> &x <-1,4,0>); |
(15) |
Example: We will plot , , their cross product, , and the parallelogram which they span.
Notice that if we parameterize the plane (through the origin) spanned by and and restrict the parameters properly, we should end up with the parallelogram.
In particular, parameterizes the plane (through the origin) spanned by u and v. If we restrict our parameters: , then we will only fill out the parallelogram spanned by u and v.
> | u := <1,2,3>;
v := <1,-1,1>; |
(16) |
> | uPlot := arrow(<0,0,0>,u,shape=arrow,color=red,thickness=3):
vPlot := arrow(<0,0,0>,v,shape=arrow,color=blue,thickness=3): uCROSSvPlot := arrow(<0,0,0>,u &x v,shape=arrow,color=black,thickness=3): uATvPlot := arrow(v,u,shape=arrow,color=red,thickness=3): vATuPlot := arrow(u,v,shape=arrow,color=blue,thickness=3): uPLUSvPlot := arrow(<0,0,0>,u+v,shape=arrow,color=green,thickness=3): parallelogramPlot := plot3d(<0,0,0>+s*u+t*v,s=0..1,t=0..1,color=yellow): display({uPlot,vPlot,uCROSSvPlot,uATvPlot,vATuPlot,uPLUSvPlot,parallelogramPlot},scaling=constrained,orientation=[173,-78],viewpoint=circleleft); |
Example: Consider the line parameterized by (defined below). We wish to find the vector and then compute the distance from the point to the line using the formula: .
> | Q := <4,2,6>;
P := <2,1,-1>; a := <1,-1,3>; r := t -> P+a*t: 'r(t)' = r(t); |
(17) |
> | b := Q-P; |
(18) |
> | Dist := Norm(b &x a)/Norm(a); |
(19) |
> | simplify(Dist); |
(20) |
Now let's compute the projection of b onto a: and call this vector p. Also, let q be the vector perpendicular to p so that p + q = b. Finally, we will plot all four vectors (based at point P) together and find the length of q.
> | p := ((a.b)/(a.a))*a;
q := b-p; aA := arrow(P,a, shape=arrow, color=red, thickness=7): bA := arrow(P,b, shape=arrow, color=gray, thickness=3): pA := arrow(P,p, shape=arrow, color=green, thickness=3): qA := arrow(P,q, shape=arrow, color=blue, thickness=3): linePlot := spacecurve(r(t),t=-1..3,color=black): pointQ := pointplot3d(Q,symbolsize=10,symbol=sphere,color=red): display({aA,bA,pA,qA,linePlot,pointQ}, scaling=constrained, axes=boxed, orientation=[10,90],viewpoint=circleleft); Norm(q); |
(21) |
How are the distance and the length related? They are exactly the same! The vector q is perpendicular to the direction of the line and points from the line to point Q. So it's length is the distance between the point and the line. This is just an alternatively way of finding the distance.
Example: A certain parallelogram has vertices: (2,2,5), (3,2,4.5), (4,4,2.5), and (3,4,3).
I have plotted this parallelogram along with its projections onto the 3 coordinate planes below. Note that, for example, its projection onto the -plane (i.e. ) is the parallelogram with vertices: (2,2,0), (3,2,0), (4,4,0), and (3,4,0).
> | restart;
with(VectorCalculus): with(plots): with(plottools): x0 := [2,2,5]: a := [1,0,-1/2]: b := [1,2,-2]: P := [x0,x0+a,x0+a+b,x0+b]: Px := [[0,P[1][2],P[1][3]],[0,P[2][2],P[2][3]],[0,P[3][2],P[3][3]],[0,P[4][2],P[4][3]]]: Py := [[P[1][1],0,P[1][3]],[P[2][1],0,P[2][3]],[P[3][1],0,P[3][3]],[P[4][1],0,P[4][3]]]: Pz := [[P[1][1],P[1][2],0],[P[2][1],P[2][2],0],[P[3][1],P[3][2],0],[P[4][1],P[4][2],0]]: Pplot := polygon(P, color=green,linestyle=dash,thickness=2, transparency=0.5): Pxplot := polygon(Px, color=blue,linestyle=dash,thickness=2),seq(line(P[i],Px[i],color=black,linestyle=dash,thickness=2),i=1..4): Pyplot := polygon(Py, color=red,linestyle=dash,thickness=2),seq(line(P[i],Py[i],color=black,linestyle=dash,thickness=2),i=1..4): Pzplot := polygon(Pz, color=violet,linestyle=dash,thickness=2),seq(line(P[i],Pz[i],color=black,linestyle=dash,thickness=2),i=1..4): display(Pplot,Pxplot,Pyplot,Pzplot,orientation=[24,80],scaling=constrained,axes=normal,projection=0.85,tickmarks=[0,0,0],viewpoint=circleleft); |
We will compute the area of the parallelogram and assign it to the variable . Then we will compute the areas of its 3 projections calling these areas and .
Let P, Q, X, and Y be the vertices of the parallelogram. (I've replaced decimals with fractions so Maple does exact computations.)
> | P := <2,2,5 >;
Q := <3,2,9/2>; X := <4,4,5/2>; Y := <3,4,3 >; |
(22) |
Here are the vectors pointing from P to the other vertices.
> | a := Q-P;
b := X-P; c := Y-P; |
(23) |
Notice that a+c = b. This means X is the vertex opposite P. Thus the vectors a & c span the parallelogram.
> | a+c = b; |
(24) |
So the parallelogram is spanned by and .
To get vectors spanning the projections of this parallelogram. We should replace in
turn the i, j, and then k components in these vectors with zeros.
Finally, recall that the area of a parallelogram is given by the length of the cross
product of two vectors spanning that parallelogram.
> | A := Norm(<1,0,-1/2> &x <1,2,-2>);
R := Norm(<0,0,-1/2> &x <0,2,-2>); S := Norm(<1,0,-1/2> &x <1,0,-2>); T := Norm(<1,0, 0> &x <1,2, 0>); |
(25) |
Notice that the sum of the squares of the areas of the projections is the square of the area of the parallelogram. There is a 3D version of the Pythagorean theorem which says this is always the case!
> | A^2 = R^2 + S^2 + T^2; |
(26) |
Example: A parallelepiped is spanned by the vectors: a, b, and c (defined below). Let's find the volume of this parallelepiped then plot this shape along with vectors a, b, & c.
> | restart;
with(VectorCalculus): with(plots): a := <2,1,1>; b := <0,2,1>; c := <1,2,0>; Volume := abs(a . (b &x c)); |
(27) |
> | aA := arrow(a, shape=arrow, color=red, thickness=3):
bA := arrow(b, shape=arrow, color=green, thickness=3): cA := arrow(c, shape=arrow, color=blue, thickness=3): s1 := polygonplot3d([convert(<0,0,0>,list),convert(a,list),convert(a+b,list),convert(b,list)],color=grey): s2 := polygonplot3d([convert(<0,0,0>,list),convert(a,list),convert(a+c,list),convert(c,list)],color=grey): s3 := polygonplot3d([convert(<0,0,0>,list),convert(b,list),convert(b+c,list),convert(c,list)],color=grey): s4 := polygonplot3d([convert(a,list),convert(a+b,list),convert(a+b+c,list),convert(a+c,list)],color=grey): s5 := polygonplot3d([convert(b,list),convert(b+c,list),convert(a+b+c,list),convert(a+b,list)],color=grey): s6 := polygonplot3d([convert(c,list),convert(a+c,list),convert(a+b+c,list),convert(b+c,list)],color=grey): display({aA,bA,cA,s1,s2,s3,s4,s5,s6},scaling=constrained,axes=none,orientation=[-75,50,60],viewpoint=circleleft); |
Alternatively, we could use the "parallelepiped" command to plot our box.
Here's a little breakdown of my cryptic (fourth) command: "plottools[parallelepiped]" calls the function which plots a parallelepiped. This function is found in the "plottools" package. I didn't use "with(plottools):" to load the whole package because it would then overwrite the "arrow" command and break my other code. "op" strips "[" and "]" off of a list. So for example, "op([1,2,3]);" returns "1,2,3" then "map(convert,[a,b,c],list)" applies the "convert" command to a, b, and c with a second argument of "list". So it returns "[convert(a,list), convert(b,list), convert(c,list)]"
> | aA := arrow(a, shape=arrow, color=red, thickness=3):
bA := arrow(b, shape=arrow, color=green, thickness=3): cA := arrow(c, shape=arrow, color=blue, thickness=3): pPiped := plottools[parallelepiped](op(map(convert,[a,b,c],list)),color=gray): display({aA,bA,cA,pPiped},scaling=constrained,axes=none,orientation=[-75,50,60],viewpoint=circleleft); |
Example: A regular octahedron is a convex regular polygon with 8 sides. Each side is an equilateral triangle, 4 such triangles meet at each vertex. This is a highly symmetric object -- in fact, it has 24 rotational symmetries [For those who've taken MAT 3110: its group of rotations is isomorphic to the symmetric group .] I have graphed an octahedron below whose vertices are located at .
> | s1 := polygonplot3d([[ 1, 0, 0], [ 0, 1, 0], [ 0, 0, 1], [ 1, 0, 0]], color=grey):
s2 := polygonplot3d([[ 1, 0, 0], [ 0,-1, 0], [ 0, 0, 1], [ 1, 0, 0]], color=grey): s3 := polygonplot3d([[ 1, 0, 0], [ 0, 1, 0], [ 0, 0,-1], [ 1, 0, 0]], color=grey): s4 := polygonplot3d([[ 1, 0, 0], [ 0,-1, 0], [ 0, 0,-1], [ 1, 0, 0]], color=grey): s5 := polygonplot3d([[-1, 0, 0], [ 0, 1, 0], [ 0, 0, 1], [-1, 0, 0]], color=grey): s6 := polygonplot3d([[-1, 0, 0], [ 0,-1, 0], [ 0, 0, 1], [-1, 0, 0]], color=grey): s7 := polygonplot3d([[-1, 0, 0], [ 0, 1, 0], [ 0, 0,-1], [-1, 0, 0]], color=grey): s8 := polygonplot3d([[-1, 0, 0], [ 0,-1, 0], [ 0, 0,-1], [-1, 0, 0]], color=grey): aA := arrow(< 1, 0, 0>, <-1, 1, 0>, shape=arrow, color=green, thickness=3): bA := arrow(< 1, 0, 0>, <-1, 0, 1>, shape=arrow, color=blue, thickness=3): cA := arrow(<1,0,0>+<-1,1,0>,<-1,0,1>-<-1,1,0>, shape=arrow, color=red, thickness=3): display({s1,s2,s3,s4,s5,s6,s7,s8,aA,bA,cA},scaling=constrained,orientation=[-5,70,-70],viewpoint=circleleft); |
Let's define a, b, and c below so they are the same as the vectors plotted above. Then we'll use a cross product to compute the area of the triangular face surrounded by these arrows. We know that gives the area of the parallelogram spanned by and .
So dividing by 2 should give the area of the triangle with sides .
> | a := <-1,1,0>;
b := <-1,0,1>; c := b-a; triangle_area := Norm(a &x b)/2; |
(28) |
Multiplying by 8 (since there are 8 faces on the octahedron) gives us the surface area of the octahedron.
> | surface_area := 8*triangle_area; |
(29) |
Example: Let , , and . Let's find the equation of the plane passing through P,Q, and R. First, define u to be the vector from P to Q and v to point from P to R. Then is normal to the plan. So our desired equation is .
> | P := <1,2,0>;
Q := <1,-1,0>; R := <-1,-1,-2>; u := Q-P; v := R-P; n := u &x v; planeEqn := n.(<x,y,z>-P)=0: |
(30) |
Let's also find the equation of the normal line through Q. This passes through Q and is parallel to n.
> | r := t -> Q + n*t:
'r(t)' = r(t); |
(31) |
Now let's plot all of these together.
> | planePlot := plot3d(solve(planeEqn,z),x=-2..2,y=-2..4):
linePlot := spacecurve(r(t),t=-1/2..3/2,color=black,thickness=3): uPlot := arrow(P,u,color=green): vPlot := arrow(P,v,color=blue): nPlot := arrow(P,n,color=red): display({planePlot,linePlot,uPlot,vPlot,nPlot},axes=boxed,scaling=constrained,orientation=[-165,-5,-155],viewpoint=circleleft); |
Example: Consider the planes and . First, let's find the angle between these planes.
> | restart;
with(VectorCalculus): with(plots): n[1] := <2,-3,-1>; n[2] := <1,2,3>; arccos(n[1].n[2]/(Norm(n[1])*Norm(n[2]))); |
(32) |
But this angle is bigger than so we must need its supplement: .
Alternatively, we could just swap out one of the norm vectors with its negation. This flips the dot product from a negative number (obtuse angle) to a positive number (acute angle). Even better, why not take the absolute value of the dot product to guarantee we have the desired acute angle?
> | theta := arccos(abs(n[1].n[2])/(Norm(n[1])*Norm(n[2]))); |
(33) |
Next, let's find the line of intersection (where these planes intersect) and then parameterize this line. To do this we need to solve the simultaneous system of equations:
> | solve({2*x-3*y-z=5,x+2*y+3*z=4}); |
(34) |
Naturally we replace with and get a parametrization of our line.
> | r := t -> <22/7-t,3/7-t,t>:
'r(t)' = r(t); |
(35) |
Finally, let's plot both planes and their line of intersection in the same plot. To use plot3d we need to solve the plane equations for . We had to play around with the domain of in spacecurve until everything looked nice. For this parametrization a range: seems to do the job.
> | solve(2*x-3*y-z=5,z);
solve(x+2*y+3*z=4,z); plane1 := plot3d(-5+2*x-3*y,x=-5..2,y=-5..2,color=gray): plane2 := plot3d(4/3-1/3*x-2/3*y,x=-5..2,y=-5..2,color=gray): intLine := spacecurve(r(t),t=0..6,thickness=3,color=blue): display({plane1,plane2,intLine},viewpoint=circleleft); |
Example: Consider the line passing through the points P and Q and the line passing through the points R and S (P,Q,R and S defined below). Let v be the vector pointing from P to Q and w be the vector pointing from R to S.
> | P := < 1, 0,-2>;
Q := <-1, 1, 3>; R := < 2,-2, 1>; S := <-4, 4, 5>; v := Q-P; w := S-R; |
(36) |
Next, we will fill in the parametrizations of the lines. The first line passes through P and Q and the second through R and S. The first parametrization starts at P (i.e. ) and the second parametrization starts at R (i.e. ). In addition, we have chosen parameterizations such that they go from P to Q and R to S (i.e. we use the vectors v and w as direction vectors).
The plot of these lines shows that they intersect (so they lie in a common plane). I have given a parametrization of the plane which passes through P, Q, R, and S and called it .
> | r[1] := t -> P + v*t:
'r[1](t)' = r[1](t); r[2] := t -> R + w*t: 'r[2](t)' = r[2](t); r[3] := (s,t) -> P + s*v + t*w: 'r[3](s,t)' = r[3](s,t); |
(37) |
> | line1 := spacecurve(r[1](t),t=-2..2,thickness=3,color=blue):
line2 := spacecurve(r[2](t),t=-2..2,thickness=3,color=green): plane := plot3d(r[3](s,t),s=-2..2,t=-2.5..1.5,color=grey,transparency=0.5): display(line1,line2,plane,scaling=constrained,axes=boxed,viewpoint=circleleft); |
Let's find the point of intersection. We need , but Maple is picky about working with vectors. So we'll need to convert these vector valued functions to a list of expressions. Also, to make life easier we'll solve the equivalent equation .
> | solve(convert(r[1](t)-r[2](s),list));
r[1](1) = r[2](1/2); |
(38) |
The point of intersection is (-1,1,3).
Finally, let's plot the line segments PQ and PR along with the triangular region whose vertices are PQR.
Notice that "" where gives the line segment from P to Q [we start at P and then move along the vector pointing from P to Q -- that is -- "Q-P"]. Likewise "" where gives the line segment pointing from P to R.
The plane containing P, Q, and R can be parametrized by "". However, if we restrict our parameters and so that and , then we will plot the whole parallelogram spanned by the vectors Q-P and R-P (based at point P). Since we only want the triangle, we need to stop along the edge which correpsponds to the vector R-Q. Notice that the parametrization for the plane is "" so if we are to range between R [t=1, s=0] and Q [t=0, s=1], it seems reasonable to demand that "" so P is not involved. This gives us the bound we're looking for: "".
> | line1 := spacecurve(P+(Q-P)*t,t=0..1,thickness=3,color=blue):
line2 := spacecurve(P+(R-P)*t,t=0..1,thickness=3,color=green): plane := plot3d(P+(Q-P)*s+(R-P)*t,s=0..1,t=0..1-s,color=grey,transparency=0.5): display(line1,line2,plane,scaling=constrained,axes=boxed,viewpoint=circleleft); |