变换(二维与三维)

226 阅读1分钟

变换

  • 模型变换(Modeling)
  • 视图变换(Viewing)

2D变换

缩放

[xy]=[sx00sy][xy]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

反射(对称)

[xy]=[1001][xy]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} -1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

切变

纵坐标不变,水平变化

[xy]=[1a01][xy]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1 & a \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

旋转

默认情况下绕(0, 0)点旋转,逆时针旋转

Rθ=[cosθsinθsinθcosθ]R_\theta = \begin{bmatrix} cos_{\theta} & -sin_{\theta} \\ sin_{\theta} & cos_{\theta} \end{bmatrix}

线性变换

齐次坐标

为什么需要齐次坐标?

平移变换

x=x+txy=y+tyx' = x + t_x \\ y' = y + t_y

平移无法表示成矩阵形式

[xy]=[abcd][xy]+[txty]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} t_x \\ t_y \end{bmatrix}

平移操作不属于线性变换

增加一个维度

  • 2D point=(x,y,1)T2D\ point = (x, y, 1)^T
  • 2D vector=(x,y,0)T2D\ vector = (x, y, 0)^T

平移矩阵表示

(xyw)=(10tx01ty001)(xy1)=(x+txy+ty1)\begin{pmatrix} x' \\ y' \\ w' \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} = \begin{pmatrix} x + t_x \\ y + t_y \\ 1 \end{pmatrix}

放射变换(Affine Transformations)

Affine map = linear map + translation

(xy)=(abcd)(xy)+(txty)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \cdot \begin{pmatrix} x \\ y \end{pmatrix} + \begin{pmatrix} t_x \\ t_y \end{pmatrix}

使用齐次坐标

(xy1)=(abtxcdty001)(xy1)\begin{pmatrix} x' \\ y' \\ 1 \end{pmatrix} = \begin{pmatrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}

逆变换

M1M^{-1}

组合变换

一个复杂变换可以由多个简单变换组成,变换的顺序至关重要(矩阵不满足交换律)。

变换分解

3D变换

齐次坐标

  • 3D point = (x,y,z,1)T(x, y, z, 1)^T
  • 3D vector = (x,y,z,0)T(x, y, z, 0)^T

矩阵表示

(xyz1)=(abctxdeftyghitz0001)(xyz1)\begin{pmatrix} x' \\ y' \\ z' \\ 1 \end{pmatrix} = \begin{pmatrix} a & b & c & t_x \\ d & e & f & t_y \\ g & h & i & t_z \\ 0 & 0 & 0 & 1 \end{pmatrix} \cdot \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}

闫令琪 <<现代计算机图形学入门>>