3 ms·
Start with the desire - we want to have an algebra of 2D affine transformations with composition and (usually) inversion. We can represent this with the trick
by blt 2y ago
Start with the desire - we want to have an algebra of 2D affine transformations with composition and (usually) inversion.
We can represent this with the trick of "homogeneous coordinates", using 3D vectors with the last entry 1 and 3x3 matrices with the last row [0, 0, 1].
This is convenient because both mathematicians and programmers are familiar with linear transforms and matrices. It's in the comfort zone. There are many libraries.
However, it's wasteful to store all those extra 1's and 0's in memory. You can always replace the matrices with
class Affine2D {
Matrix2x2 linear;
Vector2 shift;
};
and overload all the algebraic operators, including multiplication with 2D vectors.