Transformation of two-dimensional plane



video source

insert image description here

1: Zoom

Assuming that the coordinates of each vertex are (x, y), if we ask it to scale sx times in the x direction and
sy times in the y direction, then the coordinates after transformation: (x' = sx*x) (y' = sy *y )

insert image description here
insert image description hereinsert image description here

insert image description here
insert image description here

2: Pan

Similarly, if we want to translate an object in space, assuming that the displacement in the x direction is tx and the y direction is ty, then the coordinates after the transformation can be expressed as the formula on the rightinsert image description here
insert image description here

3: Translation conversion to homogeneous matrix combined with other transformations

Since matrix multiplication is the calculation of multiplying and adding corresponding elements,
we have no way to directly rewrite the translation into the form of a matrix.
Comparing the formulas, we will find that there is a lack of a constant term.
We can pass the two-dimensional coordinates (x, y) through a Three-dimensional vector to represent
, and simply set the third dimension to 1
and then use a 3x3 matrix to do the transformation
, and write the translation amount in the third column of the matrix
, and it unfolds just like the translation formula we mentioned earlier
. The technique of adding another dimension to the vector is also called homogeneous coordinates.
In this way, we can use a 3x3 matrix to represent any transformation in two-dimensional space (translation/scaling/rotation). The
corresponding three-dimensional space transformation can be represented by a 4x4 matrix. express

insert image description here
insert image description here
insert image description here

4: Rotate

Suppose we want to rotate a vertex (x, y)
whose distance from the origin is r, and the angle formed with the origin is α.
According to trigonometric functions, we can write x as r * cosα and y as r * sinα.
Suppose we inverse along the origin Rotate the vertex θ angle clockwise
, then the rotated coordinates can be similarly written as x'=cos(α+θ), y'=sin(α+θ)
through the addition theorem of trigonometric functions
where cos(α+θ) can be It is expanded into cosαcosθ-sinasinθ
and sin(α+θ) is expanded into sinαcosθ+cosαsinθFinally,
we bring it into the previous formula.
The rotated coordinates x', y' can be expressed as the sum of the product of the coordinates before rotation and the trigonometric function
This formula can be further simplified into the form of the matrix below. The trigonometric function proof link
insert image description hereinsert image description hereinsert image description here
insert image description here used in the figure below

5: Matrix multiplication is associative

The relationship between matrix multiplication
and linear transformation compounding
insert image description here
insert image description here

insert image description hereinsert image description here

other references

Guess you like

Origin blog.csdn.net/weixin_43763292/article/details/126850642