I want to do some 2D drawing and thus want to implement some matrix transformations. With my light mathematics background I am trying to understand how to do so in C# (any other oop language would do it obviously).
All I read is explaining that we need to work with 3x3 matrices to be able to cope with the translations. Because you cannot make translation with multiplications. But this is with multiplications of the matrices that we create our transformations. So we work with something like:
{ x1, x2, tx }
{ y1, y2, ty }
{ 0, 0, 1 }
I understand the mean of the third column, but why do we need the third row? In a identity matrix as well as in a rotation, scale or rotation the last row is the same. Are there operations I did not reach yet which will need it? Is it because some languages (Java) performs better with "squared dimensions" arrays? If so I can use 3 columns and 2 rows in C# (since jagged arrays works as well or better).
For example, for a rotation + translation I have a matrix like this
{ cos(rot)*x1, (-sin(rot))*x2, tx }
{ sin(rot)*y1, cos(rot)*y2, ty }
{ 0, 0, 1 }
No need of the last row.
this is with multiplications of the matrices that we create our transformations
This is why we want square matrices.
Suppose we did what you propose, and used 2x3 matrices for our transformations.
Then a rotation would be
( x1, x2, 0 )
( y1, y2, 0 )
and a translation would be
( 1, 0, tx )
( 0, 1, ty )
and we could perform either rotations or translations by multiplying our matrix by a column vector representing the point:
( x )
M ( y )
( 0 )
to get correct answers.
However - how would we go about composing transformations? Indeed, for your "for a rotation + translation I have a matrix like this" example, how did you get to that matrix? Sure, in this case you can just write it out, but in general? Well, you know the answer:
this is with multiplications of the matrices that we create our transformations
So it must be possible to multiply two transformation matrices to give another transformation matrix. And the rules of matrix multiplication show that this:
( . . . ) ( . . . )
( . . . ) ( . . . ) = ???
is not a valid matrix multiplcation. We need matrices that can be multipled in order for our transformations to be composable. So we have that extra row.
Now, the way I've expressed it here is in fact completely backward from the standard mathematical presentation, in which the familiar transformations of rotation and translation are just special cases of the full power of homogeneous coordinate transformations on the projective plane - but I think it will do to show you why we need that extra row - to make the matrix square, and thus able to be multipled with like matrices.