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 .
- Magnitude (Length): Calculated using the Pythagorean theorem.
- Normalization: Creating a unit vector (length = 1) by dividing the vector by its magnitude.
Dot Product
The dot product of two vectors and results in a scalar value.
- 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.
Cross Product
The cross product of two 3D vectors results in a third vector that is perpendicular to both.
- Magnitude: (the area of the parallelogram formed by and ).
- Graphics Use: To calculate the surface normal of a triangle. Given three vertices , the normal is .
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.
- Concatenation: Multiplying two matrices together combines their transformations. This applies first, then . 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.
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: is the matrix that "undoes" the transformation of . 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.