Mathematical Foundations of Graphics

Chapter 10: Mathematical Foundations of Graphics

Computer graphics is, at its heart, applied linear algebra. To create even the simplest 3D scene, we must master the language of vectors and matrices.

Vectors

A vector is a quantity that has both magnitude and direction. In graphics, we use vectors to represent positions, directions, velocities, and normals (the direction a surface is facing).

  • Components: A 3D vector is represented as v=(x,y,z)\mathbf{v} = (x, y, z).
  • Magnitude (Length): Calculated using the Pythagorean theorem. v=x2+y2+z2\|\mathbf{v}\| = \sqrt{x^2 + y^2 + z^2}
  • Normalization: Creating a unit vector (length = 1) by dividing the vector by its magnitude. v^=vv\hat{\mathbf{v}} = \frac{\mathbf{v}}{\|\mathbf{v}\|}

Dot Product

The dot product of two vectors a\mathbf{a} and b\mathbf{b} results in a scalar value.

ab=axbx+ayby+azbz=abcosθ\mathbf{a} \cdot \mathbf{b} = a_x b_x + a_y b_y + a_z b_z = \|\mathbf{a}\| \|\mathbf{b}\| \cos\theta

  • Geometric Significance: The dot product is zero if the vectors are perpendicular. It's positive if the angle is less than 90° and negative if greater than 90°.
  • Graphics Use: Essential for lighting calculations. The brightness of a surface often depends on the dot product of the surface normal and the light direction.
θ a b

Cross Product

The cross product of two 3D vectors results in a third vector that is perpendicular to both.

a×b=(aybzazby,azbxaxbz,axbyaybx)\mathbf{a} \times \mathbf{b} = (a_y b_z - a_z b_y, a_z b_x - a_x b_z, a_x b_y - a_y b_x)

  • Magnitude: a×b=absinθ\|\mathbf{a} \times \mathbf{b}\| = \|\mathbf{a}\| \|\mathbf{b}\| \sin\theta (the area of the parallelogram formed by a\mathbf{a} and b\mathbf{b}).
  • Graphics Use: To calculate the surface normal of a triangle. Given three vertices A,B,CA, B, C, the normal is (BA)×(CA)(B-A) \times (C-A).

Matrices

A matrix is a rectangular array of numbers. In 3D graphics, we primarily use 4x4 matrices.

Matrix Multiplication

Multiplying a matrix by a vector transforms the vector.

[abcdefghijklmnop][xyzw]=[ax+by+cz+dwex+fy+gz+hwix+jy+kz+lwmx+ny+oz+pw]\begin{bmatrix} a & b & c & d \\ e & f & g & h \\ i & j & k & l \\ m & n & o & p \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix} = \begin{bmatrix} ax+by+cz+dw \\ ex+fy+gz+hw \\ ix+jy+kz+lw \\ mx+ny+oz+pw \end{bmatrix}

  • Concatenation: Multiplying two matrices together combines their transformations. Mcombined=M2M1M_{combined} = M_2 \cdot M_1 This applies M1M_1 first, then M2M_2. Matrix multiplication is associative but not commutative.

The Identity Matrix

The matrix equivalent of the number 1. Multiplying any vector or matrix by the identity matrix results in no change.

I=[1000010000100001]I = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Determinant and Inverse

  • Determinant: A scalar value that describes the scaling factor of the linear transformation. If the determinant is 0, the matrix is singular and cannot be inverted.
  • Inverse Matrix: M1M^{-1} is the matrix that "undoes" the transformation of MM. MM1=IM \cdot M^{-1} = I Inverse matrices are used to transform vectors from world space back into local space or for special lighting calculations.

Summary

Vectors and matrices are the fundamental tools of computer graphics. They allow us to represent positions, calculate orientations, and perform complex transformations with mathematical precision. Every pixel you see on a screen is the final result of millions of these operations performed every second by a GPU.