2.4 Vector manipulation



As vectors are different from scalars, a set of rules has been developed to control how the two mathematical entities interact with one another.

For instance, we need to consider vector addition, subtraction and multiplication, and how a vector can be modified by a scalar. Unit Vectors

By definition, a unit vector has a magnitude of 1. Unit vectors are extremely useful in computer graphics applications and are used to specify the orientation of surfaces, the direction of light sources and the virtual camera. If these vectors have a unit length, the computation time associated with vector operations can be minimized. Converting a vector into a unit form is called normalizing and is achieved by dividing a vector's components by its magnitude.

To formalize this process, consider a vector "r" whose components are x, y, and z. The magnitude and the unit form of r are given by:


2.4 Vector manipulation



The standard unit vectors in 3D are given the names i, j, and k that that are aligned with the x -, y- and z -axes respectively, where i=(1,0,0), j=(0,1,0), and k=(0,0,1).

Therefore, we can write any 3D vector such as (a,b,c) as: (a,b,c)=a i+ bj + ck.

For example: v=(2,5,3) is clearly the same as 2(1,0,0) + 5(0,1,0) +3(0,0,1) which is recognized as 2i + 5j + 3k [6]. Multiplying a Vector by a Scalar

Given a vector n, 2n means that the vector's components are doubled. For example:


Similarly, if we divide n by 2, its components are halved.


2.4 Vector manipulation



Vector Addition and Subtraction

Given vectors r and s, is defined as (see figure 2.8(a,b)):


Vector addition is commutative: r+s=s+r; while vector subtraction is not commutative.


2.4 Vector manipulation




Figure 2.8: Vector addition and Subtraction

Inner Product and the Vector Product

Mathematicians have discovered that there are two ways to multiply vectors together: one gives rise to a scalar result and the other a vector result.


2.4 Vector manipulation



The dot product (or inner) product produces a scalar; the cross (or vector) product operates only on 3D vectors and produces another vector. The inner and vector products are used to solve a number of important geometric problems in graphics. The dot symbol '•' is used to represent a dot product; while the symbol "x" is used to represent a vector one.

To calculate the dot product, we multiply corresponding components of the two vectors and add the results.

For example, the dot product of (3, 4) and (1, 6) is 27, and that of (2, 3, 1) and (0, 4,-1) is 11. If a=(a1,a2,a2) and b=(b1,b2,b3) are two vectors, then the dot product: An equivalent definition of the dot product is: Where theta is the angle between the two vectors (see the figure below) and |c| denotes the magnitude of the vector c.

An important use of the dot product is to test whether or not two vectors are orthogonal. Two vectors are orthogonal if the angle between them is 90 degrees (i.e. the dot product of two orthogonal vectors is zero).

For example, the two vectors (1,-1,3) and (3,3,0) are orthogonal because the dot product is 1(3)+(-1)(3)+3(0)=0. One important use of dot products is in projections.


2.4 Vector manipulation



The scalar projection of "b" onto "a" is the length of the segment AB (see figure 2.9). The vector projection of "b" onto "a" is the vector with this length that begins at the point A points in the same direction (or opposite direction if the scalar projection is negative) as "a".


Figure 2.9: The vector projection of "b" onto "a"

The vector projection is merely the unit vector a/|a| times the scalar projection of "b" onto "a". Mathematically: Thus, the scalar projection of "b" onto "a" is the magnitude of the vector projection of "b" onto "a".


2.4 Vector manipulation



The cross product on the other hand has many useful properties, but the one we use most often is that it is perpendicular to both of the given vectors. For example, let v1=(0,0,1), v2=(1,0,0) and v3=(0,1,0) are three vertices, and r and s are two vectors then t=r x s is shown in figure 2.10 [8].


Figure 2.10: The vector t is normal to the vectors r and s.


2.4 Vector manipulation



Given the 3D vectors a=(ax, ay, az) and b=(bx, by, bz), their cross product is denoted as axb. It is defined in terms of the standard unit vectors i, j, and k by:

For example, let a=(3,0,2) and b=(4,1,8), then axb=-2i-16j+3k. The cross product is not commutative, this means that:

2.4 Vector manipulation




2.4 Vector manipulation




2.4 Vector manipulation




2.4 Vector manipulation




2.4 Vector manipulation




2.4 Vector manipulation




2.4 Vector manipulation