(二)四元数公式总结 |
您所在的位置:网站首页 › m与n的差乘四 › (二)四元数公式总结 |
在这里插入图片描述 Q = \langle x, y, z, w \rangle Q = xi + yj + zk + w 1.运算与性质1)数乘Q = s \cdot \langle x, y, z, w \rangle = \langle s \cdot z, s \cdot y, s \cdot z, s \cdot w \rangle \frac{Q}{s} = \left( \frac{x}{s}, \frac{y}{s}, \frac{z}{s}, \frac{w}{s} \right) 2)四元数加减法(Add,Substract)Q = \langle x_1 + x_2, y_1 + y_2, z_1 + z_2, w_1 + w_2 \rangle Q = \langle x_1 - x_2, y_1 - y_2, z_1 - z_2, w_1 - w_2 \rangle 3) 模运算(Norm)\|Q\| = \sqrt{x^2 + y^2 + z^2 + w^2} 4)标准化(Normalize)Q_{\text{normalized}} = \frac{Q}{\|Q\|} = \frac{\langle x, y, z, w \rangle}{\sqrt{x^2 + y^2 + z^2 + w^2}} 5)共轭(Conjugate)Q^* = \langle -x, -y, -z, w \rangle 6)逆元 (Reverse)Q^{-1} = \frac{Q^*}{\|Q\|^2} 7)四元数乘法(Mutiply)\begin{align*} Q_1 * Q_2 = \left( w_1w_2 - x_1x_2 - y_1y_2 - z_1z_2, \right. \\ \left. w_1x_2 + x_1w_2 + y_1z_2 - z_1y_2, \right. \\ \left. w_1y_2 - x_1z_2 + y_1w_2 + z_1x_2, \right. \\ \left. w_1z_2 + x_1y_2 - y_1x_2 + z_1w_2 \right) \end{align*} 注意:在下文我们使用 · (点) 来表示点乘或者数乘,使用 * (星)表示四元数乘法 7)欧拉角构造四元数在欧拉角的值为角度时 \begin{align*} \text{Yaw (}\psi\text{)} &\rightarrow \psi \\ \text{Pitch (}\theta\text{)} &\rightarrow \theta \\ \text{Roll (}\phi\text{)} &\rightarrow \phi \\ \end{align*} 在值为弧度时 \begin{align*} \text{Yaw (}\psi\text{)} &\rightarrow \frac{\text{Yaw (}\psi\text{)} \cdot \pi}{180} \\ \text{Pitch (}\theta\text{)} &\rightarrow \frac{\text{Pitch (}\theta\text{)} \cdot \pi}{180} \\ \text{Roll (}\phi\text{)} &\rightarrow \frac{\text{Roll (}\phi\text{)} \cdot \pi}{180} \\ \end{align*} 变化后,求得四元数的四个分量 \begin{align*} x &= \sin\left(\frac{\psi}{2}\right) \cdot \cos\left(\frac{\theta}{2}\right) \cdot \cos\left(\frac{\phi}{2}\right) - \cos\left(\frac{\psi}{2}\right) \cdot \sin\left(\frac{\theta}{2}\right) \cdot \sin\left(\frac{\phi}{2}\right) \\ y &= \cos\left(\frac{\psi}{2}\right) \cdot \sin\left(\frac{\theta}{2}\right) \cdot \cos\left(\frac{\phi}{2}\right) + \sin\left(\frac{\psi}{2}\right) \cdot \cos\left(\frac{\theta}{2}\right) \cdot \sin\left(\frac{\phi}{2}\right) \\ z &= \cos\left(\frac{\psi}{2}\right) \cdot \cos\left(\frac{\theta}{2}\right) \cdot \sin\left(\frac{\phi}{2}\right) - \sin\left(\frac{\psi}{2}\right) \cdot \sin\left(\frac{\theta}{2}\right) \cdot \cos\left(\frac{\phi}{2}\right) \\ w &= \cos\left(\frac{\psi}{2}\right) \cdot \cos\left(\frac{\theta}{2}\right) \cdot \cos\left(\frac{\phi}{2}\right) + \sin\left(\frac{\psi}{2}\right) \cdot \sin\left(\frac{\theta}{2}\right) \cdot \sin\left(\frac{\phi}{2}\right) \\ \end{align*} 如果需要对某个轴旋转特定角度 Q = \left(\sin\left(\frac{\theta}{2}\right) \cdot a, \sin\left(\frac{\theta}{2}\right) \cdot b, \sin\left(\frac{\theta}{2}\right) \cdot c, \cos\left(\frac{\theta}{2}\right)\right) 8)四元数转欧拉角\begin{align*} \text{Yaw (}\psi\text{)} &\rightarrow \arctan2(2 \cdot (x \cdot y + z \cdot w), 1 - 2 \cdot (y^2 + z^2)) \\ \text{Pitch (}\theta\text{)} &\rightarrow \arcsin(2 \cdot (x \cdot z - w \cdot y)) \\ \text{Roll (}\phi\text{)} &\rightarrow \arctan2(2 \cdot (y \cdot z + x \cdot w), 1 - 2 \cdot (z^2 + y^2)) \end{align*} (注意:arctan2是一个被多种编程语言支持的反正切函数) 9)四元数点乘Q_1 \cdot Q_2 = x_1 \cdot x_2 + y_1 \cdot y_2 + z_1 \cdot z_2 + w_1 \cdot w_2 我们可以通过这样的方式计算出两个四元数的夹角 \theta = \arccos(Q_1 \cdot Q_2) 当点积为0时,表明两个四元数正交 Q_1 \cdot Q_2 = 0 当四元数保持单位模时,表明为单位四元数 Q \cdot Q = 1 10)四元数普通线性插值Lerp的公式如下 Q_{\text{lerp}} = (1 - t) \cdot Q_1 + t \cdot Q_2 这个插值被称为NLerp,也就是先进行线性插值,再进行标准化 Q_{\text{nlerp}} = \frac{(1 - t) \cdot Q_1 + t \cdot Q_2}{\| (1 - t) \cdot Q_1 + t \cdot Q_2 \|} 注意:此处的“点”均为“数乘”或“四元数点乘” 11) 四元数球面线性插值\alpha = \cos^{-1}(Q_1 \cdot Q_2) Q_{\text{slerp}} = = \frac{\sin((1 - t) \cdot \alpha)}{\sin(\alpha)} \cdot Q_1 + \frac{\sin(t \cdot \alpha)}{\sin(\alpha)} \cdot Q_2 注意:此处的“点”均为“数乘”或“四元数点乘” 12) 四元数转旋转矩阵仿射变换旋转矩阵: R = \begin{bmatrix} 1 - 2y^2 - 2z^2 & 2xy - 2wz & 2xz + 2wy \\ 2xy + 2wz & 1 - 2x^2 - 2z^2 & 2yz - 2wx \\ 2xz - 2wy & 2yz + 2wx & 1 - 2x^2 - 2y^2 \end{bmatrix} 齐次坐标旋转矩阵: T = \begin{bmatrix} 1 - 2y^2 - 2z^2 & 2xy - 2wz & 2xz + 2wy & 0 \\ 2xy + 2wz & 1 - 2x^2 - 2z^2 & 2yz - 2wx & 0 \\ 2xz - 2wy & 2yz + 2wx & 1 - 2x^2 - 2y^2 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} 12)旋转矩阵转四元数对于以下仿射变换旋转矩阵 R = \begin{bmatrix} R_{11} & R_{12} & R_{13} \\ R_{21} & R_{22} & R_{23} \\ R_{31} & R_{32} & R_{33} \end{bmatrix} 或在齐次坐标下的旋转矩阵 T = \begin{bmatrix} R_{11} & R_{12} & R_{13} & 0 \\ R_{21} & R_{22} & R_{23} & 0 \\ R_{31} & R_{32} & R_{33} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} 都可以按以下方式获取四元数的四个部分 Q = \begin{cases} w = \sqrt{1 + R_{11} + R_{22} + R_{33}} \\ x = \frac{R_{32} - R_{23}}{4w} \\ y = \frac{R_{13} - R_{31}}{4w} \\ z = \frac{R_{21} - R_{12}}{4w} \end{cases} 12)四元数叉乘一般来讲四元数叉乘并没有意义,只是在某些特定的算法或情景中定义的全新的运算法则,而不具备广泛的实用性。可以根据需求调整叉乘的定义,这里不再给出相关信息。 2.运算律与定义1).单位元(Identity)规定单位元为 Q_{identity} = \langle 0, 0, 0, 1 \rangle 2).单位四元数规定模长(Norm)为1为单位四元数 3).逆元每个非零四元数都有一个逆元,相乘结果为单位元,注意前置条件 Q \cdot Q^{-1}= Q_{identity} 4).结合律(Q_1 \cdot Q_2) \cdot Q_3 = Q_1 \cdot (Q_2 \cdot Q_3) 5).乘法交换率不成立Q_1 \cdot Q_2 \neq Q_2 \cdot Q_1 6).乘法封闭性四元数乘法是封闭的,也就是说,两个四元数的乘积仍然是四元数。 7).无万向节锁问题"万向锁问题"是指在使用欧拉角来描述旋转时,存在一个特定情况,其中三个旋转轴的旋转角度不能独立地表示物体的方向,因为它们会相互影响。这会导致旋转的奇异性,使得无法准确描述物体的姿态。 四元数和旋转矩阵均无万向锁问题,但是矩阵需要占据很大的运算空间,有高昂的代价,而四元数解决这一问题的代价是升维,使得旋转失去了直观性和简单性。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |