Question about the CFrame matrix

This question is kind of a mathy one.

So I was wondering why the cframe matrix had that [0 0 0 1] row, and from what I get it’s just supposed to make the matrix a 4x4 matrix. And the row is [0 0 0 1] because that’s what the row is by default (the identity matrix).

image

Now my questions is, why can’t we have a 3x4 matrix? Is it not able to express a rotation. I mean after all, the last row doesn’t do anything, whether if you multiply it or do anything with it.

Thank you! I hope my question doesn’t get too complicated

4 Likes

I’m no expert with this stuff, but this Stack Overflow post might help. Here’s another one.

1 Like

I believe CFrames actually are stored as a 3x3 rotation matrix and a 3-component translation vector, so that’s the same amount of storage as a 3x4 matrix. (the first number is the number of rows, not columns).

But algorithmically it’s simpler to understand composition of CFrames, and using them to transform vectors, as multiplications with 4x4 matrices (this also grants extra capabilities like a perspective divide as shown in @Crazyman32’s linked post, but I don’t believe CFrames support this).

The rule of matrix multiplication is that when you multiply an axn matrix times an nxb matrix, you get a axb matrix as a result, and the ns have to be the same - the number of columns in the left matrix must be equal to the number of rows in the right. (A “vector” with n components can be treated as a nx1 matrix.) So to do multiplication
involving a 3x4 matrix and a vector, the only possibility is to start with a 4-component vector and get a 3-component vector as a result, and you can’t multiply two 3x4 matrices together.

So CFrames are implemented as if they were 4x4 matrices where the last row is always [0 0 0 1], and similarly Vector3s get treated as if they had a 4th component with a value of 1.

7 Likes

Thank you! Especially for always checking out my questions!

Thank you a lot for this flawless explanation! I really wanna dig deeper into the 4-dimensional visualising stuff.

I did realise how stupid I was, I totally forgot that matrices can only be multiplied if

I’m a dummy dum dum :slight_smile: