# 四元数的理解与应用

Last updated on：2 months ago

# 定义

$$q = a + b\mathbf{i} + c\mathbf{j} + d\mathbf{k}, a,b,c,d \in R$$

$$\mathbf{i}^2 = \mathbf{j}^2 = \mathbf{k}^2 = -1$$

$$\mathbf{i}\mathbf{j} = -\mathbf{j}\mathbf{i} = \mathbf{k}, \mathbf{j}\mathbf{k} = -\mathbf{k}\mathbf{j} = \mathbf{i}, \mathbf{k}\mathbf{i} = -\mathbf{k}\mathbf{i} = \mathbf{j}$$

$$Q = {a + b\mathbf{i} + c\mathbf{j} + d\mathbf{k} | a,b,c,d \in R}$$

## 特性

• 四元数相加：

$$(a_{1}+b_{1},\mathbf {i} +c_{1},\mathbf {j} +d_{1},\mathbf {k} )+(a_{2}+b_{2},\mathbf {i} +c_{2},\mathbf {j} +d_{2},\mathbf {k} )=(a_{1}+a_{2})+(b_{1}+b_{2}),\mathbf {i} +(c_{1}+c_{2}),\mathbf {j} +(d_{1}+d_{2}),\mathbf {k}$$

• 乘以一个系数：

$$\lambda (a+b,\mathbf {i} +c,\mathbf {j} +d,\mathbf {k} )=\lambda a+(\lambda b),\mathbf {i} +(\lambda c),\mathbf {j} +(\lambda d),\mathbf {k}$$

• 倒数：

$$(a+b,\mathbf {i} +c,\mathbf {j} +d,\mathbf {k} )^{-1}={\frac {1}{a{2}+b{2}+c{2}+d{2}}},(a-b,\mathbf {i} -c,\mathbf {j} -d,\mathbf {k} )$$

• 方向向量为单位向量，两两正交。
• 两个四元数的乘积（哈密尔顿乘积 Hamilton product）:

$$q_1 q_2 = ( a 1 + b 1\mathbf{i} + c 1\mathbf{j} + d 1\mathbf{k}) ( a 2 + b 2\mathbf{i} + c 2\mathbf{j} + d 2\mathbf{k})$$

= \begin{aligned}{4}&a_{1}a_{2}&&+a_{1}b_{2}\mathbf {i} &&+a_{1}c_{2}\mathbf {j} &&+a_{1}d_{2}\mathbf {k} \{}+{}&b_{1}a_{2}\mathbf {i} &&+b_{1}b_{2}\mathbf {i} ^{2}&&+b_{1}c_{2}\mathbf {ij} &&+b_{1}d_{2}\mathbf {ik} \{}+{}&c_{1}a_{2}\mathbf {j} &&+c_{1}b_{2}\mathbf {ji} &&+c_{1}c_{2}\mathbf {j} ^{2}&&+c_{1}d_{2}\mathbf {jk} \{}+{}&d_{1}a_{2}\mathbf {k} &&+d_{1}b_{2}\mathbf {ki} &&+d_{1}c_{2}\mathbf {kj} &&+d_{1}d_{2}\mathbf {k} ^{2}\end{aligned}

= \begin{aligned}{4}&a_{1}a_{2}&&-b_{1}b_{2}&&-c_{1}c_{2}&&-d_{1}d_{2}\{}+{}(&a_{1}b_{2}&&+b_{1}a_{2}&&+c_{1}d_{2}&&-d_{1}c_{2})\mathbf {i} \{}+{}(&a_{1}c_{2}&&-b_{1}d_{2}&&+c_{1}a_{2}&&+d_{1}b_{2})\mathbf {j} \{}+{}(&a_{1}d_{2}&&+b_{1}c_{2}&&-c_{1}b_{2}&&+d_{1}a_{2})\mathbf {k} \end{aligned}

$$q_1 q_2 = -(q_1 \dot q_2) + (q_1 \times q_2)$$

• 绝对值：

$$|q| = \sqrt {qq^{}} = \sqrt {q^ q} = \sqrt {a{2}+b{2}+c{2}+d{2}}$$

• 共轭：

$$q^* = a - b\mathbf{i} - c\mathbf{j} - d\mathbf{k}$$

# 应用

## 刚体位姿描述

$$\mathbf{Q} =\eta + \varepsilon_x \mathbf{i} + \varepsilon_y \mathbf{j} + \varepsilon_z \mathbf{k} = [\eta , \mathbf{\varepsilon}]= [\eta\ \varepsilon_x\ \varepsilon_y\ \varepsilon_z]^T$$

## RGB坐标系

$$\mathbf{p} = \mathbf{\omega}\mathbf{q}\mathbf{\omega} ^*$$

$$\mathbf{\omega} = cos\frac{\theta}{2} + sin\frac{\theta}{2}(\omega_1 \mathbf{i} + omega_2 \mathbf{j} + omega_3 \mathbf{k})$$

# 参考资料

[1] Quaternion

[2] 李文亮，四元数矩阵，国防科技大学出版社

[3] Pervin, E. and Webb, J.A., 1982. Quaternions in computer vision and robotics. CARNEGIE-MELLON UNIV PITTSBURGH PA DEPT OF COMPUTER SCIENCE.

[4] Zhu, X., Xu, Y., Xu, H. and Chen, C., 2018. Quaternion convolutional neural networks. In Proceedings of the European Conference on Computer Vision (ECCV) (pp. 631-647).