Chapter 8: 2D and 3D Transformations
Transformations are operations that modify an object's position, size, and orientation in space. By using matrices and homogeneous coordinates (as introduced in Chapter 4), we can represent these transformations in a unified mathematical way.
2D Transformations
In 2D, we represent points as and use 3x3 matrices to transform them.
Translation
Shifting an object from one position to another.
Scaling
Changing the size of an object relative to the origin.
Rotation
Rotating an object around the origin by an angle .
Reflection
Flipping an object across an axis (e.g., the or axis).
Shearing
Distorting the shape of an object along one or both axes.
3D Transformations
In 3D, we use 4x4 matrices and points represented as .
Translation in 3D
Adding a depth component ().
Scaling in 3D
Adding a scaling factor () for the axis.
Rotation in 3D
Rotation in 3D is more complex as it occurs around an axis.
- About X-axis: coordinates remain the same.
- About Y-axis: coordinates remain the same.
- About Z-axis: coordinates remain the same.
Composition of Transformations
The real power of matrix-based transformations is that we can combine multiple operations into a single matrix through multiplication.
- Order Matters: Multiplication is non-commutative. is different from .
- Pivot Points: To rotate or scale an object around an arbitrary point , we must:
- Translate the pivot to the origin.
- Perform the rotation or scaling.
- Translate the pivot back to its original position.
Summary
Matrices provide a compact and powerful way to manipulate objects in space. Whether we are moving a 2D character or rotating a complex 3D model, the underlying mathematics remain remarkably consistent. Mastering the composition of transformations is essential for creating complex animations and hierarchical models.