Vectors are of fundamental importance in any 3D game engine. They are used to represent points in space, such as the locations of objects in a game or the vertices of a triangle mesh. They are also used to represent spatial directions, such as the orientation of the camera or the surface normals of a triangle mesh. Understanding how to manipulate vectors is an essential skill of the successful 3D programmer.

Throughout this book, we encounter vectors of various types, usually representing two-dimensional, three-dimensional, or four-dimensional quantities. For now, we make no distinction between vectors representing options and vectors representing directions, nor do we concern ourselves with how vectors are transformed from one coordinate system to another.

### Vector Properties

### The Dot Product

The __dot product__ of two vectors, also known as the __scalar product__ or __inner product__, is one of the most heavily used operations in 3D graphics because it supplies a measure of the difference between the directions in which the two vectors point.

This definition states that the dot product of two vectors is given by the sum of the products of each component. In three dimensions, we have

The dot product may also be expressed as the matrix product:

Now for an important theorem that reveals the ubiquitous utility of the dot product.

Given two -dimensional vectors and , the dot product satisfies the equation

where is the planar angle between the lines connecting the origin to the points represented by and .

### The Cross Product

The __cross product__ of two three-dimensional vectors, also known as the __vector product__, returns a new vector that is perpendicular to both of the vectors being multiplied together. This property has many uses in computer graphics, one of which is a method for calculating a surface normal at a particular point given two distinct tangent vectors.

The cross product of two 3D vectors and , written as , is a vector quantity given by the formula:

A commonly used tool for remembering this formula is to calculate cross products by evaluating the pseudodeterminant

##### Theorem 2.8

where is the planar angle between the lines connecting the origin to the points represented by and .

We know that any nonzero result of the cross product must be perpendicular to the two vectors being multiplied together, but there are two possible directions that satisfy this requirement. It turns out that the cross product follows a pattern called the __right hand rule__.