Vectors

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.
Screen Shot 2016-05-05 at 13.21.14 copy.png

 

 

 

 

 

 


a
= (4, 5, 6), b =  (1, 2, 3)
The difference between these vectors is: (ax – bx, ay – by, az – bz)
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 ab = c, so the distance is the magnitude of c.
The magnitude of a vector is expressed like this: |c|
|c| = √(cx2 + cy2 + cz2)
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?
Screen Shot 2016-05-05 at 13.59.59 copy 1

Simple, add the plane’s movement vector with that of the wind:
a + b = (ax + bx, ay + by, az + bz)
Screen Shot 2016-05-05 at 14.02.16 copy 2

And the resulting vector is the plane’s actual motion with the wind applied:
Screen Shot 2016-05-05 at 14.04.00 copy 2.png

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.

cx = aybz – azby
cy = azbx – axbz
cz = axby – aybx

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:

Advertisements