3D数学基础·图形和游戏开发:矩阵和线性变换
二维中的旋转

围绕原点的两个基矢量的旋转可以简单的表示为如上所示,由此我们即可构造出如下二维旋转矩阵
\[\color{black}{ R(\theta)=\left[\begin{array}{l}
p^{\prime} \\
q^{\prime}
\end{array}\right]=\left[\begin{array}{cc}
\cos \theta & \sin \theta \\
-\sin \theta & \cos \theta
\end{array}\right] }
\]
三维中的旋转
围绕x轴的旋转
\[\color{black}{
R_{x}(\theta)=\left[\begin{array}{l}
p_{1}^{\prime} \\
q_{1}^{\prime} \\
r_{1}^{\prime}
\end{array}\right]=\left[\begin{array}{ccc}
1 & 0 & 0 \\
0 & \cos \theta & \sin \theta \\
0 & -\sin \theta & \cos \theta
\end{array}\right]
}
\]
围绕y轴旋转
\[\color{black}{
R_{y}(\theta)=\left[\begin{array}{c}
p_{1}^{\prime} \\
q_{1}^{\prime} \\
r_{1}^{\prime}
\end{array}\right]=\left[\begin{array}{ccc}
\cos \theta & 0 & -\sin \theta \\
0 & 1 & 0 \\
\operatorname{cin} \theta & \theta & \cos \theta
\end{array}\right]
}
\]
围绕任意轴的三维旋转
这里有一个小技巧,我们把矢量v分解为平行于轴n和垂直于其的两个矢量,故得到
\[\color{black}{
v=v_{||}+v_{\perp}
}
\]
这里我们设n为单位矢量,那么v平行于n的分向量便可以得到如下所示的式子
\[\color{black}{
v_{||}=(v \cdot \hat{n}) \hat{n}
}
\]
上式的一种理解是v的评选分量相当于v投影到n上的值,故而结合点积的定义可以得到上式
v的垂直部分可以通过v减去其平行部分得到
我们假设矢量w是与v的两个分矢量构成的平面垂直的,并且长度与v的垂直分矢量相当,那么结合叉积的定义很容易便可以得到如下所示的式子
\[\color{black}{
w=\hat{n} \times v_{\perp}
}
\]

上图大致表示了上面口胡的这么几个矢量之间的关系,v’表示绕n旋转后的v
v垂直分量的旋转事实上就是在w和其本身构成的平面上旋转,也就是在垂直于n的平面上旋转,这么一来我们便可以计算v垂直分量旋转后的状态
\[\color{black}{
v_{\perp}^{\prime}=\cos \theta v_{\perp}+\sin \theta w
}
\]
代入上面的一些式子,稍微展开一些得到
\[\color{black}{
v_{\perp}^{\prime}=\cos \theta(v-(v \cdot \hat{n}), \hat{n})+\sin (n \times b)
}
\]
最后代入v’即可得到
\[\color{black}{
\begin{aligned}
v^{\prime} &=v_{\perp}^{\prime}+v_{||}^{\prime} \\
&=\cos \theta(v-(v \cdot \hat{n}) \hat{n})+\sin \theta(\hat{n} \times v)+(v \cdot \hat{n})\hat{n}
\end{aligned}
}
\]
上式事实上允许绕任意轴旋转任意矢量,最后我们将其表示为旋转矩阵的形式
\[\color{black}{
\begin{array}{l}
p=\left[\begin{array}{lll}
1 & 0 & 0
\end{array}\right] \\
q=\left[\begin{array}{lll}
0 & 1 & 0
\end{array}\right] \\
r=\left[\begin{array}{lll}
0 & 0 & 1
\end{array}\right]
\end{array}
}
\] \[
\color{black}{
p^{\prime}=\left[\begin{array}{c}
n_{x}^{2}(1-\cos \theta)+\cos \theta \\
n_{x} n_{y}(1-\cos \theta)+n_{z} \sin \theta \\
n_{x} n_{z}(1-\cos \theta)-n_{y} \sin \theta
\end{array}\right]^{T}
}
\] \[
\color{black}{
q^{\prime}=\left[\begin{array}{c}
n_{x} n_{y}(1-\cos \theta)- n_{z} \sin \theta \\
n_{y}^{2}(1-\cos \theta)+\cos \theta \\
n_{y} n_{z}(1-\cos \theta)+n_{x} \sin \theta
\end{array}\right]^{T}
}
\] \[
\color{black}{
r^{\prime}=\left[\begin{array}{c}
n_{x} n_{z}(1-\cos \theta)+ n_{y} \sin \theta \\
n_{y} n_{z}(1-\cos \theta)- n_{x} \sin \theta \\
n_{z}^{2}(1-\cos \theta)+\cos \theta
\end{array}\right]^{T}
}
\] \[
\color{black}{
R(\hat{n}, \theta)=\left[\begin{array}{l}
p^{\prime} \\
q^{\prime} \\
r^{\prime}
\end{array}\right]
}
\]
绕任意轴旋转的核心其实就是将要被旋转的矢量按照基矢量去拆分,每一个复杂的旋转都可以视作分别绕三个基矢量(也就是旋转矩阵里的行矢量)的状态的叠加。
其实推导到这里,像是任意方向的放缩啊还有投影到任意线或平面上都可以做类似的推导,本质都是将高维的矢量拆成多个基矢量方向的矢量于垂直与基矢量的矢量,对于拆出来的基矢量方向的分矢量再对复杂的操作单位化原子化再进行叠加。
其实其实,我觉得最核心的不是上面这些推导,最重要的是要理解点积(算投影)和叉积(算垂直于两个矢量构成的平面的矢量)在多维空间中所表示的实际意义
发表评论