数学部分(三、各种变换矩阵)
1、基本变换
- 旋转: [ c o s θ − s i n θ s i n θ c o s θ ] \begin{bmatrix}cos\theta &-sin\theta \\sin\theta &cos\theta \end{bmatrix} [cosθsinθ−sinθcosθ]
- 缩放: [ k x 0 0 k y ] \begin{bmatrix}k_x&0\\0 &k_y\end{bmatrix} [kx00ky]
- 剪影(shear): [ 1 a 0 1 ] [ x y ] \begin{bmatrix}1&a\\0 &1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix} [10a1][xy]
- 平移: [ 1 0 t x 0 1 t y 0 0 1 ] \begin{bmatrix}1 &0 &t_x \\ 0& 1& t_y\\ 0 & 0&1\end{bmatrix} ⎣⎡100010txty1⎦⎤
- 投影:
- 镜像
- 仿射:
2、补充说明
按x轴旋转: [ 1 0 0 0 c o s θ − s i n θ 0 s i n θ c o s θ ] \begin{bmatrix}1 &0 &0\\0 &cos\theta &-sin\theta \\0 &sin\theta &cos\theta \end{bmatrix} ⎣⎡1000cosθsinθ0−sinθcosθ⎦⎤
按y轴旋转: [ c o s θ 0 s i n θ 0 1 0 − s i n θ 0 c o s θ ] \begin{bmatrix}cos\theta &0 &sin\theta\\0 &1 &0 \\ -sin\theta &0&cos\theta \end{bmatrix} ⎣⎡cosθ0−sinθ010sinθ0cosθ⎦⎤
按z轴旋转: [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0 0 1 ] \begin{bmatrix}cos\theta &-sin\theta &0\\sin\theta &cos\theta &0 \\ 0&0&1\end{bmatrix} ⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤
另外,额外考虑会有万向轴锁死的情况,即:某两个轴重叠的时候,就会只剩两个轴的方向可以转动了,剩下的就不能转动了。
《3D数学基础 图形与游戏开发》这本书的第8章中也有记录按照 任意向量进行旋转 和 按照任意向量缩放的 的公式,但是这里就不记录了,推导复杂而且结果也很复杂啊。
补充:《Games101》Lecture04:2D情况下旋转
−
θ
-\theta
−θ 角的情况:
R
θ
=
[
c
o
s
θ
−
s
i
n
θ
s
i
n
θ
c
o
s
θ
]
R
−
θ
=
[
c
o
s
θ
s
i
n
θ
−
s
i
n
θ
c
o
s
θ
]
=
R
θ
T
R
−
θ
=
R
θ
−
1
R_{\theta}=\begin{bmatrix}cos\theta &-sin\theta \\sin\theta &cos\theta \end{bmatrix}\\ R_{-\theta}=\begin{bmatrix}cos\theta &sin\theta \\-sin\theta &cos\theta \end{bmatrix}=R_{\theta}^T\\ R_{-\theta}=R_{\theta}^{-1}
Rθ=[cosθsinθ−sinθcosθ]R−θ=[cosθ−sinθsinθcosθ]=RθTR−θ=Rθ−1
3、行列式的计算
4、矩阵的逆
5、正交矩阵
另一个特殊的方阵是正交矩阵(orthogonal matrix)。正交是矩阵的一种属性。如果一个方阵M和它的转置矩阵的乘积是单位矩阵的话,我们就说这个矩阵是正交的(orthogonal)。反过来也是成立的。也就是说,矩阵M是正交的等价于:
M
M
T
=
M
T
M
=
I
MM^T=M^TM=I
MMT=MTM=I