Geometric transformation of 2D graphics

1. Basic transformation

1. translate

Definition: Repositioning to move an object from a coordinate position to another coordinate position along a straight path. Rigid body transformation of moving objects without deformation.

Original coordinate position: \ ((x, y) \) , translation distance \ (t_x \) , \ (t_y \) , new position \ ((x ', y') \) , then \ (x '= x + t_x, y '= y + t_y \)

Expressed in matrix form, let:

\[\vec{P}=\begin{pmatrix}x \\ y\end{pmatrix}\quad\vec{P'}=\begin{pmatrix}x' \\ y'\end{pmatrix}\quad\vec{T}=\begin{pmatrix}t_x \\ t_y\end{pmatrix} \]

Binary translation equation:

\ [\ thing {P '} = \ thing {P} + \ thing {T} \]

2. Rotate

When the reference point is \ ((0,0) \)

Definition: Using a reference point as the center of the circle, turn each point on the object \ ((x, y) \) around the center of the circle by a counterclockwise angle \ (θ \) to become the new coordinate \ ((x ', y ') \) Transformation.

\ [x '= rcos (φ + θ) = rcosφcosθ-rsinφsinθ \\ y' = rsin (φ + θ) = rsinφcosθ + rcosφsinθ \\ ∵x = rcosφ, y = rsinφ \\\ therefore x '= xcosθ-ysinθ \ quad y '= xsinθ + ycosθ \]

make:

\[\vec{R}=\begin{pmatrix}cosθ & -sinθ\\ -sinθ & cosθ\end{pmatrix} \]

Write in matrix form: \ (\ vec {P '} = \ vec {R} \ cdot \ vec {P} \)

Transformation equation rotating around any specified rotation position \ ((x_r, y_r) \)

  1. Translate the origin of the coordinate system to \ ((x_r, y_r) \)

  2. Rotate transformation in the new coordinate system

  3. Translate the coordinate origin back to the original coordinate system

\[x’=x_r+(x-x_r)cosθ-(y-y_r)sinθ\\y’=y_r+(x-x_r)sinθ+(y-y_r)cosθ \]

3. Change (zoom) Scaling

Definition: The transformation that makes the object enlarge or shrink according to the scale factors Sx and Sy.

\[x’=x\cdot S_x\qquad y’=y\cdot S_y \]

make

\[\vec{S} =\begin{pmatrix}S_x & 0\\ 0 & S_y\end{pmatrix} \]

Matrix form: \ (\ vec {P '} = \ vec {S} \ cdot \ vec {P} \)

\ (S_x \) , \ (S_y \) is less than 1, reduce the object size, \ (S_x \) , \ (S_y \) greater than 1, magnify objects. \ (S_x = S_y \) , keep the relative scale of the object consistent.

Special case

  • When \ (Sy = -1 \) , \ (Sx = 1 \) , press \ (x \) axis reflection
  • When \ (Sy = 1 \) , \ (Sx = -1 \) , press \ (y \) axis reflection
  • When \ (Sy = -1 \) , \ (Sx = -1 \) , according to the origin \ ((0,0) \) reflection

Second, the transformation matrix

Each basic transformation can be expressed in the form of a general matrix:

\ [\ thing {P '} = \ thing {M_1} \ thing {P} + \ thing {M_2} \]

Pan

The \ (2 \ times 2 \) matrix is ​​expanded to a \ (3 \ times 3 \) matrix, and the multiplication and translation terms of the two-dimensional geometric transformation are combined into a single matrix to represent the translation.

\[\begin{pmatrix}x' \\ y' \\1\end{pmatrix}=\begin{pmatrix}1 & 0 & t_x\\ 0 & 1 & t_y\\0 & 0 & 1\end{pmatrix}\cdot\begin{pmatrix}x \\ y \\1\end{pmatrix} \]

\ [\ thing {P '} = \ thing {T} (t_x, t_y) \ thing {P} \]

Rotation about origin

\[\begin{pmatrix}x' \\ y' \\1\end{pmatrix}=\begin{pmatrix}cos\theta & -sin\theta & 0\\ sin\theta & cos\theta & 0\\0 & 0 & 1\end{pmatrix}\cdot\begin{pmatrix}x \\ y \\1\end{pmatrix} \]

\ [\ thing {P '} = \ thing {R} (\ theta) \ thing {P} \]

Zoom relative to origin

\[\begin{pmatrix}x' \\ y' \\1\end{pmatrix}=\begin{pmatrix}S_x & 0 & 0\\ 0 & S_y & 0\\0 & 0 & 1\end{pmatrix}\cdot\begin{pmatrix}x \\ y \\1\end{pmatrix} \]

\ [\ thing {P '} = \ thing {S} (S_x, S_y) \ thing {P} \]

Three, compound transformation

1. translate

Located two successive translation vector \ ((t_ {x1}, t_ {y1}) \) and \ ((t_ {x2}, t_ {y2}) \) is the coordinate position \ (P \) , then The last change position \ (P '\) .

\[\vec{P’}=\vec{T}(t_{x2},t_{y2}){\vec{T}(t_{x1},t_{y1})\vec{P}}={\vec{T}(t_{x2},t_{y2})\cdot \vec{T}(t_{x1},t_{y1})}\cdot \vec{P} \\\vec{T}(t_{x2},t_{y2})\cdot \vec{T}(t_{x1},t_{y1})=\vec{T}(t_{x1}+t_{x2},t_{y1}+t_{y2})\\\therefore \vec{P’}=\vec{T}(t_{x1}+t_{x2},t_{y1}+t_{y2})\cdot \vec{P} \\ \]

2. Rotate

\ [\ vec {P '} = \ vec {R} (θ_2) {\ vec {R} (θ_1) \ cdot \ vec {P}} = \ vec {R} (θ_2) \ cdot \ vec {R} (θ_1) \ cdot \ thing {P} \\\ thing {R} (θ_2) \ cdot \ thing {R} (θ_1) = \ thing {R} (θ_1 + θ_2) \\\ therefore \ thing {P ' } = \ vec {R} (θ_2 + θ_1) \ cdot \ vec {P} \]

3. Zoom

\[\vec{S}(S_{x2}\cdot S_{y2})\cdot \vec{S}(S_{x1}\cdot S_{y1})=\vec{S}(S_{x1}\cdot S_{x2},S_{y1}\cdot S_{y2}) \]

Compound transformation matrix rotating around any specified rotation position \ ((x_r, y_r) \)

\[\begin{pmatrix}1 & 0 & x_r\\ 0 & 1 &y_r\\0 & 0 & 1\end{pmatrix}\begin{pmatrix}cos\theta & -sin\theta & 0\\ sin\theta & cos\theta & 0\\0 & 0 & 1\end{pmatrix}\begin{pmatrix}1 & 0 & -x_r\\ 0 & 1 & -y_r\\0 & 0 & 1\end{pmatrix}=\begin{pmatrix}cos\theta & -sin\theta & x_r(1-cos\theta)+y_rsin\theta\\ sin\theta & cos\theta & y_r(1-cos\theta)-x_rsin\theta\\0 & 0 & 1\end{pmatrix} \]

in conclusion

In order to carry out the compound operation effectively, the transformation matrix should be formed first, and all transformation sequences should be combined .

Four, affine transformation

The form is:

\ [x '= a_ {xx} x + a_ {xy} y + b_x \\ y' = a_ {yx} x + a_ {yy} y + b_y \]

Coordinate transformation

\ (x ', y' \) is a linear function of \ (x, y \)

Affine transformation has the characteristics that parallel lines are converted to parallel lines, and finite points are mapped to finite points. Translation, rotation, scaling, reflection, and miscutting are special cases of two-dimensional affine transformation.

Guess you like

Origin www.cnblogs.com/iamfatotaku/p/12684637.html