Home | AI | Physics | Mathematics | Compiler Design | Games | Downloads | About Me
You are visitor number 147042 since February 2003
Mathematics
Introduction
Vectors
 
Free Books


Vectors

There are some physical quantities, which are fully described by a single number with a unit (e.g the mass of a body or the speed of a car). On the other hand, there are other quantities that, in addition to the number, need a direction specified in order to be fully qualified. For example, traveling with a velocity of 50 miles per hour due south is not the same as traveling with a velocity of 40 miles per hour due east. This quantities are what we call vectors and it is important to distinguish them from scalars (physical quantities described by a single number). Examples of vector quantities are forces, velocity or the position of a robot.

Calculations performed on scalar quantities use the operations of normal arithmetic. For example, 10Kg − 6Kg = 4Kg, or 9s + 5s = 14s. However, combination of vectors requires a different set of operations.

To understand more about vectors and how they combine, I am going to start with displacement, which is the simplest vector quantity. Displacement is simply a change in position of a point. This point may represent a particle or a small body.) The figure below shows the representation of the change in position from point P1 to point P2 by a line from P1 to P2, with an arrowhead at P2 to represent the direction of motion.

Displacement is a vector quantity because we must state not only how far the particle moves, but also in what direction. Walking 4m north from you front door doesn't get you to the same place as walking 4m northeast; these two displacements have the same magnitude, but different directions.

A vector quantity such as displacement is usually represented by a single letter with an arrow above it, such as , or in handwriting we underline the vector, such as V. We use these notations to distinguish them from scalar quantities. In my tutorials I use boldface to distinguish vectors from scalars.

When drawing a vector we always draw a line with an arrowhead at its tip. The length of the line shows the vector's magnitude, and the direction of the line shows the vector's direction.

Note: Displacement is not related directly to the total distance traveled. If a particle were to travel from P1 to P2 and then back to P1, the displacement for the entire trip would be zero whilst the total distance would be 2 × magnitude of P1P2.

If two vectors have the same direction, they are said to be parallel. If they have the same magnitude and the same direction, they are equal, not matter where they are located in space. The vectors shown in the figure below are equal even though they start at different points.

Two vectors are said to be equal only if they have the same magnitude and the same direction. For instance, the two vectors shown in the figure below have the same magnitude, but opposite directions; hence, they are not equal.

When two vectors V1 and V2 have opposite directions, whether their magnitudes are the same or not, we say that they are antiparallel. If they have the same magnitude, the relation between the two vectors is V1 =V2 or V2 =V1.

The magnitude of a vector quantity is usually represented by the same letter used for the vector, but in italic with no arrow on top. An alternative notation is the vector symbol with vertical bars on both sides. The two notations are shown below:

(Magnitude of V) = V = |V|

By definition the magnitude of a vector quantity is a scalar quantity (a number) and is always positive.

Below are the descriptions of the vector operations

Vector addition

Let's now suppose that a particle undergoes a displacement A, followed by a second displacement B. The final result is the same as if the particle had started at the same initial point and undergone a single displacement C. In vector addition we usually place the tail of the second vector at the head, or tip, of the first vector as shown in the figure below:

We call displacement C the vector sum, or resultant, of displacements A and B. This relationship is expressed symbolically as:

C = A + B

If we make the displacements A and B in reverse order, with B first and A second, the result is the same. It can be seen in the figure below:

Thus

C = B + A and A + B = B + A.

This shows that the order of terms in a vector sum doesn't matter. In other words, vector addition obeys the commutative law. The figure below shows an alternative representation of the vector sum.

When vectors A and B are both drawn with their tails at the same point, vector C is the diagonal of a parallelogram constructed with A and B as two adjacent sides.

Vector Subtraction

Vector subtraction is a special case of vector addition. Subtraction of a vector from another is performed by adding the corresponding negative vector, that is if we seek AB, we form A + (−B).

As an example consider the two vectors V1 and V2 shown below:

To perform the subtraction V1V2, we first invert the direction of V2 and since addition is commutative, we place the tail of V1 at the tip of V2 and perform the addition as show in the figure below:

Pretty easy, right?

Multiplication of a vector by a scalar

If k is a positive scalar and V is a vector then kV is a vector in the same direction as V but k times as long. If k is any negative scalar, kV is a vector in the opposite direction to V, and k times as long. As an example have a look at the figure below.

Unit vectors

Vectors which have a length 1 are called unit vectors. If U has length 4, for example, then a unit vector in the direction of U is clearly ¼U. More generally we denote the unit vector in the direction of U by Û. Recall that the length or modulus of V is |V| and so we can write:

Û = U⁄|U|, where |U| and 1⁄|U| are scalars.

Components of vectors

Up until now we have been adding and subtracting vectors using diagrams and by using the properties of right triangles. Measuring a diagram offers only very limited accuracy, and calculations with right triangles work only when the two vectors are perpendicular. So we need a simple but general method for adding vectors. This is called the method of components.

To define what we mean by the components of a vector, we begin with a rectangular (Cartesian) coordinate system of axes, and then we draw the vector we're considering with its tail at O, the origin of the coordinate system. We can represent any vector lying in the xy− plane as the sum of a vector parallel to the x−axis and a vector parallel to the y−axis. The two vectors are labeled Vx and Vy in the figure below and are called the component vectors of vector V, and their vector sum is equal to V.

In symbols they are written as follows:

V = Vx + Vy

By definition, each component vector lies along a coordinate-axis direction. Thus we need only a single number to describe each one. When a component vector Vx points in the positive x−direction, we define a number Vx to be equal to the magnitude of Vx. When the component vector Vx points in the negative x−direction, we define the number Vx to be equal to the negative of that magnitude, keeping in mind that the magnitude of a vector quantity is always positive. We define the number Vy in the same way. The two numbers Vx and Vy are called the components of V.

The components Vx and Vy of vector V are just numbers; they are not vectors themselves. This is why you don't see the components as boldface.

If we know the magnitude and the direction of a vector, we can calculate its components. We will describe the direction of a vector by its angle relative to some reference direction. The figure below shows the positive x−axis as the reference direction, and the angle between vector V and the positive x−axis is θ (spelled theta).

Imagine that the vector V originally lies along the +x−axis and that we then rotate it to its correct direction, as indicated by the arrow in the figure above. If this rotation is from the +x−axis toward the +y−axis, as shown in the figure above, then θ is positive; if the rotation is from the +x−axis toward the −y−axis, θ is negative. Thus the +y−axis is at an angle of 90°, the −x−axis at 180°, and the −y−axis at 270° (or −90°). If θ is measured in this way, then from the definition of trigonometric functions,

Vx ⁄ V = cos θ and Vy ⁄ V = sin θ;
Vx = V cos θ and Vy = V cos θ.
(θ measured from the +x−axis, rotating toward the +y−axis)
(V is the magnitude of V)

Note: The equations above are only valid when the angle θ is measured from the positive x−axis as described above. If the angle of the vector is given from a different reference direction or using a different sense of rotation, the relationships are different.

Using components

A vector can be described completely by giving either its magnitude and direction or its x− and y−components. We have already shown how to find the components of a vector when we have its magnitude and its direction. Now we are going to show you the reverse: find the magnitude and direction if we know the components of the vector. By applying the Pythagorean theorem to the figure above, we find that the magnitude of a vector V is

V = √(Vx2 + Vy2),

where we always take the positive root. The above equation is valid for any choice of x−axis and y−axis, as long as they are mutually perpendicular. The expression for the vector direction comes from the definition of tangent of an angle. If θ is measured from the positive x−axis, and a positive angle is measured toward the positive y−axis as show in the figure above, then

tan θ = Vy ⁄ Vx and θ = arctan Vy ⁄ Vx.

I will always use the notation arctan for the inverse of tangent function since it is closely related to atan as used by programming languages such as Java, C⁄C++, Python, ActionScript, etc….

Note: There is one slight complication in using the equations above to find θ. Suppose Vx = 2 m and Vy = −2m; then tan &theta = −1. But there are two angles having tangents of −1, namely, 135° and 315° (or 45°). In general, any two angles that differ by 180° have the same tangent. To decide which is correct, we have to look at the individual components. Because Vx is positive and Vy is negative, the angle must be in the fourth quadrant; thus &theta = 315° (or −45°) is the correct value. You should always draw a sketch to check which of the two possibilities is the correct one.

Here's how we use components to calculate the vector sum (resultant) of two or more vectors. The figure below shows two vectors V1 and V2 and their vector sum V, along with the x− and y−components of all three vectors. You can see from the diagram that the x−component Vx of the vector sum is simply the sum (V1x + V2x) of the x−components of the vectors being added. The same is true for the y−components.

In symbols the sum is described as follows,

Vx = V1x + V2x,   Vy = V1y + V2y   (components of V = V1 + V2).

The figure above shows this result for the case in which the components V1x, V1y, V2x, and V2y are all positive. You should draw additional diagrams to verify for yourself that the equations above are valid for any signs of components of V1 and V2.

The procedure for finding the sum of two vectors can easily be extended to any number of vectors. Let V be the vector sum of V1, V2, V3, V4, V5, …. Then the components of V are

Vx = V1x + V2x + V3x + V4x + V5x + …,
Vy = V1y + V2y + V3y + V4y + V5y + ….

We have talked only about vectors that lie in the xy−plane, but the component method works just as well for vectors having any direction in space. We introduce a z−axis perpendicular to the xy−plane then in general a vector V has components Vx, Vy and Vz in the three coordinate directions. The magnitude V is given by

V = √(Vx2 + Vy2 + Vz2).

Again, we always take the positive root. Also, the equations for the components of the vector sum V have an additional member:

Vz = V1z + V2z + V3z + V4z + V5z + ….

Finally, while our discussion of vector addition has centered on combining displacement vectors, the method is applicable to all other vector quantities as well.

Products of vectors

Two other powerful tools that facilitate working with vectors are the dot (or inner) product and the cross product. The dot product produces a scalar; the cross product operates only on three−dimensional vectors and produces another vector. In this section we review the basic properties of the dot product, principally to develop the notion of perpendicularity. After that, the cross product is introduced.

The scalar product of two vectors A and B is denoted by A · B. Because of this notation, the scalar product is also called the dot product.

To define the scalar product A · B of two vectors A and B, we draw the two vectors with their tails at the same point as shown in the figure below.

The angle between their directions is φ as shown; the angle φ always lies between 0° and 180°. (As usual, we use Greek letters for the angles.) The figure below shows the projection of vector B onto the direction of A;

This projection is the component of B parallel to A and is equal to B cos φ. We define A · B to be the magnitude of A multiplied by the component of B parallel to A. Expressed as an equation,

A · B = AB cos φ = |A||B|cos φ    (definition of the scalar (dot) product),

where φ ranges from 0° and 180°.

Alternatively, we can define A · B to be the magnitude of B multiplied by the component of A parallel to B, as shown in the figure below.

Hence A · B = B(A cos φ) = AB cos φ, which is the same as the previous equation above.

The scalar product is a scalar quantity, not a vector, and it may be positive, negative, or zero. When φ is between 0° and 90°, the scalar product is positive. When φ is between 90° and 180°, it is negative. Finally, when φ = 90°, A · B = 0. The scalar product of two perpendicular vectors is always zero.

For any two vectors A and B, AB cos φ = BA cos φ. This means that A · B = B · A.

The scalar product obeys the commutative law of multiplication; the order of the two vectors does not matter.

The scalar product can also be expressed in terms of components as follows:

A · B = AxBx + AyBy + AzBz    (scalar (dot) product in terms of components).

Thus the scalar product of two vectors is the sum of the products of their respective components.

The scalar product gives a straightforward way to find the angle φ between any two vectors A and B whose components are known. In this case the equation of the dot product expressed in terms of components can be used to find the scalar product of A and B. From the first expression of the dot product we can find it through AB cos φ. The vector magnitudes A and B can be found from the vector components with the formulas A = √(Ax2 + Ay2 + Az2) and B = √(Bx2 + By2 + Bz2), so cos φ and hence the angle φ can be determined.

Vector product

The vector product of two vectors A and B, also called the cross product, is denoted by A X B.

To define the vector product A X B of tow vectors A and B, we again draw the two vectors with their tails at the same point and then they lie in a plane as shown below.

We define the vector product to be a vector quantity with a direction perpendicular to this plane (that is, perpendicular to both A and B) as shown in the figure below.

The magnitude of this vector is equal to AB cos φ. That is, if C = A X B, then

C = AB cos φ    (magnitude of the vector (cross) product of A and B).

We measure the angle φ from A toward B and take it to be the smaller of hte two possible angles, so φ ranges from 0° and 180°. Thus C in hte equation is always positive, as a vector magnitude should be. Note also that when A and B are parallel or antiparallel, φ = 0° or 180° and C = 0. That is, the vector product of any vector with itself is zero. To see the contrast between the scalar product and the magnitude of the vector product, imagine that we vary the angle between A and B while keeping their magnitudes constant. When A and B are parallel, the scalar product will be maximum and the mangnitude of the vector product will be zero. When A and B are perpendicular, the scalar product will be zero and the magnitude of the vector product will be maximum.

There are always two directions perpendicular to a given plane, one on each side of the plane. We choose which of these is the direction of A X B as follows. Imagine rotating vector A about the perpendicular line until it is aligned with B, choosing the smaller of the two possible angles between A and B. Curl the fingers of your right hand around the perpendicular line so that the fingertips point in the direction of rotation; your thumb will then point in the direction of A X B.

Similarly, we determine the direction of B X A by rotating B into A.

The result is a vector that is opposite to the vector A X B. The vector product is not commutative! In fact, for any two vectors A and B,

A X B = −B X A.

If we know the components of A and B, we can calculate the components of the vector product, using a procedure similar to that for the scalar product. The components of C = A X B are given by

Cx = Ax + Bx,    Cy = Ay + By,    Cz = Az + Bz     (components of C = A X B).

Well, this is all you need to know to perform vector operations in computer graphics. I will in the future write a tutorial showing how to implement this operations in C++, Java, Flash ActionScript and Python. In the meantime, you can download the the implementations I provide below.

Files for download:

If you have any queries regarding this tutorial, do not hesitate to contact me.

Best Regards

Fidel






Books



© 2002, 2003 Fidel Viegas. All rights reserved.