7 ms·
Can anyone explain why in physics you use a 3x3 matrix for rotation but in computer graphics you have a 4x4 with “1” in the lower right corner of the matrix.
by pkrumins 4y ago
Can anyone explain why in physics you use a 3x3 matrix for rotation but in computer graphics you have a 4x4 with “1” in the lower right corner of the matrix.
- deleted 4y ago[deleted]
- arbitrandomuser 4y agoSuch 4x4 matrices allow for translations along with rotations (and skewing I think) into one linear transformation the 4th column can include the translation vector x,y,z and the last element is 1
- GuB-42 4y agoThese are called homogeneous coordinates, and as expected since you have 4x4 matrices, vectors are also 4D, usually in the form (x,y,z,1). The idea is that you can multiply each coordinate by a non-zero scalar and the vector represents the same point, it has several interesting mathematical properties. For computer graphics, the main advantage is that you can represent translation and projection in the matrix in addition to the other linear transformations like rotation and scaling. For projection, the 4th vector coordinate, usually named "w", is called the homogeneous coordinate and it is typically not 1 after going through the projection matrix. As a final step, it divides all the other coordinates, so (x,y,z,w) becomes (x/w,y/w,z/w,1), x/w and y/w are the 2D screen coordinates, and z/w goes into the Z-buffer.
- joppy 4y agoThe 4x4 represents both a 3x3 matrix A and a translation t, so that the “affine transformation” applied to a vector is v -> Av + t. One could pass around pairs (A, t) instead, and figure out how to compose those pairs, but it turns out there’s a nice way of embedding them in a 4x4 matrix such that composition is just 4x4 matrix multiplication. You may opt into some other mathematical niceties too, which are handy for applying perspective transformations, but the main takeaway is that you get efficient compositions of affine transformations.
- rogual 4y agoTo add to the explanations already given here, the way I think of it as a non-maths person is: A matrix represents a transform of the form: x' = Ax + By + Cz y' = Dx + Ey + Fz z' = Gx + Hy + Iz ...the A...I letters being the elements of the 3x3 matrix. (If you squint you can see the matrix above). Although this can represent scales and rotations, there's no way to represent a simple translation with this. As proof, imagine you want to move everything 3 units along the x axis. You really just want to add 3 to x (x' = x + 3) but you can't: x' is always defined in terms of x, y and z (x' = Ax + By + Cz). There's no room for a constant. To represent translations, then, what you really want is (x' = Ax + By + Cz + D), where D isn't multiplied by any component of the input vector, it's just D, your translation. Well, it turns out you can do this by just adding an extra column to the matrix and using 1 for the fourth component of your vectors. Now x' = Ax + By + Cz + Dw, where w=1, and D is your translation amount. The full matrix then becomes x' = Ax + By + Cz + Dw y' = Ex + Fy + Gz + Hw z' = Ix + Jy + Kz + Lw w' = Mx + Ny + Oz + Pw You can see how (D, H, L) now functions as a translation vector.
- tmoertel 4y agoJust to add to the existing responses, matrices represent linear transforms, which have many convenient properties. However, translation, that is moving things, is not a linear transform. (All linear transforms must map the zero vector to itself, but if you move an object at the origin somewhere else, it's no longer at the origin.) Translation is an affine transform. Now here's the trick. You can embed your three-dimensional space into a four-dimensional space at a fixed fourth coordinate (but not zero). In this new space, translation in the original three-dimensional space is a linear transform.