2D Transformations

1. 平移(translation)

点 (x,y)平移到 (x',y'),经过的距离为 (tx, ty). 则

x' = x + tx

y' = y + ty

或者

P' = P + T

其中,

P'= \begin{bmatrix} x'\\ y'\\ \end{bmatrix} P=\begin{bmatrix} x\\ y\\ \end{bmatrix} T=\begin{bmatrix} tx\\ ty\\ \end{bmatrix}

\begin{bmatrix} x'\\ y'\\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & tx\\ 0 & 1 & ty\\ 0 & 0 & 1 \end{bmatrix} *\begin{bmatrix} x\\ y\\ 1 \end{bmatrix}

 2. 旋转(以坐标原点为中心喜转动角度 \theta, 逆时针 \theta大于0,顺时针 \theta小于0

 假设点(x,y)绕原点逆时针转动 \theta到(x',y'). 那么

x = r\cos \phi \quad y=r\sin \phi\\ x'=r\cos \left ( \phi +\theta \right ) \quad y'=r\sin \left ( \phi +\theta \right )

 三角函数展开,最后可以得出:

x' = x\cos \theta - y\sin \theta \quad y'=y\cos \theta + x\sin \theta

 \begin{bmatrix} x'\\ y' \end{bmatrix} =\begin{bmatrix} \cos \theta &-\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} *\begin{bmatrix} x\\ y \end{bmatrix}

 \begin{bmatrix} x'\\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos \theta &- \sin \theta & 0\\ \sin \theta & \cos \theta & 0\\ 0& 0& 1 \end{bmatrix} *\begin{bmatrix} x\\ y \\ 1 \end{bmatrix}

3. 绕任一点(p_{x},p_{y})旋转:

3.1 平移点(p_{x},p_{y})到原点 T(-p_{x},-p_{y})

3.2 旋转R(\theta)

3.3 平移该点到原来位置 T(p_{x},p_{y})

P' = T(-p_{x},-p_{y}) * R(\theta) * T(p_{x},p_{y}

\begin{bmatrix} x'\\ y'\\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & p_{x}\\ 0 & 1 & p_{y}\\ 0 &0 & 1 \end{bmatrix} * \begin{bmatrix} \cos \theta & -\sin \theta & 0\\ \sin \theta & \cos \theta &0 \\ 0& 0& 1 \end{bmatrix} * \begin{bmatrix} 1 &0 & -p_{x}\\ 0& 1 & -p_{y}\\ 0& 0 & 1 \end{bmatrix} *\begin{bmatrix} x\\ y \\ 1 \end{bmatrix}

x'= \left ( x-p_{x} \right ) \cos \theta -\left ( y-p_{y} \right ) \sin \theta +p_{x}

y'= \left ( x-p_{x} \right )\sin \theta+ \left ( y-p_{y} \right ) \cos \theta+ p_{y}

4.缩放(scaling)

通过缩放参数(S_{x},S_{y})改变对象的大小

 \begin{bmatrix} x'\\ y' \end{bmatrix}= \begin{bmatrix} S_{x} &0 \\ 0& S_{y} \end{bmatrix} *\begin{bmatrix} x\\ y \end{bmatrix}

\begin{bmatrix} x'\\ y'\\ 1 \end{bmatrix}=\begin{bmatrix} S_{x} &0 &0 \\ 0& S_{y}&0 \\ 0& 0& 1 \end{bmatrix} *\begin{bmatrix} x\\ y\\ 1 \end{bmatrix}

一个副作用是目标的位置也变了

5.以任一点P(p_{x},p_{y})为中心缩放

5.1 平移对象到点P额原点重合T(-p_{x},-p_{y})

5.2 缩放对象S(S_{x},S_{y})

5.3把对象移动到原来的位置 T(p_{x},p_{y})

 6.仿射变换(Affine Transformation)

上面提到的平移,旋转,缩放还有错切(shearing) 都是仿射变换。

仿射变换后的点是原来的点的线性组合

\begin{bmatrix} x'\\ y'\\ 1 \end{bmatrix}=\begin{bmatrix} m11 & m12& m13\\ m21& m22& m23\\ 0& 0& 1 \end{bmatrix} *\begin{bmatrix} x\\ y\\ 1 \end{bmatrix}

任意一个2维仿射变换都可以分解成旋转,缩放,错切(shearing)和平移这几个有序步骤。

Affine matrix = translation x shearing x scaling x rotation

如果对点P应用变换矩阵 M1, 然后 应用M2, 然后M3,

 一般变换矩阵不不符合交换律 (AxB != BxA)

参考:

https://web.cse.ohio-state.edu/~shen.94/681/Site/Slides_files/transformation_review.pdf

https://cseweb.ucsd.edu/classes/wi18/cse167-a/lec2.pdf

猜你喜欢

转载自blog.csdn.net/CaspianSea/article/details/122419858
2D