CG Math

Coordinate System

3D Cartesian coordinate system conventions

  • Thumb: + x-axis
  • Index: + y-axis
  • Middle: + z-axis

Right-handed coordinate system

  • Maya

Left-handed coordinate system

Vector

A vector is defined by magnitude and direction, and noted as (x, y, z), but do no define positional data. On the other hand, points are noted as (x, y, z) but define positional data.

Magnitude notation can be optimized by not taking the square root.

Magnitude=x2+y2+z2Magnitude = \sqrt{x^2 + y^2 + z^2}

Magnitude2=x2+y2+z2Magnitude^2 = {x^2 + y^2 + z^2}

Scalar values scale vectors. Multiplying by negative scalar values result in a vector pointing in opposite direction of its original direction.

VectorA=VectorBScalarVectorA = VectorB * Scalar

Vectors can be added to other vectors to create new vectors.

VectorC=VectorA+VectorBVector C = Vector A + Vector B

Vector with length of 1 is a unit vector. Normalize a vector by dividing each element by the vector's magnitude.

Vectornormalized=(xmagnitude,ymagnitude,zmagnitude)Vector_{normalized} = ({\frac{x}{magnitude}, \frac{y}{magnitude}, \frac{z}{magnitude}})

Dot Product

Dot product between 2 vectors results in a scalar value defining the angle between the 2 vectors and to denote if the 2 vectors are pointing in the same general direction or not.

VectorAVectorB=VectorAVectorBcosθVectorA \cdot VectorB = |VectorA||VectorB|cos\theta

VectorAVectorB=cosθVectorA \cdot VectorB = cos\theta

For normalized vectors

θ=arccos(VectorAVectorB)\theta = arccos(VectorA \cdot VectorB)

VectorAVectorB=xAxB+yAyB+zAzBVectorA \cdot VectorB = x_Ax_B + y_Ay_B + z_Az_B

Dot product between 2 normalized vectors will always be in range {-1, 1}.

  • Dot product > 0, vectors are pointing in same general direction.
  • Dot product = 0, vectors are perpendicular to each other.
  • Dot product < 0, vectors are pointing in opposite directions.

Dot product of a vector B with a normalized vector A is the projection of vector B onto vector A.

Cross Product

Cross product between 2 vectors results in a new vector perpendicular to the original 2 vectors.

VectorAVectorB=yAzBzAyB,zAxBxAzB,xAyByAxBVector A * Vector B = y_Az_B-z_Ay_B, z_Ax_B-x_Az_B, x_Ay_B-y_Ax_B

Using this strategy can create a coordinate system with perpendicular vectors. Take the cross product between 2 vectors to create a new vector and then take the cross product between the first vector and the new vector to get the new third vector to create a perpendicular coordinate system.

VectorC=(VectorAVectorB)VectorAVector C = (Vector A * Vector B) * Vector A

This is also referred to as an orthonormal basis.

Matrix