3D mathematics-more knowledge about matrices (5)

Source: Internet
Author: User

General Affine Transformation

The 3x3 matrix can only represent linear transformations in 3D and cannot contain translations. After being armed with a 4x4 matrix, we can now construct a general affine transformation matrix including translation. For example:

(1) do not rotate through the axis of the origin.

(2) scale along the plane that does not pass through the origin.

(3) flat images that do not pass through the origin.

(4) orthogonal projection to a plane that does not pass through the origin.

Their basic idea is to translate the transformed "center" to the origin, then perform linear transformation, and then translate the "center" back to the original position. Start to use the translation matrixTChange PointPMove to the origin, and then use the linear transformation matrixRLinear transformation, and the final affine transformation matrixMEqual to the product of the matrix, that is:TRT-1.T-1Is the translation matrix, and the execution andTThe opposite transformation.

It is interesting to observe the general form of this matrix. Let's first use the "multipart" form to write the previously usedT,R,T-1.

It can be seen that the translation added in the affine transformation only changes the last line of the 4x4 matrix, and does not affect the 3x3 part of the linear transformation contained above.

 

Perspective Projection

The best way to learn perspective projection is to compare it with normal projection. Orthogonal projection is also called Parallel projection, because the projection line is parallel (the projection line refers to the line from the point in the original space to the projection point ). Parallel line 9.3 in orthogonal projection:

In 3D, perspective projection is still projected onto the 2D plane, but the projection lines are no longer parallel. In fact, they intersect at one point, which is called the projection center. 9.4:

Because the projection center is in front of the projection plane and the projection line has already intersection before it reaches the plane, the image on the projection plane is flipped. When the object is far away from the center of the projection, the orthogonal projection remains unchanged, but the Perspective Projection becomes smaller. 9.5:

In Figure 9.5, the teapot on the right is farther away from the projection plane, so its projection is smaller than the teapot closest to the projection plane. This is a very important visual phenomenon, called perspective scaling.

 

Small Hole Imaging

Perspective Projection is very important in graphics because it is a model of human visual systems. In fact, human visual systems are far more complex than that, because we have two eyes, and for each eye, the projected surface (retina) is not a plane. So let's look at a simple example-Small Hole imaging. A small hole imaging system is a box with a small hole on one side. The light shines through the small hole to the back of the other side, where it is the projection plane. 9.6:

As shown in figure 9.6, the left and right sides of the box are transparent so that you can see the inside of the box. Note that the projection inside the box is inverted, because the light (projection line) has already exceeded at a small hole (projection center.

Let's explore the geometric principles behind small hole imaging. Imagine a 3D coordinate system. Its origin is in the center of the projection, its Z axis is perpendicular to the projection plane, and its X and Y axes are parallel to the projection plane. 9.7:

Let's see if we can calculate the expected point.PCoordinates projected from a small hole to a projection planeP'. First, you need to know the distance from the small hole to the projection plane, and set it to D. Therefore, the projection plane is Z =-D. Now, let's look at the problem from another perspective and find the New Y. 9.8.

Obtained from a similar triangle:

Note that the image is reversed by the small hole imaging,PYAndPy'.Px'Can be obtained through a similar method:

The Z values of all projection points are the same:-D. Therefore, the result of point P projection to the plane Z =-D through the origin is shown in formula 9.11:

In practical applications, negative signs bring unnecessary complexity. So move the projection plane to the front of the projection (that is, the plane Z = D), as shown in 9.9:

Of course, this is impossible for the actual small hole imaging. Because the purpose of setting a small hole is to make the light pass through only small holes, but in the computer mathematics world, you can ignore these rules. As you wish, move the projection plane to the center of the projection, and the annoying negative sign disappears, as shown in formula 9.12:

 

4x4 matrix for Perspective Projection

The transformation from 4D to 3D means division, so we can use a 4x4 matrix to write code to implement perspective projection. The basic idea is to proposeP'In the formula, X, Y, and Z have a denominator, and then a 4x4 matrix is constructed to make W equal to this denominator. Here we assume that the initial point is W = 1.

Expressed in 3D format firstP'Deformation of the formula:

When the 4D homogeneous vector is transformed to 3D, divide the 4D vector by W.P'The 4D format is:

[X y z/D]

Therefore, we need a 4x4 matrix that can receive a singular homogeneous vector. The vector is in the form of [x, y, z, 1] and then transformed into the above form. Such a matrix is shown in formula 9.13:

In this way, we get a 4x4 projection matrix. There are several points to note:

(1) multiplied by this matrix does not carry out the actual perspective projection transformation. It just calculates the proper denominator. Projection actually occurs when it is transformed from 4D to 3D.

(2) There are multiple transformations. For example, placing a projection plane at Z = 0 and a projection center at [0, 0,-D] leads to a different formula.

(3) It looks complicated here. It seems that we only need to simply divide it by Z, so we don't have to bother with the matrix. So why should we use a homogeneous matrix? First, the 4x4 matrix provides a method to convert the projection table so that it can be connected to other transformations. Second, it makes it feasible to project to a plane that does not travel on the coordinate axis. In fact, we do not need to perform any operations on the homogeneous coordinates, but the 4x4 matrix provides a simple way to express and manipulate the projection transformation.

(4) The projection matrix in the actual ry pipeline is not exported here, and there are many important details to consider. If the preceding matrix is used to transform a vector, the Z value is actually discarded, and this value is used in many graphics systems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.