3D affine transformation matrix derivation

Affine transformations include linear transformations and translational transformations. First, the rotation transformation in linear transformations is a little more complicated.

Before talking about this, I assume that you already have a certain understanding of linear algebra, such as trigonometric functions, vectors, and related knowledge of matrices (and the geometric meaning they represent). If you are not familiar with the above knowledge, it is difficult to understand the following content. .

Affine transformations include rotation, scaling, translation, shearing, reflection, etc. In 3D space, all these effects are done through matrices, that is, matrix multiplication, which satisfies the associative law , that is to say, we can translate and rotate the object to the final position by first processing the translation matrix and then the rotation matrix, or we can first combine the two matrices of translation and rotation into a final matrix, which is applied to the object to achieve the effect.

Of course, the rotation can be a combination of any dimension in the x-axis, y-axis, and z-axis. Based on the above inference, we only need to deduce the rotation of any axis, and then combine the three-dimensional rotation into the final matrix and apply it to on the object.

So let's take the Z axis as an example. If we rotate around the Z axis, the coordinates of the Z axis remain unchanged. We project any point N in the space to the plane where the XY is located, regardless of the Z axis, assuming that the projection point is P (x, y), when rotating around the Z axis (imagine this scenario, it helps to understand the proof below), the projected point rotates by a certain angle to reach the point P1 (x1, y1), as shown below:


According to the multiplication rules of matrices, the matrix M that rotates around the Z axis can be obtained. Similarly, if we rotate around the X axis or the Y axis, it can be easily proved.

A more intuitive understanding is given below:

We know that any point or vector in 3D space can be represented as a combination of basis vectors (unit vectors in the X, Y, Z directions, respectively), and in object space, we define the range of the coordinate axis as [-1, 1 ], before any linear transformation, the three basis vectors are X(1,0,0), Y(0,1,0), Z(0,0,1), see the figure below, if yes Rotation around the X axis, that is, the rotation of the ZY plane, is as follows:



Similarly: rotate around the Y axis as:


Rotation around the Z axis is:


The above image is from  Angles to Axes

This is to look at the rotation matrix from two perspectives, the same way, but the following one, intuitive, concise, very suitable for understanding, no need to prove.

According to the rules of matrix multiplication, the coordinates before scaling and the coordinates after scaling are:

 

即 x '= ax, y' = ay, z '= az

Then the scaling matrix is:


The translation matrix is:


Why does the translation transform become a four-dimensional matrix (4x4), according to the result of the final operation

x' = x+t

y' = y+t

z' = z+t

If you don't add a dimension, you cannot use unified matrix multiplication to represent translation transformation (the projection matrix also unifies the transformation by adding a dimension), you only need to simply add one dimension to perfectly unify all transformation operations. , that is, through the multiplication operation, the linear transformation and the translation transformation are unified (affine transformation), which is convenient for calculation.

Using affine transformation, the object can be transformed from the model space coordinate system to the world space coordinate system through the Model Matrix

Through the View Matrix, objects can be converted from the world control coordinate system to the view (camera) space coordinate system

Through the Projection Matrix, you can convert objects from the view (camera) space coordinate system to the screen


Next: Projection matrix



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325811833&siteId=291194637