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=x1x2y1y2+(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)=(x1x2y1y2,  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 可以分解为在基 xxyy 上的分量

{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 得到 vv',其相应分量 vxv_xvyv_y 也随之旋转 θ\theta^\circ 得到 vxv'_xvyv'_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)=(x1x2y1y2,  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=cos2θ+sin2θ=1\| \cos{\theta} + \sin{\theta}\mathbf{i} \| = \sqrt{\cos^2{\theta} + \sin^2{\theta}} = 1

复数的矩阵形式

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

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

矩阵形式的 复数乘法

(x1+y1i)(x2+y2i)=[x1y1y1x1][x2y2]=[x1x2y1y2x2y1+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=[x1y1y1x1],z2=x2+y2i=[x2y2y2x2]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=[x1y1y1x1][x2y2y2x2]=[x2x1y2y1x2y1+x2x1]z2z1=[x2y2y2x2][x1y1y1x1]=[x1x2y1y2x1y2+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 到矩阵 [xyyx]\begin{bmatrix} x & -y \\ y & x \end{bmatrix},可得 [1001]=1\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \mathbf{1},得到 单位矩阵,其乘以其他任何矩阵得其本身,确实是 单位 1

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

    [0110][0110]=[0110]=[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=[xyyx]zˉ=xyi=[xyyx]=[xyyx]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=[xyyx]z2=x2+y2det[xyyx]=x2y2=x2+y2=z2z = 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)vv+(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=vv,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=ve1+0e2=ve1=[v0](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=[v0](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θ][v0](e1,e2)=[vcosθvsinθ](e1,e2)=vcosθ e1+vsinθ 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=vv,e2=n^×e1\mathbf{e}_1 = \frac{\vec{v}_{\perp}}{\|\vec{v}_{\perp}\|} ,\quad \mathbf{e}_2 = \hat{n} \times \vec{e}_1

代入,得到

v=vcosθ e1+vsinθ e2=vcosθ vve1+vsinθ n^×e1e2=cosθ v+sinθ v(n^×vv)=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^×(vv)=n^×vn^×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)=vcosθ+(n^×v)sinθ+n^(n^v)(1cosθ)\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})

这里可能需要讨论的是,四元数 nnvv_{\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θvv'_{\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=venθe^{n\theta}v_{\perp} = v_{\perp}e^{-n\theta}

首先来看 enθve^{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}_znn 在各虚轴上的分量

将其代回,得到

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=(w1w2ab,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θ0sinθn^v,  0sinθ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*}

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

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

同样使用 乘法法则

venθ=(0,v)(cosθ, sinθ n^)=(0,  cosθvv×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})
  • venθ=(0,  cosθvv×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θve^{n\theta}v_{\perp}venθv_{\perp}e^{-n\theta}向量部分 完全相等,且它们的 标量部分 全都为零,所以

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

证明 enθv=venθ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*}

同理可以分析

venθ=(0,v)(cosθ, sinθ n^)=(vsinθ n^,  cosθv+v×sinθ n^)=(vsinθ 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})
  • venθ=(vsinθ n^,  cosθv)v_{\parallel}e^{n\theta} = (-\vec{v}_{\parallel}\cdot \sin{\theta}\ \hat{n}, \ \ \cos{\theta}\vec{v}_{\parallel})

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

enθv=venθ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=venθenθv=venθ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=vv_{\parallel}' = v_{\parallel} 平行分量旋转不变,是我们之前得到的结论

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

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

v=v+enθv=enθ2enθ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*}

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

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

得到

v=enθ2enθ2v+enθ2enθ2v=enθ2venθ2+enθ2venθ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*}
  • 注意,根据先前证明的等式,vv_{\parallel} 和它前面的 指数四元数 交换顺序,指数四元数 无需改变指数上的符号
  • 但是 vv_{\perp} 的交换则需要改变 指数四元数 的符号

然后我们可以提取公因子

v=enθ2venθ2+enθ2venθ2=enθ2(v+v)enθ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+vv = v_{\parallel} + v_{\perp},所以

v=enθ2(v+v)enθ2=enθ2 v enθ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 enθ2v' = e^{n\frac{\theta}{2}}\ v \ e^{-n\frac{\theta}{2}}

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

v=qvqv' = 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=enθ2=cosθ2sinθ2n^xisinθ2n^yjsinθ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}}

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

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