1 2D线性变换(2D Transformation)

1.1 缩放(Scale)

缩放变换是一种沿着坐标轴的变换,定义如下:

[Sx00Sy](Scale Matrix)\begin{bmatrix} S_x & 0 \\ 0 & S_y \\ \end{bmatrix} \tag{Scale Matrix}

即除了(0,0)T(0,0)^T保持不变之外,其他所有点都变成(SxX,SyY)T(S_xX,S_yY)^T

1.2 切变(Shear)

切变是将物体的一边固定住,然后去拉另外一边,也就是

[1a01](Shear-x(a) Matrix)\begin{bmatrix} 1 & a \\ 0 & 1 \\ \end{bmatrix} \tag{Shear-x(a) Matrix}

[10a1](Shear-y(a) Matrix)\begin{bmatrix} 1 & 0 \\ a & 1 \\ \end{bmatrix} \tag{Shear-y(a) Matrix}

1.3 旋转(rotation)

此处的旋转是逆时针旋转,并且其旋转中心是原点,直接给出定义和推导过程

[cosθsinθsinθcosθ](Rotation Matrix)\begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \\ \end{bmatrix} \tag{Rotation Matrix}

推导过程:

1.4 2维绕任意点旋转

例如我们绕旋转的点为cc

  1. 将点cc作Translate转移到原点
  2. 作旋转
  3. 使用Translate的逆矩阵将其转移回去

T(c)R(α)T(c)T(c) \cdot R(\alpha) \cdot T(-c)

2 3D线性变换

2.1 3维缩放,切变和旋转

缩放还是和2D一个套路

[Sx000Sy000Sz]\begin{bmatrix} S_x & 0 & 0 \\ 0 & S_y & 0 \\ 0 & 0 & S_z \end{bmatrix}

切变也一样

[1dydz010001](Shear-x(dydz) Matrix)\begin{bmatrix} 1 & d_y & d_z \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \tag{Shear-x($d_y d_z$) Matrix}

再来到三维的旋转,有三个矩阵,分别对应绕x轴,y轴和z轴旋转,注意是右手系,绕z轴(x轴转向y轴),绕x轴(y轴转向z轴),绕y轴(z轴转向x轴)

[cosθsinθ0sinθcosθ0001](rotate-z(θ))\begin{bmatrix} cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \tag{rotate-z($\theta$)}

[1000cosθsinθ0sinθcosθ](rotate-x(θ))\begin{bmatrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{bmatrix} \tag{rotate-x($\theta$)}

[cosθ0sinθ010sinθ0cosθ](rotate-y(θ))\begin{bmatrix} cos\theta & 0 & sin\theta \\ 0 & 1 & 0 \\ -sin\theta & 0 & cos\theta \end{bmatrix} \tag{rotate-y($\theta$)}

由此可知,所有的旋转矩阵都是正交矩阵,即它们的逆矩阵也就是它们的转置矩阵

注意,我们此处的绕y旋转的旋转矩阵为什么是负号在左下角呢,用叉乘的性质就可以解释,比如x×y=zx \times y = zy×z=xy \times z = xz×x=yz \times x = y,我们不难看出,像是一个xyzxyz的循环,但是我们计算的时候都是先算xx坐标再算zz坐标,与叉乘的顺序相反了,所以是反的

3 仿射变换

最后只剩了一个位移,为了使位移的表示统一且方便,我们引入了齐次坐标,例如三维的齐次坐标矩阵为四维:

[xyz1]T(point)\begin{bmatrix} x & y & z & 1 \end{bmatrix} T \tag{point}

[xyz0]T(vector)\begin{bmatrix} x & y & z & 0 \end{bmatrix} T \tag{vector}

对vector的位移是毫无意义的,方向始终不会变

3.1 位移(translation)

对一个三维的点作位移变换:

[xyz1]=[100xt010yt001zt0001][xyz1]\begin{bmatrix} x^{'} \\ y^{'} \\ z^{'} \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & x_t \\ 0 & 1 & 0 & y_t \\ 0 & 0 & 1 & z_t \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}


参考文档:https://blog.csdn.net/qq_38065509/article/details/105156501