3D mathematics-matrix and linear transformation

Source: Internet
Author: User

[To] http://www.cnblogs.com/bobyguo/articles/1263355.html

In general, the square matrix can describe any linear transformation. Linear transformation retains the straight lines and parallel lines, but the origin is not moved. While linear transformation retains a straight line, other geometric properties such as length, angle, area, and volume may be changed. In a non-technical sense, linear transformation may "stretch" the coordinate system, but will not "bend" or "roll" the coordinate system.

 

How does a matrix transform a vector?

Ry can be interpreted as a series of displacement parallel to the axis. Generally, any vectorVThey can all be written as "extensions:

Another form of slight difference is:

Note that the unit vectors on the right are the X, Y, and Z axes. Here, the concept is matted. Each coordinate of the vectors indicates the directed displacement parallel to the corresponding coordinate axis.

Let's rewrite the vector above.P,Q,RIt is defined as the unit vector pointing to + X, + Y, and + Z, as follows:

V= XP+ YQ+ ZR

Now, VectorVIs expressed as a vector.P,Q,RLinear transformation of, VectorP,Q,RIt is called a base vector. Here, the base vector is the Cartesian coordinate axis, but in fact, a coordinate system can be defined with any three base vectors. Of course, these three base vectors must be linearly independent (that is, they are not on the same plane ). ToP,Q,RCreate a 3x3 matrix m for the row and obtain the following matrix:

Multiply the matrix by a vector to obtain the following result:

If the line of the matrix is interpreted as the base vector of the coordinate system, multiplying the matrix is equivalent to executing a coordinate transformation. IfAM=B, We can say,MSetAConvertB.

From this point of view, the terms "Conversion" and "multiplication" are equivalent.

Frankly speaking, the matrix is not mysterious. It just uses a compact method to express the mathematical operations required for coordinate transformation. Furthermore, using linear algebra to operate matrices is a simple method for simple conversion or exporting more complex transformations.

 

Matrix format:

Base vector [1, 0, 0], [0, 1, 0], [0, 0, 1] multiplied by any MatrixM:

Multiply by the base vector [1, 0, 0]MThe result isM1st rows. The other two rows have the same result, which is a key finding: each row of the matrix can be interpreted as the base vector after conversion.

This powerful concept has two important properties:

1. There is a simple method to visualize the transformation represented by the matrix.

2. With the possibility of establishing a matrix in reverse direction-providing an expected transformation (such as rotation and scaling), a matrix can be constructed to represent this transformation. All we need to do is calculate the transformation of the base vector, and then fill in the transformed base vector in the matrix.

First, let's take a look at the 2D example, a 2x2 matrix:

What is the transformation represented by this matrix? First, extract the base vector from the matrix.PAndQ:

P= [2 1]

Q= [-1 2]

Figure 7.1 uses the "original" base vector (X axis, Y axis) as a reference and shows these vectors in the cartesian plane.

,

As shown in 7.1, X-base vector transformation is abovePVector, y base vectorQVector. Therefore, the method of imagining a matrix in 2D is to imagine the "L" shape composed of row vectors. In this example, we can clearly see that,MIt indicates that the part is rotated 26 degrees counter-clockwise.

Of course, all vectors are affected by linear transformation, not just base vectors. The most intuitive impression of transformation can be obtained from the "L" shape, the Complete 2D parallelogram composed of the base vector helps to further see the impact of the transformation on other vectors, as shown in Figure 7.2:

The parallelogram is called a deflection box. It is helpful to draw an object in the box, as shown in 7.3:

Obviously, the matrixMIt not only rotates the coordinate system, but also extends it.

This technology can also be applied to 3D conversion. There are two base vectors in 2D to form the "L" model. Three base vectors in 3D form a "tripod". First, let's show an item before conversion. Figure 7.4 shows a teapot, a cube. The base vector is at the unit vector.

(In order not to confuse the image, the Z-axis base vector [0, 0, 1] is not marked, and it is blocked by the teapot and cube .)

Consider the following 3D transformation matrix:

Extract the base vector from the row of the Matrix to imagine the transformation represented by the matrix. The transformed base vector, cube, and teapot 7.5 are shown below:

This transformation includes 45 degrees clockwise rotation of the Z axis and irregular scaling, making the teapot "higher" than before. Note that the transformation does not affect the Z axis, because the third row of the matrix is [0, 0, 1].

 

We can scale up or down an object by proportional factor K. If the same scale is applied in all directions and the object is "expanded" along the origin point, the object is scaled evenly. Even scaling can keep the object's angle and proportion unchanged. If the length is increased or decreased by K, the area is increased or decreased by K ^ 2. In 3D, the volume increases or decreases by K ^ 3.

If you want to squeeze or stretch an object, apply different factors in different directions. This is called uneven scaling. The angle of the object changes when the image is scaled unevenly. The length, area, and volume vary depending on the scaling factor in each direction.

If | K | <1, the object is "shorter". If | K |> 1, the object is "longer". If K = 0, it is orthogonal projection, if K <0 is the image.

The effect of uneven scaling is similar to shear. In fact, uneven scaling and shear are difficult to distinguish.

 

Scale along the coordinate axis

The simplest scaling method is to apply a separate scaling factor along each coordinate axis. scaling is performed along the vertical axis (in 2D) or plane (in 3d. If the zooming factor of each axis is the same, the zooming is even. Otherwise, the zooming is not even.

There are two different zooming factors in 2D: kx and KY. Figure 8.13 shows how different zooming factors are applied.

Intuitively, we can know the base vector.P,QIt is independently affected by the corresponding scaling factor:

P'= KxP= Kx [1 0] = [kx 0]

Q'= KyQ= Ky [0 1] = [0 Ky]

Construct a matrix using a base vector, as shown in formula 8.6:

For 3D, you need to add the third zoom factor KZ. The 3D zoom matrix is shown in formula 8.7:

 

Scale in any direction

We can scale the image in any direction without relying on the coordinate system.NThis is the unit vector in the horizontal scaling direction, k is the scaling factor, and the scaling side goes through the origin and is parallelNLine (in 2D) or plane (in 3d.

We need to export an expression to give a vectorV, You can useV,NAnd K.V'. To achieve thisVDecomposed into two components,V| AndV Branch, ParallelNAnd perpendicularNAnd meetV=V| +V.V| YesVInNFrom (V.N)NYou can getV|. BecauseVRegion perpendicularNIt will not be affected by the scaling operation. Therefore,V'=V| '+VContinue, the remaining question is how to getV| '. BecauseV| Parallel to the scaling direction,V| 'The Formula KV| The result is as follows: 8.14:

Summarize the known vectors and perform substitution:

Now that we know how to scale any vector, we can also calculate the scaled base vector. Here, we will only detail the method for finding a base vector in 2D, and the rest of the base vectors will be listed in turn. We only give the result (note that the column vector form is used below to make the equation form look better .)

Construct the matrix using the base vector to obtain the unit vector.NThis is the scaling direction, and K is the scaling matrix of the factor, as shown in formula 8.8:

In 3D, the base vector is:

Unit VectorNThe 3D zoom matrix with K as the factor is shown in formula 8.9:

In general, projection means dimensionality reduction. One method of projection is to use 0 as the scaling factor in a certain direction. In this case, all points are flattened to the vertical axis (2D) or plane (3D. This type of projection is called orthogonal projection (or parallel projection) because the straight lines from the original point to the projection point are parallel to each other.

 

Projection to the coordinate axis or plane

The simplest projection method is to project to the coordinate axis (2D) or plane (3D), as shown in Figure 8.15:

Projection to the coordinate axis or plane does not often occur in the actual transformation. In most cases, it is used to assign values to the low-dimensional transformation and discard the dimension. For example, assign a 3D point to a 2D point, discard the Z component, and only copy X and Y.

By making the zooming factor in the vertical direction zero, you can project to the coordinate axis or plane. Considering integrity, the transformation matrices are listed below, as shown in formula 8.10-8.14.

 

Projection to any straight line or plane

It can also be projected into any straight line or plane. As usual, because the translation is not considered, these straight lines or planes must pass through the origin. Projection is a unit vector perpendicular to a straight line or plane.NDefinition.

You can use the zooming factor of this direction to export the matrix projected in any direction to 0, as shown in formula 8.15 in 2D:

Remember hereNVertical to the projection line, rather than parallel. In 3D, verticalNThe plane projection matrix of is shown in formula 8.16:

 

Images

An image (also called reflection) is a kind of transformation. It is used to "fold" an object along a straight line (in 2D) or plane (in 3d). Figure 8.16 shows the image effect.

If the scaling factor is-1, the image transformation can be easily implemented.NIs a 2D unit vector. The matrix shown in formula 8.17 follows the origin and is perpendicularNTo convert the image.

In 3D, the reflection plane replaces the straight line. In formula 8.18, the matrix follows the origin and is perpendicularNTo perform image transformation:

Note that an object can only be "mirrored" once. If it is re-mirrored (when it is along a different axis or plane), the object will be turned back to the "front" (as imagined by a piece of paper ), this is the same as rotating an object in the original position.

 

Shear

Shear is a coordinate system "Twist" transformation, stretching it unevenly. The angle changes during shear, but the area and volume remain unchanged. The basic idea is to add the product of a coordinate to another. For example, in 2D, multiply y by a certain factor and add it to X to obtain x' = x + Sy, 8.17 as shown in:

The matrix implementing this shear transformation is:

 

Conversion combination

Imagine an object in any direction and position in the world. We want to render it to a camera in any direction and position. To achieve this, all vertices of an object must be transformed from the object coordinate system to the world coordinate system, and then from the world coordinate system to the camera coordinate system. The mathematical transformations are summarized as follows:

Matrix Multiplication satisfies the combination law, so we can use a matrix to directly transform from the object coordinate system to the camera coordinate system:

In this way, all matrices can be combined out of the rendering loop, so that the matrix multiplication in the loop only needs to be multiplied by a matrix (the object has many vertices, saving a single matrix multiplication method will increase a lot of efficiency), as shown below:

Therefore, matrix combination uses the combination law of matrix multiplication from the perspective of algebra. The row vector of the matrix is the base vector after transformation, which is also true in the case of multiple transformations. Matrix MultiplicationAB, Each row in the result isACorresponding rows and matrices inBThe result of multiplication. In other words, set A1, A2, and A3ACan be written as follows:

This makes the conclusion clearer,ABThe row vector in the result is indeedABase vectorBThe result of the transformation.

 

Change category

The transformed category is not mutually exclusive, and there is no certain "order" or "hierarchy", which makes one category more or less restrictive than the other category.

When we discuss general transformations, we will use a similar term: ing or function. In the most general sense, ing is a simple rule that accepts input and generates output. WeAToBOfFIngF(A) =B.

 

Linear transformation

In mathematics, if the following formula is met, the ingF(A) Is linear:

F(A+B) =F(A) +F(B) AndF(KA) = KF(A)

If the ing F maintains the basic operation: Addition and multiplication, The ing can be called linear. In this case, the result of adding the two vectors and then performing the transformation is the same as that of adding the transformed vectors. Similarly, the result of the number multiplication transformation of a vector is the same as that of the first line transformation and then number multiplication.

The definition of this linear transformation has two important lements:

(1) ingF(A) =AM, WhenMFor any square matrix, ing is a linear transformation because:

F(A+B) = (A+B)M=AM+BM=F(A) +F(B)

And

F(KA) = (KA)M= K (AM) = KF(A)

(2) The result of any linear transformation of zero vectors is still zero vectors. (IfF(0) =A,A=0. SoFIt cannot be a linear transformation. BecauseF(K0) =A,F(K0) ≠ KF(0), So linear transformation will not cause translation (the origin position will not change ).

In some documents, linear transformation is defined as a parallel line after transformation. In most cases, it is right, but there is a small exception: projection (when a linear projection becomes a point, what can we think of this point as parallel ?) In addition to this theoretical exception, this definition is correct. Linear transformation may cause "stretching", but the straight line does not "Bend", so the parallel lines are still parallel.

 

Affine Transformation

Affine Transformation refers to linear transformation followed by translation. Therefore, the set of affine transformations is the superset of linear transformation. Any linear transformation is an affine transformation, but not all of them are linear transformation.

Any FormV'=VM+BAll transformations are affine transformations.

 

REVERSIBLE TRANSFORMATION

If there is a inverse transformation that can "undo" the original transformation, the transformation is reversible. In other words, if there is a inverse transformationG, MakingG(F(A) =AFor anyA, IngF(A) Is reversible.

There is a reversible transformation of non-affine transformations, but they are not considered for the moment. Now, we focus on checking whether an affine transform is reversible. An affine transformation is a linear transformation plus translation. Obviously, the opposite amount can be used to "undo" the translation part, so the question is whether a linear transformation is reversible.

Obviously, all transformations except projection can be "undo". When an object is projected, some useful information in one dimension is discarded, which cannot be recovered. Therefore, all basic transformations except projection are reversible.

Any linear transformation can be expressed as a matrix, so the inverse transformation is equivalent to the inverse of the matrix. If the matrix is singular, the transformation is irreversible. The determinant of the reversible matrix is not 0.

 

Equisigned Transformation

If the angle and direction of the two vectors before and after the transformation do not change, the transformation is of the same angle. Only translation, rotation, and even scaling are equal-angle transformations. The proportional transformation will remain unchanged. The image is not an equisigned transformation, because although the angle between the two vectors remains unchanged, the angle direction changes. All angular transformations are affine and reversible.

 

Orthogonal Transformation

The term "orthogonal" is used to describe a matrix of a certain nature. The basic idea of orthogonal transformation is that the axes are perpendicular to each other without scaling.

Translation, rotation, and mirroring are only orthogonal transformations. The length, angle, area, and volume remain unchanged. (Even so, image transformation is considered orthogonal transformation, so you must pay close attention to the accurate definition of angle, area and volume ).

The determinant of the orthogonal matrix is 1 or negative 1. All orthogonal matrices are affinable and reversible.

 

Rigid Body Transformation

A rigid body transformation only changes the position and direction of an object, excluding the shape. The length, angle, area, and volume remain unchanged. Translation and rotation are only rigid-body transformations, and images are not considered rigid-body transformations. Rigid Body transformations are also called regular transformations. All rigid body transformations are orthogonal, angular, reversible, and affinable. Some Rigid Body transformations have a rotation matrix of 1.

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.