Use of Vectors.

Copyright (c) Susan Laflin. August 1999.

A vector has both magnitude and direction. For example, when the clue in the treasure hunt concludes ` .... and take 20 paces towards the crooked oak-tree', it specifies a vector. If it merely gave the magnitude of the distance (20 paces), you would have to search the circumference of a circle. If it gave direction and no magnitude, you would have to search along a straight line from the starting point all the way to the tree and possibly beyond it. With the vector, you are directed to a single point, thus greatly reducing the search.

A `unit vector' is a vector with a magnitude of unity and so it is used to specify a direction.

The most widely used set of unit vectors are those which relate to the coordinate axes. Here i is the unit length along the Ox axis, j is that along the Oy axis and k is that along the Oz axis. Hence the point P(x,y,z) may be represented by the vector from the origin O to the point P.

p = x* i + y* j + z* k

The magnitude of the vector p is given by |p| = SQRT(x*x + y*y + z*z)

Equation of a Straight Line.

Consider the equation of the line which joins the two points P1 = (x1,y1,z1) and P2 = (x2,y2,z2). Any other point P = (x,y,z) on the same line is given by
p = (1-k) p1 + k p2
or
p = p1 + k ( p2 - p1)

where p1 is the `base vector' and d = (p2 - p1) is the `direction vector'. This single vector equation is equivalent to the three scalar equations
x = x1 + k (x2-x1)
y = y1 + k (y2-y1)
and
z = z1 + k (z2-z1)

and these give the coordinates of the point P = (x,y,z) with each coordinate being calculated independently. As with the corresponding two-dimensional equations, values of k between 0 and 1 give points in the segment P1-P2 while negative values of k give points on its continuation beyond P1 and values of k greater than one give points on its continuation beyond P2.

The magnitude of the vector d gives the length of the line P1-P2. If you are only interested in the direction of the line and not in its length, then you need to specify a unit vector and in this case the components are called `direction cosines'. To calculate these from the vector d you proceed as follows:

d = ( x2-x1, y2-y1, z2-z1 )

The magnitude of d is given by the equation

d = | d | = SQRT{ (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 }

and so we have:
cos A1 = (x2-x1)/d
cos A2 = (y2-y1)/d
and
cosA3 = (z2-z1)/d

which are the direction cosines for this line. These imply that A1, A2 and A3 are the angles between the line and the x, y and z axes respectively.

Scalar or Dot Products

The `scalar product' or `dot-product' or `inner-product' of two vectors A and B is given by the expression:

A.B = | A | | B | cos(theta)

where theta is the angle between the two vectors. This is equal to the expression

A.B = Ax*Bx + Ay*By + Az*Bz

Graphically it may be thought of as either the product of the magnitude of A and the projection of B on to A, or vice versa. If the two vectors are perpedicular to each other, then the angle theta is equal to 90degrees and so its cosine is zero. This means that

A.B = 0

If the two vectors are parallel, then we have:

Ax/Bx = Ay/By = Az/Bz

and so their components are proportional.

Example of the Use of the Dot-Product.

To find the angle between the vectors A = (3,6,9) and  B = (-2,3,1).
The dot-product is: 	 A.B = 3*(-2) + 6*3 + 9*1 = 21
The magnitudes are: 	 | A | = SQRT{ 3*3 + 6*6 + 9*9 } = 3 * SQRT{14}
and			| B | =  SQRT{ (-2)*(-2) + 3*3 + 1*1 } = SQRT{14}
Now we know that   A.B = | A |* | B | * cos (theta )
and so 	 cos (theta) = 21/ (3* SQRT{14} * SQRT{14} }  =  1/2
Consequently theta = 60degrees is the required angle between the two lines.

Intersection of Two Lines

Next consider calculating the point of intersection of two lines. In two dimensions, the only problem occurs when the lines are parallel and do not have a finite point of intersection. In three dimensions, you also have to check for the case when the lines are not coplanar and so cannot intersect each other. The simplest way to check this is to solve the two-dimensional case, and then check the z-coordinates to see whether they are equal.

So the lines have the equations : 	P = B1 + k*D1 
and 					P = B3 + m*D3

and this gives equations in x, y, and z (three equations) for the two values of k and m. Solving the equations in x and y to give the value of m, we have

x1 + k( x2-x1) = x3 + m(x4-x3)	and	y1 + k(y2-y1) = y3 + m(y4-y3)

Eliminating k from these equations gives

{ (x3-x1)+m(x4-x3)}/{(x2-x1)} = { (y3-y1)+m(y4-y3)}/{(y2-y1)}

rearranging these gives
  (x3-x1)(y2-y1) + m(x4-x3)(y2-y1) = (y3-y1)(x2-x1) +m(y4-y3)(x2-x1)

  (x3-x1)(y2-y1) - (y3-y1)(x2-x1) = m((y4-y3)(x2-x1)-(x4-x3)(y2-y1))

Dividing through by (x2-x1)(x4-x3) gives
(x3-x1)(y2-y1)/{(x2-x1)(x4-x3)}-(y3-y1)/(x4-x3) = 
			m(y4-y3)/(x4-x3)-(y2-y1)/(x2-x1)

So once again there is no solution if 	
		(y4-y3)/(x4-x3) = (y2-y1)/(x2-x1)

Otherwise the value of m is given by
 m= {(x3-x1)(y2-y1)-(y3-y1)(x2-x1)}/{(y4-y3)(x2-x1)-(y2-y1)(x4-x3)}

If the lines are not parallel, this will give the value of m and hence the value of k. If these values lie between 0 and 1 then the intersection lies within the segments concerned. This tells you that the lines given by the projection onto the plane z=0 of the actual lines in three dimensions have a suitable point of intersection. Now you have to check the position in the z-direction. To do this, you must substitute the values of k and m into the z-equations for the two points. If the resulting z-values are equal, then the points are coplanar. Otherwise you know that they are at different heights above the plane z=0 and so they miss each other even though their projections(or shadows) intersect.

Equations of a Plane

The equation of a plane is defined in terms of the unit vector normal to that plane. If N is the unit vector normal to the plane and X is the vector from the origin to a point X lying on the plane, then you have the expression:

N . X = constant

There are many parallel planes which have the same normal, and so the size of the constant identifies which plane is required. If another point A also lies on the same plane, then you know that

N . (X - A) = 0

It is also possible to calculate the equation of a plane passing through three points, but in order to do this you need to study the `vector-product' or `cross product' of two vectors.

Vector or Cross Products

Consider the vectors P = (p1,p2,p3) and Q = (q1,q2,q3). 
The cross-product is given by the equation

		 P x Q = (p1, p2, p3) x (q1, q2, q3)  = (c1, c2, c3) 

where c1 = | p2   p3 |	c2 = 	| p3  p1 |	c3 =	| p1  p2 |
	   | q2   q3 |  	| q3  q1 |		| q1  q2 |

or	[c1,c2,c3] =  [ (p2q3-q2p3), (p3q1-q3p1), (p1q2-q1p2) ] 

and this gives a vector which is perpendicular to both P and Q.

The plane through the three points A, B and C has a normal N which is perpendicular to both the line AB and the line AC. That is a vector which is normal to both the vector (A-B) and the vector (A-C). So any other point X on the plane through the points A, B and C is given by:

[(A-B) x (A-C)] . (A-X) = 0

and this can easily be evaluated for any particular case.

There are many other equations to be found in texts on coordinate geometry, for example the equation of the line of intersection of two planes, but these are sufficient for the present.