# Common Uses:

- Represent a point in space or a force.
- Represent a direction.

# Useful Functions:

**Subtraction**– difference between vectors (distance, scale etc).**Magnitude**– length of a vector.**Addition**– combining two vectors to get a resulting vector.**Cross Product**– returns a vector perpendicular to two vectors, useful for finding the “up vector”.**Dot Product –**returns a scalar indicative of the angle between two vectors.**Normalisation**– used for a vector to represent a direction.

## Subtraction:

Note: Vectors are represented using lower case letters.

**
a** = (4, 5, 6),

**b**= (1, 2, 3)

The difference between these vectors is: (a

_{x}– b

_{x}, a

_{y}– b

_{y}, a

_{z}– b

_{z})

which equates to the new vector (3, 3, 3) which we will call vector

**c**.

## Magnitude:

The distance between **a** and **b **is the magnitude of the difference between them. In this case **a** – **b** = **c**, so the distance is the magnitude of **c**.

The magnitude of a vector is expressed like this: |**c**|

|**c**| = √(c_{x}^{2} + c_{y}^{2} + c_{z}^{2})

which = 5.19…

so the distance between the points **a** and **b**, is 5.19…

## Addition:

If you had an airplane flying forward with a tail wind coming from the back right, the tailwind would have an effect on the plane’s motion. How would you calculate this?

Simple, add the plane’s movement vector with that of the wind:

a + b = (a_{x} + b_{x}, a_{y} + b_{y}, a_{z} + b_{z})

And the resulting vector is the plane’s actual motion with the wind applied:

## Cross Product:

Note: this only works for vectors with 3 dimensions.

a x b means the cross product of the vectors a and b.

There are two ways to calculate the cross product – which returns a vector at right angles to both of the input vectors.

c_{x} = a_{y}b_{z} – a_{z}b_{y}

c_{y} = a_{z}b_{x} – a_{x}b_{z}

c_{z} = a_{x}b_{y} – a_{y}b_{x}

**or**

a x b = |a| |b| sin(Θ) n

where Θ is the angle between the two vectors and n is a unit vector at right angles to both a and b.

Note the “handedness” of your coordinate system as that will affect the direction of the output vector.

For more information click here.

## Dot Product:

Works with vectors of any dimension.

a.b means the dot product of a and b.

a.b = |a| x |b| x cos(Θ)

where Θ is the angle between the two vectors.

Note: this is useful when using normalised vectors (directions) as you get a values of

- 1 if the vectors are in exactly the same direction.
- -1 if they point in completely opposite directions.
- 0 if the vectors are perpendicular.

For more information click here.

## Normalisation:

Vectors that have a magnitude of 1 are called unit vectors and have been normalised.

To normalise a vector we simply divide each component by the vector’s magnitude.

Unit vectors are great for storing direction as you can multiply a force vector by a unit vector to get the force in the unit vector’s direction, without changing the force’s magnitude.

Note: for (x, y, z, w) vectors, the w component is often used to indicate whether the vector is a direction or position. w = 1 is position, w = 0 is direction.

# Sources:

- http://technology.cpm.org/general/3dgraph/

- http://www.3dgep.com/3d-math-primer-for-game-programmers-vector-operations/
- https://www.mathsisfun.com/algebra/vectors.html