How does 4x4 matrix work in 3d graphic?

2020-03-07 05:37发布

问题:

I am learning about 3d graphics and have stumbled upon matrixes, which I don't fully understand. I have a 3d object, with topology, points in coordinate system and ECS (4x4 matrix of the object). ECS is:

-1.1247455413666E-32 , 1.83690953073357E-16, 1                    , -95  , 
 1                   , 6.12303176911189E-17, 0                    , 604  , 
-6.12303176911189E-17, 1                   , -1.83690953073357E-16, 200.5, 
 0                   , 0                   , 0                    , 1    , 

What does each line separated with comma mean ? Are these translation vectors?

回答1:

Matrices define linear transformations between vector spaces. All linear transformations map the origin of the domain to the origin of the range. Therefore 3x3 matrices cannot perform translation on 3D vectors since the origin in one space cannot be mapped to anything but the origin on another using linear maps.

To overcome this problem, we can fake the system into performing translations through the use of an extra dimension where all vectors will have a 1 in the last vector component. These 4D vectors will never be at the origin (having 1 in the last component) and so are not required to always map to the origin. Through the use of this we can construct a 4x4 matrix to perform translation as in:

| 1  0  0  Tx|   | x |   | x + Tx |
| 0  1  0  Ty|   | y |   | y + Ty |
| 0  0  1  Tz| x | z | = | z + Tz |
| 0  0  0   1|   | 1 |   |   1    |

For rendering purposes, the 1 in the last position is dropped.



回答2:

The upper left 3x3 block gives the rotation of the coordinate system, the upper 3 coordinates of the last column give the translation vector.

The general idea of this affine parametrization is that for the transformation one multiplies

[ x, y, z, 1 ]^T

from the right.