Introduction:
This tutorial goes over the basics of linear algebra, which is a very important concept in computer graphics.

Vectors:
Vector diagram
Vectors are numbers, or pairs of numbers, which have a length and direction. The overhead arrow, , is common notation for vector variables (i.e. a). Vectors are commonly expressed as coordinates, for example a 3D vector v is equivalent to the 3D coordinates (x,y,z).

In computer graphics, a vector are used for many different things, a few examples would be:
  • Points of a 3D model
  • Position of a character or object
  • Direction a character or object is moving in

Vector Operations:
Vector length:
Vector length diagram
A vector's length, denoted by 2 vertical bars ||, can be calculated using Pythagorean's theorem. For instance, the length of a 2D vector v=(x,y) is ||v||=x2+y2. In 3D, this would be:
v=(x,y,z) ||v||=x2+y2+z2

A vector which has length 1 is called a unit vector. Unit vectors have many useful properties, including:
  • Ideal for storing directions
  • Easy to scale to any length (by multiplying with a scalar, covered next)

Scalar multiplication:
Scalar multiplication diagram
Scalar multiplication multiplies a vector's elements by a scalar value, which essientially scales a vector's length. In the 3D case, this is:
s·v =s·(x,y,z) =(s·x,s·y,s·z)
For example, multiplying the 2D vector v=(2,3) by the scalar value 4 gives:
4·(2,3) =(4·2,4·3) =(8,12)
If a vector is a unit vector and it gets multiplied by a scalar value, its length will become equal to that scalar value:
||v||=1 s·||v||=s·1 ||s·v||=s

Vector addition:
Vector addition diagram
Vectors can be added together to produce new vectors. Vector addition simply adds each vectors element's together, for example in 3D that is:
v1+v2 = ( x1 , y1 , z1 ) + ( x2 , y2 , z2 ) = ( x1+x2 , y1+y2 , z1+z2 )

Vector addition is commutative, so the order of addition does not matter.

An example of somewhere vector addition may be useful is moving objects around a 3D world, an offset vector can be added to the object's current position to move it around.

Vector subtraction:
Vector subtraction diagram
Vectors can subtracted to calculate the differences between vectors. Vector subtraction simply subtracts each vector's elements, for example in 3D that is:
v1v2 = ( x1 , y1 , z1 ) ( x2 , y2 , z2 ) = ( x1x2 , y1y2 , z1z2 )
An example of somewhere vector subtraction may be useful is calculating a difference vector between 2 objects, or calculating directions between objects, etc.

Vector dot product:
Vector dot product diagram
The dot product, denoted by "·", of two vectors is a very important and common operation. The dot product of two 3D vectors is calculated as follows:
v1 · v2 = (x1·x2) + (y1·y2) + (z1·z2)
This calculation can be generalized to any number of dimensions (2D, 4D, etc.).

This calculation is equivalent to:
v1 · v2 = ||v1|| · ||v2|| · cos(θ)
Note that θ is the angle between v1 and v2.

The cos(θ) makes the dot product very useful to find the angle between two vectors using arccosine:
v1 · v2 = ||v1|| · ||v2|| · cos(θ) v1 · v2 ||v1|| · ||v2|| = cos(θ) θ = arccosine ( v1 · v2 ||v1|| · ||v2|| )
Note: If v1 and v2 are unit vectors, there is no need divide by ||v1|| ·||v2|| .

Another very useful property of the dot product is that if it is zero, it means the two vectors are perpendicular:
v1 · v2 = (x1·x2) + (y1·y2) + (z1·z2) = 0 ||v1|| · ||v2|| · cos(θ) = 0 cos(θ) = 0 θ=π2 or θ=3π2

Also note that a vectors dot product with itself is its length squared:
v · v = x·x + y·y + z·z = x2 + y2 + z2

Vector cross product:
Vector cross product diagram
The cross product, denoted by "×", of two vectors is another very common and important operation. The cross product can only be computed on 3D vectors, and the calculation is the following matrix determinant:
u × v = ( uyvz uzvy ) i ( uxvz uzvx ) j + ( uxvy uyvx ) k
This is equivalent to the determinant of the matrix (covered in next matrix section):
u × v = | i j k ux uy uz vx vy vz |

This cross product calculation is equivalent to:
u × v = ||u|| · ||v|| · sin(θ) n
Note that θ is is the angle between u and v, and n is the vector perpendicular to both u and v. This means the cross product returns a new vector which is perpendicular to both u and v.

The cross product can be very useful for many operations, i.e. calculating surface normals for lighting.

Vector projection:
Vector projection diagram
Vector projection is another common and important operation for computer graphics. The vector projection of the vector b onto the vector a, denoted by projab, gives the vector part of b parallel to a. The calculation of vector projection is:
projab = cos(θ) · ||b|| · a||a|| Note: a||a|| is the unit vector in the direction of a Note: cos(θ)·||b|| is the length of the projected vector Note: θ is the angle between a and b Recall: a·b=||a||·||b||·cos(θ) cos(θ) = a·b||a||·||b|| = a·b||a||·||b|| · ||b|| · a||a|| = a·b||a||·||a|| a Recall: ||a||·||a|| = a·a = a·ba·aa

Matrices:
Matrices are arrays of vectors which can be used to apply transformations to vectors.In 3D, we commonly use 2x2, 3x3, and 4x4 matrices for 2D, 3D, and 4D vectors respectively. A matrix has the form:
[ R00 R01 ... R10 R11 ... ... ... ... ]

A matrix can transform a vector by matrix vector multiplication, which is calculated by multiplying each row of the matrix by the vector to form a new vector. Example 3D matrix vector calculation:
[ M00 M01 M02 M10 M11 M12 M20 M21 M22 ] [ Vx Vy Vz ] = [ M00·Vx + M01·Vy + M02·Vz M10·Vx + M11·Vy + M12·Vz M20·Vx + M21·Vy + M22·Vz ]

Matrices can be combined together using matrix multiplication, which involves using the dot product on the rows of one matrix with the columns of the other matrix:
[ M00 M01 M02 M10 M11 M12 M20 M21 M22 ] [ N00 N01 N02 N10 N11 N12 N20 N21 N22 ] = [ [M00,M01,M02] · [N00,N10,N20] [M00,M01,M02] · [N01,N11,N21] [M00,M01,M02] · [N02,N12,N22] [M10,M11,M12] · [N00,N10,N20] [M10,M11,M12] · [N01,N11,N21] [M10,M11,M12] · [N02,N12,N22] [M20,M21,M22] · [N00,N10,N20] [M20,M21,M22] · [N01,N11,N21] [M20,M21,M22] · [N02,N12,N22] ] = [ ( M00·N00 + M01·N10 + M02·N20 ) ( M00·N01 + M01·N11 + M02·N21 ) ( M00·N02 + M01·N12 + M02·N22 ) ( M10·N00 + M11·N10 + M12·N20 ) ( M10·N01 + M11·N11 + M12·N21 ) ( M10·N02 + M11·N12 + M12·N22 ) ( M20·N00 + M21·N10 + M22·N20 ) ( M20·N01 + M21·N11 + M22·N21 ) ( M20·N02 + M21·N12 + M22·N22 ) ]

Sources: