# 四元数与旋转矩阵

### 二维情况

$$z1z2 = (a+bi)(c+di) = (ac-bd)+(ad+bc)i$$

$$\begin{bmatrix} a & -b \\ b & a \\ \end{bmatrix} \cdot z2$$

$$z1z2 = \begin{bmatrix} a & -b \\ b & a \\ \end{bmatrix} \cdot \begin{bmatrix} c & -d \\ d & a \\ \end{bmatrix}$$

#### 二维旋转

$$\begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \\ \end{bmatrix}$$

### 三维情况

#### 四元数

$$\vec{q} = \begin{bmatrix} a \\ b \\ c \\ d \\ \end{bmatrix}$$

$$ij =k \\ jk =i \\ ki =j$$

\begin{aligned} q1q2 & = ae + a f i + agj + ahk + \\ & bei − b f + bgk − bhj + \\ & cej − c f k − cg + chi + \\ & dek + d f j − dgi − dh \\ & = ( ae − b f − cg − dh )+ \\ & ( be + a f − dg + ch ) i \\ & ( ce + d f + ag − bh ) j \\ & ( de − c f + bg + ah ) k \end{aligned}

$$q1q2 = \begin{bmatrix} a & -b & -c & -d \\ b & a & -d & c \\ c & d & a & -b \\ d & -c & b & a \end{bmatrix} \begin{bmatrix} e \\ f \\ g \\ h \\ \end{bmatrix}$$

#### Graßmann积

$$q1q2 = [ ae − \vec{v} \cdot \vec{u} , a\vec{u} + e\vec{v} + \vec{v} \times \vec{u} ]$$

$$q1q2 = [− \vec{v} \cdot \vec{u}, \vec{v} \times \vec{u} ]$$

#### 共轭性质

\begin{aligned} qq^* & = [s,\vec{v}] \cdot [s,-\vec{v}] \\ & = [s^2 - \vec{v} \cdot (-\vec{v}), s(-\vec{v}) + s\vec{v} + \vec{v}\times(-\vec{v})] \\ & = [s^2 + \vec{v} \cdot \vec{v}, \vec{0}] \\ \end{aligned}

\begin{aligned} qq^* & = [s^2 + \vec{v} \cdot \vec{v}, \vec{0}] \\ & = s^2 + |\vec{v}|^2 \\ & = a^2 + b^2 + c^2 +d^2 \\ \end{aligned}

$$q^*q = |q|^2 \\ \frac{q^*}{|q|^2}q =1$$

#### 三维旋转

$$\vec{v’} = \vec{v’_{||}} +\vec{v’_\bot} = \vec{v_{||}} +\vec{v’_\bot}$$

\begin{aligned} v’_\bot & = v_\bot cos\theta + (u v_\bot)sin\theta \\ & = (cos\theta + usin\theta)v_\bot \end{aligned}

\begin{aligned} v’ & = v’_{||} + v’_\bot \\ & = v_{||} + qv_\bot \\ & = pp^{-1}v_{||} + ppv_\bot \\ & = pp^*v_{||} + ppv_\bot \end{aligned}

\begin{aligned} qv_{||} & = [\alpha, \beta \vec{u}] \cdot [0,\vec{v}_{||}] \\ & = [-\beta \vec{u} \cdot \vec{v}_{||} , \alpha \vec{v}_{||} + \beta \vec{u} \times \vec{v}_{||}] \\ & = [-\beta \vec{u} \cdot \vec{v}_{||} , \alpha \vec{v}_{||}] \\ \end{aligned}

\begin{aligned} v_{||}q & = [0,\vec{v}_{||}] \cdot [\alpha, \beta \vec{u}] \cdot \\ & = [-\beta \vec{u} \cdot \vec{v}_{||} , \alpha \vec{v} +\vec{u} \times \vec{v}_{||}] \\ & = [-\beta \vec{u} \cdot \vec{v}_{||} , \alpha \vec{v} ] \\ & = qv_{||} \end{aligned}

\begin{aligned} qv_\bot & = [\alpha, \beta \vec{u}] \cdot [0,\vec{v}_{}] \\ & = [-\beta \vec{u} \cdot \vec{v}_\bot , \alpha \vec{v}_\bot + \beta \vec{u} \times \vec{v}_\bot] \\ & = [0, \alpha \vec{v}_\bot + \beta \vec{u} \times \vec{v}_\bot] \\ \end{aligned}

\begin{aligned} v_\bot q^* & = [0,\vec{v}_\bot] \cdot [\alpha, -\beta \vec{u}] \cdot \\ & = [-\beta \vec{u} \cdot \vec{v}_\bot , \alpha \vec{v}_\bot + \beta \vec{u} \times \vec{v}_\bot] \\ & = [0, \alpha \vec{v}_\bot + \beta \vec{u} \times \vec{v}_\bot] \\ & = qv_\bot \end{aligned}

\begin{aligned} v’ & = pp^*v_{||} + ppv_\bot \\ & = pv_{||}p^* + pv_\bot p^* \\ & = p(v_{||} + v_\bot) p^* \\ & = pvp^* \end{aligned}

#### 矩阵形式

$$L= \begin{bmatrix} a & -b & -c & -d \\ b & a & -d & c \\ c & d & a & -b \\ d & -c & b & a \end{bmatrix}$$

$$R = \begin{bmatrix} a & -b & -c & -d \\ b & a & -d & -c \\ c & -d & a & b \\ d & c & -b & a \end{bmatrix}$$

\begin{aligned} qvq^* & = L(q)R(q^*)v \\ & = \begin{bmatrix} a & -b & -c & -d \\ b & a & -d & c \\ c & d & a & -b \\ d & -c & b & a \\ \end{bmatrix} \begin{bmatrix} a & b & c & d \\ -b & a & -d & c \\ -c & d & a & -b \\ -d & -c & b & a \\ \end{bmatrix} v \\ & = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1-2c^2-2d^2 & 2bc-2ad & 2ac+2bd \\ 0 & 2bc+2ad & 1-2b^2-2d^2 & 2cd -2ab \\ 0 & 2bd-2ac & 2ab+2cd & 1-2b^2-2c^2 \\ \end{bmatrix} v \\ \end{aligned}

$$\vec{v’} = \begin{bmatrix} 1-2c^2-2d^2 & 2bc-2ad & 2ac+2bd \\ 2bc+2ad & 1-2b^2-2d^2 & 2cd -2ab \\ 2bd-2ac & 2ab+2cd & 1-2b^2-2c^2 \\ \end{bmatrix} \vec{v}$$