I'm confused by this. Why use a 3D matrix for a 2D transformation?
I'm confused by this. Why use a 3D matrix for a 2D transformation?
"For example, a point in space is a 3×1 matrix. To transform it, you multiply it by a 3×3 transformation matrix."
It seems we're transforming a point in 3D space using a 3x3 matrix, no?
Say we're working in 2d and have a unit square starting at the origin and we want to translate it right by 1. This is not possible with any kind of matrix multiplication by a 2x2 matrix. That's easy to confirm if you just try it but trivially the lower right hand corner is on the origin and anything you multiply by zero is going to be zero. So any 2x2 matrix you multiply the coordinates of your square by is going to result in something where that point is still at the origin.
So instead what you do is pop your square up a dimension into 3D. So now you have a unit cube. If you do a shear of the unit cube by 1 in the x direction (which is a 3x3 matrix multiplication), you can take the projection ("shadow") of the top face of the cube to get back into 2D and you'll find it's where you wanted it (moved over by 1).
<meta-point: apologies - my original response seems to have been chopped in half. I didn't mean to submit in this form and I was in meetings etc so it's too old to edit now>
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotati...
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.