关于齐次坐标以及绕坐标轴的旋转,需要提前了解,参考本博客的文章:【数学】齐次坐标、三维点/向量的平移、缩放、旋转
下面来推导绕任意轴 (与轴的长度无关,则可以在计算前进行单位化为单位向量,也即 )旋转 角度的公式
![](https://img-blog.csdnimg.cn/20210113174000511.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZyZWVTb3V0aFM=,size_16,color_FFFFFF,t_70)
首先我们将 看待为其由 轴,绕y轴旋转了 ,又绕 轴旋转了 (逆时针是正,顺时针是负)。如果我们要求一个向量绕 旋转 的公式,我们可以先执行将 旋转到 轴的变换 ,而后执行绕 轴旋转 ,之后再执行 将 轴再移回 。由于有点绕,我们再分步骤详述一下:
将旋转轴 绕 轴旋转 转至 平面将步骤1的成果绕 轴旋转 转至与 轴重合绕 轴旋转 执行步骤2的逆过程执行步骤1的逆过程
![](https://img-blog.csdnimg.cn/20210114143406699.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0ZyZWVTb3V0aFM=,size_16,color_FFFFFF,t_70)
【步骤1】
现在我们来将 执行第一个步骤,其旋转为绕 轴的普通旋转,其角度为 ,旋转后形成向量 在 平面上,这个 就等于上图中将 投影到 平面上形成向量 , 与 轴的夹角:
我们首先来看绕 轴旋转矩阵(参考:【数学】齐次坐标、三维点/向量的平移、缩放、旋转):
![\begin{pmatrix} 1 & 0 & 0 & 0\\ 0&cos\beta & -sin\beta & 0 \\ 0&sin\beta & cos\beta & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%201%20%26%200%20%26%200%20%26%200%5C%5C%200%26cos%5Cbeta%20%26%20-sin%5Cbeta%20%26%200%20%5C%5C%200%26sin%5Cbeta%20%26%20cos%5Cbeta%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
要将上述矩阵为已知值 相关,则需要求出向量 的长度,其长度由 则长度为 ,
其中 , 则绕 轴的旋转矩阵记为 :
![\begin{pmatrix} 1 & 0 & 0 & 0\\ 0&c/\sqrt{b^2+c^2} & -b/\sqrt{b^2+c^2} & 0 \\ 0&b/\sqrt{b^2+c^2} & c/\sqrt{b^2+c^2} & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%201%20%26%200%20%26%200%20%26%200%5C%5C%200%26c/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%20-b/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%26b/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%20c/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
【步骤2】
我们首先来求向量 的值,因为其是由 绕 轴旋转而来,因此其 不会变化为 ,又因为旋转到了 平面上,因此其 值为0,而旋转不会导致长度发生变化为单位向量,则易求得其 分量为 ,则
![w=(a,0,\sqrt{b^2+c^2})](https://private.codecogs.com/gif.latex?w%3D%28a%2C0%2C%5Csqrt%7Bb%5E2+c%5E2%7D%29)
然后将步骤1的成果也就是向量 ,再绕 旋转个 (顺时针为负)即可。我们首先来看绕 轴旋转矩阵(参考:【数学】齐次坐标、三维点/向量的平移、缩放、旋转):
![\begin{pmatrix} cos(-\alpha) &0& sin(-\alpha) & 0 \\ 0 & 1 & 0 & 0\\ \\ -sin(-\alpha) & 0&cos(-\alpha) & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%20cos%28-%5Calpha%29%20%260%26%20sin%28-%5Calpha%29%20%26%200%20%5C%5C%200%20%26%201%20%26%200%20%26%200%5C%5C%20%5C%5C%20-sin%28-%5Calpha%29%20%26%200%26cos%28-%5Calpha%29%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
其中 ,![cos\alpha=\sqrt{b^2+c^2}](https://private.codecogs.com/gif.latex?cos%5Calpha%3D%5Csqrt%7Bb%5E2+c%5E2%7D)
则绕 旋转的矩阵记为 :
![\begin{pmatrix} \sqrt{b^2+c^2} &0& -a & 0 \\ 0 & 1 & 0 & 0\\ \\ a & 0&\sqrt{b^2+c^2} & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%20%5Csqrt%7Bb%5E2+c%5E2%7D%20%260%26%20-a%20%26%200%20%5C%5C%200%20%26%201%20%26%200%20%26%200%5C%5C%20%5C%5C%20a%20%26%200%26%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
完成【步骤1】和【步骤2】以后,则向量 与 轴完全重合执行步骤3
【步骤3】绕 轴旋转 ,则绕 轴旋转矩阵(参考:【数学】齐次坐标、三维点/向量的平移、缩放、旋转)记为 :
![\begin{pmatrix} cos\theta & -sin\theta & 0 & 0\\ sin\theta & cos\theta & 0 &0 \\ 0 & 0 & 1 & 0\\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%20cos%5Ctheta%20%26%20-sin%5Ctheta%20%26%200%20%26%200%5C%5C%20sin%5Ctheta%20%26%20cos%5Ctheta%20%26%200%20%260%20%5C%5C%200%20%26%200%20%26%201%20%26%200%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
【步骤4】
因为旋转矩阵是正交矩阵,其逆矩阵与其转轶矩阵相等,因此【步骤4】只需要将【步骤2】转轶即可,得到 :
![\begin{pmatrix} \sqrt{b^2+c^2} &0& a & 0 \\ 0 & 1 & 0 & 0\\ \\ -a & 0&\sqrt{b^2+c^2} & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%20%5Csqrt%7Bb%5E2+c%5E2%7D%20%260%26%20a%20%26%200%20%5C%5C%200%20%26%201%20%26%200%20%26%200%5C%5C%20%5C%5C%20-a%20%26%200%26%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
【步骤5】
同理是【步骤1】的转轶, :
![\begin{pmatrix} 1 & 0 & 0 & 0\\ 0&c/\sqrt{b^2+c^2} & b/\sqrt{b^2+c^2} & 0 \\ 0&-b/\sqrt{b^2+c^2} & c/\sqrt{b^2+c^2} & 0 \\ 0 & 0 &0 &1 \end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%201%20%26%200%20%26%200%20%26%200%5C%5C%200%26c/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%20b/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%26-b/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%20c/%5Csqrt%7Bb%5E2+c%5E2%7D%20%26%200%20%5C%5C%200%20%26%200%20%260%20%261%20%5Cend%7Bpmatrix%7D)
【最终】
我们得到绕任意单位向量 旋转的结果为 :
,最终结果为:
![\begin{pmatrix}(b^2+c^2)cos\theta+a^2 & ab(1-cos\theta)-csin\theta & ac(1-cos\theta)+bsin\theta &0 \\ ab(1-cos\theta)+csin\theta & b^2+(1-b^2)cos\theta & bc(1-cos\theta)-asin\theta& 0\\ ac(1-cos\theta)-bsin\theta & bc(1-cos\theta)+asin\theta & c^2+(1-c^2)cos\theta &0 \\ 0 & 0& 0& 1\end{pmatrix}](https://private.codecogs.com/gif.latex?%5Cbegin%7Bpmatrix%7D%28b%5E2+c%5E2%29cos%5Ctheta+a%5E2%20%26%20ab%281-cos%5Ctheta%29-csin%5Ctheta%20%26%20ac%281-cos%5Ctheta%29+bsin%5Ctheta%20%260%20%5C%5C%20ab%281-cos%5Ctheta%29+csin%5Ctheta%20%26%20b%5E2+%281-b%5E2%29cos%5Ctheta%20%26%20bc%281-cos%5Ctheta%29-asin%5Ctheta%26%200%5C%5C%20ac%281-cos%5Ctheta%29-bsin%5Ctheta%20%26%20bc%281-cos%5Ctheta%29+asin%5Ctheta%20%26%20c%5E2+%281-c%5E2%29cos%5Ctheta%20%260%20%5C%5C%200%20%26%200%26%200%26%201%5Cend%7Bpmatrix%7D)
|