Quaternions and Rotation 四元数和旋转

从二维复数旋转推导到三维 Rodrigues 旋转公式,并解释四元数旋转的完整形式。

Quaternions and Rotation 四元数和旋转

上一章我们介绍了 四元数,可以认为它是一种 高维复数,让我们先把视角放回 二维复数,看看它与旋转有何关联

复数是形如

a+bia + b\mathbf{i}

的数,其中

  • i2=−1\mathbf{i}^2 = -1 是虚数单位

aa 是 实部,bb 为 虚部,可以记作 (a,b)(a,b) 这样的实数对,也可以看作 二维笛卡尔坐标系 中的一个 向量 (yy 轴为虚部轴)

可以直观的推导 复数乘法

(x1+y1i)(x2+y2i)=x1x2+x1y2i+x2y1i+y1y2i2=x1x2−y1y2+(x1y2+x2y1)i\begin{align*} (x_1 + y_1\mathbf{i})(x_2 + y_2\mathbf{i}) &= x_1x_2 + x_1y_2\mathbf{i} + x_2y_1\mathbf{i} + y_1y_2\mathbf{i}^2 \\ &= x_1x_2 - y_1y_2 + (x_1y_2 + x_2y_1)\mathbf{i} \end{align*}

即

(x1,y1)(x2,y2)=(x1x2−y1y2,  x1y2+x2y1)(x_1,y_1)(x_2,y_2) = (x_1x_2 - y_1y_2,\ \ x_1y_2 + x_2y_1)

若将 虚轴 作为 yy 轴,则复数 v=(a,b)v = (a,b) 也可以作为向量表示在如下的二维笛卡尔坐标系中

Complex number z equals a plus bi shown as a vector on the complex plane with real and imaginary projections.
复数 z = a + bi 同时可以看成复平面上的点和从原点出发的向量;a、b 分别对应实轴和虚轴分量。

其中 vv 可以分解为在基 xx 和 yy 上的分量

{vx=(a,0)vy=(0,b)  ⟹  v=vx+vy\begin{cases} v_x = (a,0) \\ v_y = (0,b) \end{cases} \implies v = v_x + v_y

随后,考虑将 vv 旋转 θ∘\theta^\circ 得到 v′v',其相应分量 vxv_x 和 vyv_y 也随之旋转 θ∘\theta^\circ 得到 vx′v'_x 和 vy′v'_y

Complex multiplication as rotation, comparing multiplication by i with multiplication by e to the i theta.
乘以 得到 90 度旋转;乘以 则在保持长度的同时增加 角。
∵v=vx+vy且旋转是一个线性变换∴v′=vx′+vy′\because v = v_x + v_y \quad \text{且旋转是一个线性变换} \\ \therefore v' = v'_x + v'_y

根据三角函数,易得

v′=vx′+vy′=(a,0)′+(0,b)′=(acos⁡θ,  asin⁡θ)+(−bsin⁡θ,  bcos⁡θ)=(acos⁡θ−bsin⁡θ,  asin⁡θ+bcos⁡θ)\begin{align*} v' &= v'_x + v'_y \\ &= (a, 0)' + (0,b)' \\ &= (a\cos{\theta}, \ \ a\sin{\theta}) + (-b\sin{\theta}, \ \ b\cos{\theta}) \\ &= (a\cos{\theta} - b\sin{\theta},\ \ a\sin{\theta} + b\cos{\theta}) \end{align*}

我们前面推导出

(x1,y1)(x2,y2)=(x1x2−y1y2,  x1y2+x2y1)(x_1,y_1)(x_2,y_2) = (x_1x_2 - y_1y_2,\ \ x_1y_2 + x_2y_1)

可以设

{x1=ay1=b,{x2=cos⁡θy2=sin⁡θ\begin{cases} x_1 = a \\ y_1 = b \end{cases}, \quad \begin{cases} x_2 = \cos{\theta} \\ y_2 = \sin{\theta} \end{cases}

那么我们有

v′=(x1cos⁡θ−y1sin⁡θ,  x1sin⁡θ+y1cos⁡θ)=(x1,y1)(cos⁡θ,sin⁡θ)=(x1+y1i)(cos⁡θ+sin⁡θi)\begin{align*} v' = (x_1\cos{\theta} - y_1\sin{\theta},\ \ x_1\sin{\theta} + y_1\cos{\theta}) &= (x_1,y_1)(\cos{\theta},\sin{\theta}) \\ &= (x_1 + y_1\mathbf{i})(\cos{\theta} + \sin{\theta}\mathbf{i}) \end{align*}

根据 欧拉公式

eiθ=cos⁡θ+sin⁡θie^{\mathbf{i}\theta} = \cos{\theta} + \sin{\theta}\mathbf{i}

所以我们有

v′=(x1+y1i)(cos⁡θ+sin⁡θi)=eiθ(x1+y1i)v' = (x_1 + y_1\mathbf{i})(\cos{\theta} + \sin{\theta}\mathbf{i}) = e^{\mathbf{i}\theta}(x_1 + y_1\mathbf{i})

即,对于 v=x1+y1iv = x_1 + y_1\mathbf{i},其 逆时针 旋转 θ∘\theta^\circ 的结果为

v′=eiθv=(cos⁡θ+sin⁡θi)(x1+y1i)v' = e^{\mathbf{i}\theta}v = (\cos{\theta} + \sin{\theta}\mathbf{i})(x_1 + y_1\mathbf{i})

也就是说:复数的相乘实际上蕴涵了二维旋转,可以认为 纯旋转 (无缩放) 一个 复数 θ∘\theta^\circ 就是乘以 实部 为 cos⁡θ\cos{\theta} 而 虚部 为 sin⁡θ\sin{\theta} 的 复数

cos⁡θ+sin⁡θi\cos{\theta} + \sin{\theta}\mathbf{i}

并且该 复数 是 单位复数,也就是说它的长度为 11

∥cos⁡θ+sin⁡θi∥=cos⁡2θ+sin⁡2θ=1\| \cos{\theta} + \sin{\theta}\mathbf{i} \| = \sqrt{\cos^2{\theta} + \sin^2{\theta}} = 1

复数的矩阵形式

就像 四元数 可以表示为矩阵形式一样,复数 也可以表示为 2×22\times 2 矩阵形式

x+yi=[x−yyx]x + y\mathbf{i} = \begin{bmatrix} x & -y \\ y & x \end{bmatrix}

矩阵形式的 复数乘法

(x1+y1i)(x2+y2i)=[x1−y1y1x1][x2y2]=[x1x2−y1y2x2y1+x1y2](x_1 + y_1\mathbf{i})(x_2 + y_2\mathbf{i}) = \begin{bmatrix} x_1 & -y_1 \\ y_1 & x_1 \end{bmatrix} \begin{bmatrix} x_2 \\ y_2 \end{bmatrix} = \begin{bmatrix} x_1x_2 -y_1y_2 \\ x_2y_1 + x_1y_2 \end{bmatrix}

注意,在上面这个相乘计算中,我们省略了 x2+y2ix_2 + y_2\mathbf{i} 的完整矩阵形式,而只取它的第一列来计算,这是因为如果我们只想得到复数的 实部坐标 xx,复数坐标 yy,那么只需要计算矩阵的第一列就可以拿到 [xy]\begin{bmatrix} x \\ y \end{bmatrix},但是通常我们不会把列向量当作「复数」本身,因为 [xy]\begin{bmatrix} x \\ y \end{bmatrix} 只有 坐标信息,却没有编码 乘法规则

  • 可以认为把第二个 复数 写成 列向量 是在 “取坐标”

因为 复数乘法 是满足 交换律 的,但是矩阵乘法本身不满足 交换律,所以我们只有将复数表示为完整的 2×2 2\times 2 矩阵,才能编码可交换的代数结构

即这一簇矩阵组成的子代数是 交换的(矩阵一般不交换),这正好对应复数乘法可交换的性质

例如,若有

z1=x1+y1i=[x1−y1y1x1],z2=x2+y2i=[x2−y2y2x2]z_1 = x_1 + y_1\mathbf{i} = \begin{bmatrix} x_1 & -y_1 \\ y_1 & x_1 \end{bmatrix}, \quad z_2 = x_2 + y_2\mathbf{i} = \begin{bmatrix} x_2 & -y_2 \\ y_2 & x_2 \end{bmatrix}

那么

z1z2=[x1−y1y1x1][x2−y2y2x2]=[x2x1−y2y1x2y1+x2x1]z2z1=[x2−y2y2x2][x1−y1y1x1]=[x1x2−y1y2x1y2+x1x2]\begin{align*} z_1z_2 &= \begin{bmatrix} x_1 & -y_1 \\ y_1 & x_1 \end{bmatrix} \begin{bmatrix} x_2 & -y_2 \\ y_2 & x_2 \end{bmatrix} = \begin{bmatrix} x_2x_1 - y_2y_1 \\ x_2y_1 + x_2x_1 \end{bmatrix} \\ z_2z_1 &= \begin{bmatrix} x_2 & -y_2 \\ y_2 & x_2 \end{bmatrix} \begin{bmatrix} x_1 & -y_1 \\ y_1 & x_1 \end{bmatrix} = \begin{bmatrix} x_1x_2 - y_1y_2 \\ x_1y_2 + x_1x_2 \end{bmatrix} \end{align*}

所以

z1z2=z2z1z_1z_2 = z_2z_1

确实满足 交换律

注意,复数虽然满足 交换律,但是 四元数 是丢失了 交换律 才得以定义的,所以 四元数乘法不满足交换律 (根据 哈密顿规则)

验证自洽性

接下来考察一些情况,看看矩阵形式的复数能否自洽

  • 纯实数 11 : x=1,y=0  ⟹  1+0ix = 1, y = 0 \implies 1 + 0\mathbf{i}
    代入 x=1,y=0x = 1, y = 0 到矩阵 [x−yyx]\begin{bmatrix} x & -y \\ y & x \end{bmatrix},可得 [1001]=1\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \mathbf{1},得到 单位矩阵,其乘以其他任何矩阵得其本身,确实是 单位 1

  • 纯虚数 ii:x=0,y=1  ⟹  0+ix = 0, y = 1 \implies 0 + \mathbf{i}
    代入 x=0,y=1x = 0, y = 1 到矩阵 [x−yyx]\begin{bmatrix} x & -y \\ y & x \end{bmatrix},可得 [0−110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix},虚数的定义是 i2=−1i^2 = -1

    [0−110][0−110]=[0−1−10]=−[0110]=−1\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & -1 \\ -1 & 0 \end{bmatrix} = -\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} = -\mathbf{1}

    依然成立

性质

复数的矩阵形式有如下性质

  • 性质1:复数的共轭等于其对应矩阵形式的转置

    z=x+yi=[x−yyx]zˉ=x−yi=[xy−yx]=[x−yyx]T\begin{align*} z &= x + y\mathbf{i} = \begin{bmatrix} x & -y \\ y & x \end{bmatrix} \\ \bar{z} &= x - y\mathbf{i} = \begin{bmatrix} x & y \\ -y & x \end{bmatrix} = \begin{bmatrix} x & -y \\ y & x \end{bmatrix}^{\mathsf{T}} \end{align*}
  • 性质2:复数的模长(其对应二维向量的长度)的平方等于其对应矩阵的行列式

    z=x+yi=[x−yyx]∥z∥2=x2+y2det⁡[x−yyx]=x2−−y2=x2+y2=∥z∥2z = x + y\mathbf{i} = \begin{bmatrix} x & -y \\ y & x \end{bmatrix} \\ \|z\|^2 = x^2 + y^2 \\ \det{\begin{bmatrix} x & -y \\ y & x \end{bmatrix}} = x^2 - -y^2 = x^2 + y^2 = \|z\|^2

复数和二维旋转矩阵

我们知道将一个复数旋转 θ∘\theta^\circ 需要乘以下面这个复数

cos⁡θ+sin⁡θi\cos{\theta} + \sin{\theta}\mathbf{i}

我们也可以将它写成矩阵形式

cos⁡θ+sin⁡θi=[cos⁡θ−sin⁡θsin⁡θcos⁡θ]\cos{\theta} + \sin{\theta}\mathbf{i} = \begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix}

这就是 二维旋转矩阵,用其乘以任意二维向量,得到旋转变换 θ∘\theta^\circ 之后的结果,即将向量代数和复数联系起来

3D 旋转 和 罗德里格斯旋转公式

我们先来考虑 3D 旋转的一种特殊情况:3D 向量绕与其垂直的转轴向量旋转

可以认为,与被旋转向量 v⃗\vec{v} 垂直的转轴 n^\hat{n} 定义了一个平面 (n^\hat{n} 是平面的 法向量,它是 单位向量),那么 v⃗\vec{v} 与其旋转 θ∘\theta^\circ 之后的结果 v⃗′\vec{v}' 均位于该平面内

Three-dimensional vector rotated around a unit normal axis, showing the rotation plane and angle.
向量绕单位法线旋转时,垂直于法线的分量沿旋转平面转动,旋转角为 θ。

计算 法向量 n^\hat{n} 和 v⃗\vec{v} 的 叉乘 可以得到垂直于它们的向量 n^×v⃗\hat{n} \times \vec{v}

Cross product direction for two vectors, showing the right-hand normal and the parallelogram plane.
叉乘给出同时垂直于两个输入向量的方向,也就是后续旋转平面的法线方向。

n^\hat{n} 和 v⃗\vec{v} 是一组在平面内 正交,长度为 11 的 基向量,在它们 张成 的二维平面里,任何旋转都是普通的 2D 旋转,可以由我们之前推导的 二维旋转矩阵 来描述

[cos⁡θ−sin⁡θsin⁡θcos⁡θ]\begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix}

我们在矩阵分解中谈论过的使用 Givens 旋转 在 2维度子空间中旋转消零来进行 QR-分解,有兴趣可以阅读相关笔记

但是实际上,被旋转向量 v⃗\vec{v} 当然不会完全 正交 于 转轴 n^\hat{n}

Vector decomposed into parallel and perpendicular components relative to a rotation axis.
任意向量都可以按旋转轴拆成平行分量和垂直分量;只有垂直分量参与平面内旋转。

但是我们任然可以将其拆分为 正交于转轴 和 平行于转轴 的两部分

v⃗=v⃗∥+v⃗⊥=(n^⋅v⃗)v⃗⏟v⃗∥+(v⃗−(n^⋅v⃗)n^)⏟v⃗⊥\begin{align*} \vec{v} &= \vec{v}_{\parallel} + \vec{v}_{\perp} \\ &= \underbrace{(\hat{n}\cdot\vec{v})\vec{v}}_{\vec{v}_{\parallel}} + \underbrace{(\vec{v} - (\hat{n}\cdot\vec{v})\hat{n})}_{\vec{v}_{\perp}} \end{align*}
  • 平行分量 v⃗∥\vec{v}_{\parallel} 与轴 n^\hat{n} 共线,旋转后 保持不变

  • 垂直分量 v⃗⊥\vec{v}_{\perp} 位于垂直于轴 n^\hat{n} 的平面里,需要在该平面内旋转 θ\theta

Rotated vector reconstructed from an unchanged parallel component and a rotated perpendicular component.
旋转后的向量由保持不变的平行分量和旋转后的垂直分量重新相加得到。

也就是说,旋转后的向量 v⃗′\vec{v}' 是旋转后 平行分量 v⃗∥′\vec{v}_{\parallel}' 和 旋转后的 正交分量 之和,但是由于 平行分量 旋转后保持不变,所以有

v⃗∥′=v⃗∥\vec{v}_{\parallel}' = \vec{v}_{\parallel}

也就是

v⃗′=v⃗∥′+v⃗⊥′=v⃗∥+v⃗⊥′\begin{align*} \vec{v}' &= \vec{v}_{\parallel}' + \vec{v}_{\perp}' \\ &= \vec{v}_{\parallel} + \vec{v}_{\perp}' \end{align*}

而为了得到旋转后的 正交分量 v⃗⊥′\vec{v}_{\perp}',我们首先在 旋转平面 里建立 正交基 来表示 v⃗⊥\vec{v}_{\perp},我们构造的基是:

e1=v⃗⊥∥v⃗⊥∥,e2=n^×e1\mathbf{e}_1 = \frac{\vec{v}_{\perp}}{\|\vec{v}_{\perp}\|} ,\quad \mathbf{e}_2 = \hat{n} \times \mathbf{e}_1

由于 e1\mathbf{e}_1 是借助 v⃗⊥\vec{v}_{\perp} 构造的与之同向的 单位向量,所以 v⃗⊥\vec{v}_{\perp} 表示在该坐标系中,将只在 e1\mathbf{e}_1 方向上有分量,而我们知道这个分量大小当然是 ∥v⃗⊥∥\|\vec{v}_{\perp}\|

v⃗⊥=xe1+ye2=∥v⃗⊥∥e1+0e2=∥v⃗⊥∥e1=[∥v⃗⊥∥0](e1,e2)\begin{align*} \vec{v}_{\perp} &= x\mathbf{e}_1 + y\mathbf{e}_2 \\ &= \|\vec{v}_{\perp}\|\mathbf{e}_1 + 0\mathbf{e}_2 \\ &= \|\vec{v}_{\perp}\|\mathbf{e}_1 \\ &= \begin{bmatrix} \|\vec{v}_{\perp}\| \\ 0 \end{bmatrix}_{(\mathbf{e}_1, \mathbf{e}_2)} \end{align*}

我们知道 v⃗⊥′\vec{v}_{\perp}' 是 v⃗⊥\vec{v}_{\perp} 在平面内旋转 θ\theta 得到的,而我们已经在平面内选取了基 e1,e2\mathbf{e}_1, \mathbf{e}_2,并得到了 v⃗⊥\vec{v}_{\perp} 在这组基下的坐标

v⃗⊥=[∥v⃗⊥∥0](e1,e2)\vec{v}_{\perp} = \begin{bmatrix} \|\vec{v}_{\perp}\| \\ 0 \end{bmatrix}_{(\mathbf{e}_1, \mathbf{e}_2)}

我们此时可以应用之前分析得到的 2-D 旋转矩阵 来将其旋转 θ\theta 得到 v⃗⊥′\vec{v}_{\perp}'

v⃗⊥′=[cos⁡θ−sin⁡θsin⁡θcos⁡θ][∥v⃗⊥∥0](e1,e2)=[∥v⃗⊥∥cos⁡θ∥v⃗⊥∥sin⁡θ](e1,e2)=∥v⃗⊥∥cos⁡θ e1+∥v⃗⊥∥sin⁡θ e2\begin{align*} \vec{v}_{\perp}' &= \begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix} \begin{bmatrix} \|\vec{v}_{\perp}\| \\ 0 \end{bmatrix}_{(\mathbf{e}_1, \mathbf{e}_2)} \\ &= \begin{bmatrix} \|\vec{v}_{\perp}\|\cos{\theta} \\ \|\vec{v}_{\perp}\|\sin{\theta} \end{bmatrix}_{(\mathbf{e}_1, \mathbf{e}_2)} \\ &= \|\vec{v}_{\perp}\|\cos{\theta} \ \mathbf{e}_1 + \|\vec{v}_{\perp}\|\sin{\theta} \ \mathbf{e}_2 \end{align*}

我们可以将构造 e1,e2\mathbf{e}_1, \mathbf{e}_2 时的定义

e1=v⃗⊥∥v⃗⊥∥,e2=n^×e⃗1\mathbf{e}_1 = \frac{\vec{v}_{\perp}}{\|\vec{v}_{\perp}\|} ,\quad \mathbf{e}_2 = \hat{n} \times \vec{e}_1

代入,得到

v⃗⊥′=∥v⃗⊥∥cos⁡θ e1+∥v⃗⊥∥sin⁡θ e2=∥v⃗⊥∥cos⁡θ v⃗⊥∥v⃗⊥∥⏟e1+∥v⃗⊥∥sin⁡θ n^×e1⏟e2=cos⁡θ v⃗⊥+sin⁡θ ∥v⃗⊥∥(n^×v⃗⊥∥v⃗⊥∥)=cos⁡θ v⃗⊥+sin⁡θ (n^×v⃗⊥)\begin{align*} \vec{v}_{\perp}' &= \|\vec{v}_{\perp}\|\cos{\theta} \ \mathbf{e}_1 + \|\vec{v}_{\perp}\|\sin{\theta} \ \mathbf{e}_2 \\ &= \|\vec{v}_{\perp}\|\cos{\theta} \ \underbrace{\frac{\vec{v}_{\perp}}{\|\vec{v}_{\perp}\|}}_{\mathbf{e}_1} + \|\vec{v}_{\perp}\|\sin{\theta} \ \underbrace{\hat{n} \times \mathbf{e}_1}_{\mathbf{e}_2} \\ &= \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ \|\vec{v}_{\perp}\|(\hat{n} \times \frac{\vec{v}_{\perp}}{\|\vec{v}_{\perp}\|}) \\ &= \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ (\hat{n} \times \vec{v}_{\perp}) \end{align*}

由于 v⃗∥\vec{v}_{\parallel} 与 n^\hat{n} 共线,n^×v⃗∥=0\hat{n} \times \vec{v}_{\parallel} = 0 所以

n^×v⃗⊥=n^×(v⃗−v⃗∥)=n^×v⃗−n^×v⃗∥=n^×v⃗\hat{n} \times \vec{v}_{\perp} = \hat{n} \times (\vec{v} - \vec{v}_{\parallel}) = \hat{n}\times \vec{v} - \hat{n}\times \vec{v}_{\parallel} = \hat{n}\times \vec{v}

再次将这个结果代入,得到

v⃗⊥′=cos⁡θ v⃗⊥+sin⁡θ (n^×v⃗)\vec{v}_{\perp}' = \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ (\hat{n} \times \vec{v})

将它与 平行分量 合并,得到

v⃗′=v⃗∥+v⃗⊥′=v⃗∥+cos⁡θ v⃗⊥+sin⁡θ (n^×v⃗)\begin{align*} \vec{v}' &= \vec{v}_{\parallel} + \vec{v}_{\perp}' \\ &= \vec{v}_{\parallel} + \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ (\hat{n} \times \vec{v}) \end{align*}

而 v⃗∥\vec{v}_{\parallel} 是 v⃗\vec{v} 向 转轴 n^\hat{n} 上投影得到的,它等于

v⃗∥=(n^⋅v⃗)n^\vec{v}_{\parallel} = (\hat{n}\cdot \vec{v})\hat{n}

将它带入,我们最终得到 罗德里格斯三项式

v⃗′=v⃗∥+v⃗⊥′=(n^⋅v⃗)n^+cos⁡θ v⃗⊥+sin⁡θ (n^×v⃗)=v⃗cos⁡θ+(n^×v⃗)sin⁡θ+n^(n^⋅v⃗)(1−cos⁡θ)\begin{align*} \vec{v}' &= \vec{v}_{\parallel} + \vec{v}_{\perp}' \\ &= (\hat{n}\cdot \vec{v})\hat{n} + \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ (\hat{n} \times \vec{v}) \\ &= \boxed{\vec{v}\cos{\theta} + (\hat{n}\times\vec{v})\sin{\theta} + \hat{n}(\hat{n}\cdot\vec{v})(1-\cos{\theta})} \end{align*}

这就是著名的 罗德里格斯旋转公式

3D旋转 和 四元数

前面的分析是完全基于 线性代数 的,我们也可以使用 四元数 来表示旋转,事实上 四元数 可能是更好的方案

我们首先从 正交分量 v⃗⊥′\vec{v}'_{\perp} 开始,根据前面的推导,我们知道

v⃗⊥′=cos⁡θ v⃗⊥+sin⁡θ (n^×v⃗⊥)\vec{v}_{\perp}' = \cos{\theta} \ \vec{v}_{\perp} + \sin{\theta} \ (\hat{n} \times \vec{v}_{\perp})

我们设定所有需要用到的对象为等价的 四元数

v⊥=(0,v⃗⊥)v⊥′=(0,v⃗⊥′)n=(0,n^)v_{\perp} = (0,\vec{v}_{\perp}) \quad v'_{\perp} = (0,\vec{v}_{\perp}') \quad n = (0,\hat{n})
  • 注意,不带箭头的表示 四元数

因为原对象全都是向量,所以直接将他们塞入 四元数 的 向量部分 即可构造对应四元数,所以上面的式子变为

v⊥′=cos⁡θ v⊥+sin⁡θ (n v⊥)v'_{\perp} = \cos{\theta} \ v_{\perp} + \sin{\theta} \ (n \ v_{\perp})

这里可能需要讨论的是,四元数 nn 和 v⊥v_{\perp} 的相乘是否与原来的向量叉乘 n^×v⃗⊥\hat{n}\times \vec{v}_{\perp} 等价,根据我们前面推导出的四元数乘法法则,有

nv⊥=(−n^⋅v⃗, n^×v⃗)nv_{\perp} = (-\hat{n}\cdot \vec{v}, \ \hat{n}\times \vec{v})

我们知道 v⃗⊥\vec{v}_{\perp} 正交 于 n^\hat{n},所以

n^⋅v⃗=0\hat{n}\cdot \vec{v} = 0

也就是说

nv⊥=(−n^⋅v⃗, n^×v⃗)=(0, n^×v⃗)=n^×v⃗\begin{align*} nv_{\perp} &= (-\hat{n}\cdot \vec{v}, \ \hat{n}\times \vec{v}) \\ &= (0, \ \hat{n}\times \vec{v}) \\ &= \hat{n}\times \vec{v} \end{align*}

所以确实是等价的

那么我们使用四元数替换的式子就是

v⊥′=cos⁡θ v⊥+sin⁡θ (n v⊥)=(cos⁡θ+sin⁡θn)v⊥\begin{align*} v'_{\perp} &= \cos{\theta} \ v_{\perp} + \sin{\theta} \ (n \ v_{\perp}) \\ &= (\cos{\theta} + \sin{\theta}n)v_{\perp} \end{align*}

注意四元数乘法不满足交换律,所以提取顺序不可改变

然后我们来分析一下 nn,我们会发现它实际上是 虚数单位,因为

n2=(0,n^)(0,n^)=(−n^⋅n^, n^×n^)=(−∥n^∥2, 0)=(−1, 0)=−1=i\begin{align*} n^2 &= (0,\hat{n})(0,\hat{n}) \\ &= (-\hat{n}\cdot \hat{n}, \ \hat{n}\times \hat{n}) \\ &= (-\|\hat{n}\|^2, \ 0) \\ &= (-1,\ 0) \\ &= -1 \\ &= i \end{align*}

我们知道 欧拉公式

eiθ=(cos⁡θ+sin⁡θi)e^{i\theta} = (\cos{\theta} + \sin{\theta}i)

所以原式变为

v⊥′=(cos⁡θ+sin⁡θn)v⊥=enθv⊥\begin{align*} v'_{\perp} &= (\cos{\theta} + \sin{\theta}n)v_{\perp} \\ &= e^{n\theta}v_{\perp} \end{align*}
  • nn 是 转轴单位向量 构造的四元数,θ\theta 是转动角度

导出完整的四元数旋转公式

我们已经推导得到

v⊥′=enθv⊥v'_{\perp} = e^{n\theta}v_{\perp}

但是如若想完整的用 四元数 来表达旋转,我们还需要一些步骤,首先是补齐前面没有定义的四元数

v=(0,v⃗)v⊥=(0,v⃗⊥)v∥=(0,v⃗∥)v⊥′=(0,v⃗⊥′)n=(0,n^)v = (0, \vec{v}) \quad v_{\perp} = (0,\vec{v}_{\perp}) \quad v_{\parallel} = (0,\vec{v}_{\parallel}) \\ v'_{\perp} = (0,\vec{v}_{\perp}') \quad n = (0,\hat{n})
  • 注意,不带箭头的表示 四元数,原对象全都是 向量,所以直接将他们塞入 四元数 的 向量部分 即可构造对应 四元数

证明 enθv⊥=v⊥e−nθe^{n\theta}v_{\perp} = v_{\perp}e^{-n\theta}

首先来看 enθv⊥e^{n\theta}v_{\perp},我们知道 enθe^{n\theta} 是从 欧拉公式 来的

enθ=(cos⁡θ+sin⁡θn)e^{n\theta} = (\cos{\theta} + \sin{\theta}n)

而这里 nn 是 纯向量四元数,只含有向量部分,并且 n2=−1n^2 = -1,所以可以将它写为如下形式

n=0+n^xi+n^yj+n^kkn = 0 + \hat{n}_x\mathbf{i} + \hat{n}_y\mathbf{j} + \hat{n}_k\mathbf{k}
  • n^x,n^y,n^z\hat{n}_x,\hat{n}_y,\hat{n}_z 是 nn 在各虚轴上的分量

将其代回,得到

enθ=(cos⁡θ+sin⁡θn)=cos⁡θ+sin⁡θ(n^xi+n^yj+n^kk)=cos⁡θ+sin⁡θn^xi+sin⁡θn^yj+sin⁡θn^kk=(cos⁡θ, sin⁡θ n^)\begin{align*} e^{n\theta} &= (\cos{\theta} + \sin{\theta}n) \\ &= \cos{\theta} + \sin{\theta}(\hat{n}_x\mathbf{i} + \hat{n}_y\mathbf{j} + \hat{n}_k\mathbf{k}) \\ &= \cos{\theta} + \sin{\theta}\hat{n}_x\mathbf{i} + \sin{\theta}\hat{n}_y\mathbf{j} + \sin{\theta}\hat{n}_k\mathbf{k} \\ &= (\cos{\theta}, \ \sin{\theta}\ \hat{n}) \end{align*}

所以我们得到 四元数 enθe^{n\theta} 的 向量-标量表示法 是 (cos⁡θ, sin⁡θ n^)(\cos{\theta}, \ \sin{\theta}\ \hat{n})

可以认为 enθ=cos⁡θ+sin⁡θn^xi+sin⁡θn^yj+sin⁡θn^kke^{n\theta} = \cos{\theta} + \sin{\theta}\hat{n}_x\mathbf{i} + \sin{\theta}\hat{n}_y\mathbf{j} + \sin{\theta}\hat{n}_k\mathbf{k} 是 四元数形式的欧拉公式

如此一来,我们有

enθv⊥=(cos⁡θ, sin⁡θ n^)v⊥=(cos⁡θ, sin⁡θ n^)(0,v⃗⊥)\begin{align*} e^{n\theta}v_{\perp} &= (\cos{\theta}, \ \sin{\theta}\ \hat{n})v_{\perp} \\ &= (\cos{\theta}, \ \sin{\theta}\ \hat{n})(0,\vec{v}_{\perp}) \end{align*}

前面的章节我们推导出,四元数的乘法规则 (用向量,标量表示) 是

q1q2=(w1w2−a⃗⋅b⃗,w2a⃗+w1b⃗+a⃗×b⃗)aq_1q_2 = (w_1w_2 - \vec{a} \cdot \vec{b}, \quad w_2\vec{a} + w_1\vec{b} + \vec{a} \times \vec{b}) \\ \phantom{a}

所以,得到

enθv⊥=(cos⁡θ, sin⁡θ n^)(0,v⃗⊥)=(cos⁡θ⋅0−sin⁡θn^⋅v⃗⊥,  0⋅sin⁡θn^+cos⁡θv⃗⊥+sin⁡θn^×v⃗⊥)=(−sin⁡θn^⋅v⃗⊥,  cos⁡θv⃗⊥+sin⁡θn^×v⃗⊥)\begin{align*} e^{n\theta}v_{\perp} &= (\cos{\theta}, \ \sin{\theta}\ \hat{n})(0,\vec{v}_{\perp}) \\ &= ( \cos{\theta} \cdot 0 - \sin{\theta}\hat{n} \cdot \vec{v}_{\perp}, \ \ 0\cdot \sin{\theta}\hat{n} + \cos{\theta}\vec{v}_{\perp} + \sin{\theta}\hat{n} \times \vec{v}_{\perp} ) \\ &= ( - \sin{\theta}\hat{n} \cdot \vec{v}_{\perp}, \ \ \cos{\theta}\vec{v}_{\perp} + \sin{\theta}\hat{n} \times \vec{v}_{\perp} ) \end{align*}

因为 n^⊥v⃗⊥\hat{n}\perp \vec{v}_{\perp} 所以 n^⋅v⃗⊥=0\hat{n}\cdot \vec{v}_{\perp} = 0,即

enθv⊥=(−sin⁡θn^⋅v⃗⊥,  cos⁡θv⃗⊥+sin⁡θn^×v⃗⊥)=(0,  cos⁡θv⃗⊥+sin⁡θn^×v⃗⊥)\begin{align*} e^{n\theta}v_{\perp} &= ( - \sin{\theta}\hat{n} \cdot \vec{v}_{\perp}, \ \ \cos{\theta}\vec{v}_{\perp} + \sin{\theta}\hat{n} \times \vec{v}_{\perp} ) \\ &= ( 0, \ \ \cos{\theta}\vec{v}_{\perp} + \sin{\theta}\hat{n} \times \vec{v}_{\perp} ) \end{align*}

然后再来看 v⊥e−nθv_{\perp}e^{-n\theta},经过同样的分析,我们可以得到 e−nθe^{-n\theta} 的 向量-标量表示法

e−nθ=(cos⁡θ, −sin⁡θ n^)e^{-n\theta} = (\cos{\theta}, \ -\sin{\theta}\ \hat{n})

同样使用 乘法法则

v⊥e−nθ=(0,v⃗⊥)(cos⁡θ, sin⁡θ n^)=(0,  cos⁡θv⃗⊥−v⃗⊥×sin⁡θ n^)\begin{align*} v_{\perp}e^{-n\theta} &= (0,\vec{v}_{\perp})(\cos{\theta}, \ \sin{\theta}\ \hat{n}) \\ &= ( 0,\ \ \cos{\theta}\vec{v}_{\perp} - \vec{v}_{\perp}\times \sin{\theta}\ \hat{n} ) \end{align*}

所以,现在我们有

  • enθv⊥=(0,  cos⁡θv⃗⊥+sin⁡θn^×v⃗⊥)e^{n\theta}v_{\perp} = ( 0, \ \ \cos{\theta}\vec{v}_{\perp} + \sin{\theta}\hat{n} \times \vec{v}_{\perp})
  • v⊥e−nθ=(0,  cos⁡θv⃗⊥−v⃗⊥×sin⁡θ n^)v_{\perp}e^{-n\theta} = (0,\ \ \cos{\theta}\vec{v}_{\perp} - \vec{v}_{\perp}\times \sin{\theta}\ \hat{n})

我们知道交换叉乘顺序会改变符合,也就是

sin⁡θn^×v⃗⊥=−v⃗⊥×sin⁡θ n^\sin{\theta}\hat{n} \times \vec{v}_{\perp} = - \vec{v}_{\perp}\times \sin{\theta}\ \hat{n}

所以 enθv⊥e^{n\theta}v_{\perp} 和 v⊥e−nθv_{\perp}e^{-n\theta} 的 向量部分 完全相等,且它们的 标量部分 全都为零,所以

enθv⊥=v⊥e−nθe^{n\theta}v_{\perp} = v_{\perp}e^{-n\theta}

证明 enθv∥=v∥enθe^{n\theta}v_{\parallel} = v_{\parallel}e^{n\theta}

我们已知

enθ=(cos⁡θ, sin⁡θ n^)v∥=(0,v⃗∥)\begin{align*} e^{n\theta} &= (\cos{\theta}, \ \sin{\theta}\ \hat{n}) \\ v_{\parallel} &= (0,\vec{v}_{\parallel}) \end{align*}

同样直接代入 四元数乘法公式,可得

enθv∥=(cos⁡θ, sin⁡θ n^)(0,v⃗∥)=(−sin⁡θ n^⋅v⃗∥,  cos⁡θv⃗∥+sin⁡θ n^×v⃗∥)\begin{align*} e^{n\theta}v_{\parallel} &= (\cos{\theta}, \ \sin{\theta}\ \hat{n})(0,\vec{v}_{\parallel}) \\ &= ( -\sin{\theta}\ \hat{n} \cdot \vec{v}_{\parallel}, \ \ \cos{\theta}\vec{v}_{\parallel} + \sin{\theta}\ \hat{n} \times \vec{v}_{\parallel} ) \end{align*}

因为 n^\hat{n} 和 v⃗∥\vec{v}_{\parallel} 共向,所以他们的叉乘为零

sin⁡θ n^×v⃗∥=0\sin{\theta}\ \hat{n} \times \vec{v}_{\parallel} = 0

所以

enθv∥=(−sin⁡θ n^⋅v⃗∥,  cos⁡θv⃗∥+sin⁡θ n^×v⃗∥)=(−sin⁡θ n^⋅v⃗∥,  cos⁡θv⃗∥)\begin{align*} e^{n\theta}v_{\parallel} &= ( -\sin{\theta}\ \hat{n} \cdot \vec{v}_{\parallel}, \ \ \cos{\theta}\vec{v}_{\parallel} + \sin{\theta}\ \hat{n} \times \vec{v}_{\parallel} ) \\ &= ( -\sin{\theta}\ \hat{n} \cdot \vec{v}_{\parallel}, \ \ \cos{\theta}\vec{v}_{\parallel} ) \end{align*}

同理可以分析

v∥enθ=(0,v⃗∥)(cos⁡θ, sin⁡θ n^)=(−v⃗∥⋅sin⁡θ n^,  cos⁡θv⃗∥+v⃗∥×sin⁡θ n^)=(−v⃗∥⋅sin⁡θ n^,  cos⁡θv⃗∥)\begin{align*} v_{\parallel}e^{n\theta} &= (0,\vec{v}_{\parallel}) (\cos{\theta}, \ \sin{\theta}\ \hat{n}) \\ &= ( -\vec{v}_{\parallel}\cdot \sin{\theta}\ \hat{n}, \ \ \cos{\theta}\vec{v}_{\parallel} + \vec{v}_{\parallel} \times \sin{\theta}\ \hat{n} ) \\ &= ( -\vec{v}_{\parallel}\cdot \sin{\theta}\ \hat{n}, \ \ \cos{\theta}\vec{v}_{\parallel} ) \end{align*}

所以最终得到

  • enθv∥=(−sin⁡θ n^⋅v⃗∥,  cos⁡θv⃗∥)e^{n\theta}v_{\parallel} = ( -\sin{\theta}\ \hat{n} \cdot \vec{v}_{\parallel}, \ \ \cos{\theta}\vec{v}_{\parallel})
  • v∥enθ=(−v⃗∥⋅sin⁡θ n^,  cos⁡θv⃗∥)v_{\parallel}e^{n\theta} = (-\vec{v}_{\parallel}\cdot \sin{\theta}\ \hat{n}, \ \ \cos{\theta}\vec{v}_{\parallel})

它们的向量部分完全相同,而标量部分的点乘天然具有可交换顺序的性质,所以

enθv∥=v∥enθe^{n\theta}v_{\parallel} = v_{\parallel}e^{n\theta}

最终写出四元数乘法公式

我们到目前为止已经知道

v=(0,v⃗)v⊥=(0,v⃗⊥)v∥=(0,v⃗∥)v⊥′=(0,v⃗⊥′)n=(0,n^)aenθv⊥=v⊥e−nθenθv∥=v∥enθv = (0, \vec{v}) \quad v_{\perp} = (0,\vec{v}_{\perp}) \quad v_{\parallel} = (0,\vec{v}_{\parallel}) \\ v'_{\perp} = (0,\vec{v}_{\perp}') \quad n = (0,\hat{n}) \\ \phantom{a} \\ e^{n\theta}v_{\perp} = v_{\perp}e^{-n\theta} \quad e^{n\theta}v_{\parallel} = v_{\parallel}e^{n\theta}

且

v′=v∥′+v⊥′=v∥+enθv⊥\begin{align*} v' &= v_{\parallel}' + v'_{\perp} \\ &= v_{\parallel} + e^{n\theta}v_{\perp} \end{align*}
  • v∥′=v∥v_{\parallel}' = v_{\parallel} 平行分量旋转不变,是我们之前得到的结论

  • v⊥′=enθv⊥v'_{\perp} = e^{n\theta}v_{\perp} 也是我们先前分析得到的结果

我们可以添加几个指数形式的四元数,同时保持等式不变

v′=v∥+enθv⊥=enθ2e−nθ2v∥+enθ2enθ2v⊥\begin{align*} v' &= v_{\parallel} + e^{n\theta}v_{\perp} \\ &= e^{n\frac{\theta}{2}}e^{-n\frac{\theta}{2}}v_{\parallel} + e^{n\frac{\theta}{2}}e^{n\frac{\theta}{2}}v_{\perp} \end{align*}

注意,这不改变原等式,然后我们可以借助之前证明的两个等式,来交换 v∥v_{\parallel} 和 v⊥v_{\perp} 与它们各自前面的 指数四元数 的顺序

enθv⊥=v⊥e−nθenθv∥=v∥enθe^{n\theta}v_{\perp} = v_{\perp}e^{-n\theta} \quad e^{n\theta}v_{\parallel} = v_{\parallel}e^{n\theta}

得到

v′=enθ2e−nθ2v∥+enθ2enθ2v⊥=enθ2v∥e−nθ2+enθ2v⊥e−nθ2\begin{align*} v' &= e^{n\frac{\theta}{2}}e^{-n\frac{\theta}{2}}v_{\parallel} + e^{n\frac{\theta}{2}}e^{n\frac{\theta}{2}}v_{\perp} \\ &= e^{n\frac{\theta}{2}}v_{\parallel}e^{-n\frac{\theta}{2}} + e^{n\frac{\theta}{2}}v_{\perp}e^{-n\frac{\theta}{2}} \end{align*}
  • 注意,根据先前证明的等式,v∥v_{\parallel} 和它前面的 指数四元数 交换顺序,指数四元数 无需改变指数上的符号
  • 但是 v⊥v_{\perp} 的交换则需要改变 指数四元数 的符号

然后我们可以提取公因子

v′=enθ2v∥e−nθ2+enθ2v⊥e−nθ2=enθ2(v∥+v⊥)e−nθ2\begin{align*} v' &= e^{n\frac{\theta}{2}}v_{\parallel}e^{-n\frac{\theta}{2}} + e^{n\frac{\theta}{2}}v_{\perp}e^{-n\frac{\theta}{2}} \\ &= e^{n\frac{\theta}{2}}(v_{\parallel} + v_{\perp})e^{-n\frac{\theta}{2}} \end{align*}

注意四元数乘法不遵从交换律,所以提取顺序要注意

因为 v=v∥+v⊥v = v_{\parallel} + v_{\perp},所以

v′=enθ2(v∥+v⊥)e−nθ2=enθ2 v e−nθ2\begin{align*} v' &= e^{n\frac{\theta}{2}}(v_{\parallel} + v_{\perp})e^{-n\frac{\theta}{2}} \\ &= e^{n\frac{\theta}{2}}\ v \ e^{-n\frac{\theta}{2}} \end{align*}

所以最终得到,将 四元数 旋转 θ\theta 度的公式

v′=enθ2 v e−nθ2v' = e^{n\frac{\theta}{2}}\ v \ e^{-n\frac{\theta}{2}}

注意 enθ2e^{n\frac{\theta}{2}} 和 e−nθ2e^{-n\frac{\theta}{2}} 是两个互为 共轭 的 四元数,若设 q=enθ2q = e^{n\frac{\theta}{2}},则共轭是 q∗=e−nθ2q^\ast = e^{-n\frac{\theta}{2}},所以也可以写成

v′=qvq∗v' = qvq^\ast

也就是说,如果我们表示一个 θ∘\theta^\circ 的旋转,我们需要构造一个 四元数

q=enθ2=cos⁡θ2+sin⁡θ2n^xi+sin⁡θ2n^yj+sin⁡θ2n^zkq = e^{n\frac{\theta}{2}} = \cos{\frac{\theta}{2}} + \sin{\frac{\theta}{2}}\hat{n}_x\mathbf{i} + \sin{\frac{\theta}{2}}\hat{n}_y\mathbf{j} + \sin{\frac{\theta}{2}}\hat{n}_z\mathbf{k}

然后将待旋转的向量也构建一个 纯向量四元数 vv,乘以 qq 之后再乘以它的共轭

q∗=e−nθ2=cos⁡θ2−sin⁡θ2n^xi−sin⁡θ2n^yj−sin⁡θ2n^zkq^\ast = e^{-n\frac{\theta}{2}} = \cos{\frac{\theta}{2}} - \sin{\frac{\theta}{2}}\hat{n}_x\mathbf{i} - \sin{\frac{\theta}{2}}\hat{n}_y\mathbf{j} - \sin{\frac{\theta}{2}}\hat{n}_z\mathbf{k}
  • sin⁡\sin 是 奇函数,sin⁡−θ2=−sin⁡θ2 \sin{-\frac{\theta}{2}} = -\sin{\frac{\theta}{2}}
  • cos⁡\cos 是 偶函数,cos⁡−θ2=cos⁡θ2\cos{-\frac{\theta}{2}} = \cos{\frac{\theta}{2}}

即可得到最终旋转后的结果 v′v'

v′=qvq∗\boxed{v' = qvq^\ast}