Transform2D

每个Object都有自己的坐标系统,把这个物体放在世界坐标系统后,对Object执行变换操作,本质上是在变换它的坐标系,而不是改变物体上的点线面的位置。

Transform2D的结构是这样的:

$$\begin{bmatrix} basis.x.x & basis.y.x & origin.x \\ basis.x.y & basis.y.y & origin.y \end{bmatrix}$$

如果我执行旋转操作的时候,本身是给某个点执行左乘旋转矩阵,旋转矩阵的长这样:

$$
R(θ) =
\begin{bmatrix}
\cosθ & -\sinθ \\
\sinθ & \cosθ
\end{bmatrix}
$$

入股哦我们有一个2D的点或者一个Vector:

$$ v = \begin{bmatrix} x \\ y \end{bmatrix}$$

旋转矩阵执行矩阵乘法后是:

$$v’ = R(θ) \times v =
\begin{bmatrix}
\cosθ & -\sinθ \\
\sinθ & \cosθ
\end{bmatrix}
\begin{bmatrix}
x \\
y \end{bmatrix} = \begin{bmatrix}
x\cosθ – y\sinθ \\
x\sinθ + y\cosθ
\end{bmatrix}$$

平移:

因为平移操作无法通过2×2矩阵的线性计算获得,本质上是加一个偏移量,所以在计算机图形中使用Homogeneous coordinates,将一个2D的点/Vector扩展成3维的向量:

$$P_{h} = \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$

此时的transformations变成3×3的矩阵,比如要执行平移操作(translation)将所有点平移$(t_x, t_y)$,数学表达:

$$\begin{bmatrix} x’ \\ y’ \end{bmatrix} = \begin{bmatrix} x’+t_x \\ y’ + t_y \end{bmatrix}$$

在Hogogeneous coordinates的平移矩阵是

$$T(t_x, t_y) = \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix}$$

Leave a Reply

Your email address will not be published. Required fields are marked *