四元数组旋转_四元数和旋转(Quaternion & rotation)

四元数和旋转(Quaternion & rotation)

本篇文章主要讲述3D空间中的旋转和四元数之间的关系。其中会涉及到矩阵、向量运算,旋转矩阵,四元数,旋转的四元数表示,四元数表示的旋转如何转化为旋转矩阵。层层铺垫,可能文章有点长。基础好的同学,可以直接跳到四元数表示旋转部分,见下文公式(18)和公式(21)。

1 向量的点积和叉积

1.1 点积

给定两个n维向量\(\mathbf{P}, \mathbf{Q}\),则它们的点积(dot product,又称为内积)为:

\[\mathbf{P}\cdot \mathbf{Q} = \left\|\mathbf{P}\right\| \left\|\mathbf{Q}\right\|\cos\alpha \qquad(1),

\]

其中\(\alpha\)是两向量之间的夹角。

图1 向量P在Q上的投影

如上面图1,向量\(\mathbf{P}\)在\(\mathbf{Q}\)上的投影为:

\[proj_Q \mathbf{P} = \frac{\mathbf{P}\cdot \mathbf{Q}}{\left\|\mathbf{Q}\right\|^2}\mathbf{Q}

\]

向量\(\mathbf{P}\)垂直于\(\mathbf{Q}\)的分量为:

\[\begin{aligned}

perp_Q \mathbf{P} &= \mathbf{P} - proj_Q \mathbf{P}\\

&=\mathbf{p} - \frac{\mathbf{P}\cdot \mathbf{Q}}{\left\|\mathbf{Q}\right\|^2}\mathbf{Q}

\end{aligned}

\]

其中,向量\(\mathbf{P}\)在\(\mathbf{Q}\)上的投影可以看作\(\mathbf{P}\)的线性变换,可以写成矩阵向量积:

\[proj_Q \mathbf{P} = \frac{1}{\left\|\mathbf{Q}\right\|^2}\left[

\begin{matrix}

\mathcal{Q}_x^2 & \mathcal{Q}_x\mathcal{Q}_y & \mathcal{Q}_x\mathcal{Q}_z\\

\mathcal{Q}_x\mathcal{Q}_y & \mathcal{Q}_y^2 & \mathcal{Q}_y\mathcal{Q}_z \\

\mathcal{Q}_x\mathcal{Q}_z & \mathcal{Q}_y\mathcal{Q}_z & \mathcal{Q}_z^2

\end{matrix}

\right]

\left[

\begin{matrix}

P_x\\

P_y\\

P_z

\end{matrix}

\right]

\qquad (2)

\]

1.2 叉积(cross product)

给定两个3D向量\(\mathbf{P}, \mathbf{Q}\),则它们的叉积(又称为向量积,vector product)是一个向量:

\[\mathbf{P}\times \mathbf{Q} = \left \langle P_yQ_z - P_zQ_y, P_zQ_x - P_xQ_z, P_xQ_y - P_yQ_x \right \rangle.

\]

叉积的模:

\[\left \| \mathbf{P}\times \mathbf{Q}\right \| = \left \| \mathbf{P} \right \| \left \| Q \right \| \sin\alpha

\]

叉积也可以写成矩阵向量相乘的形式:

\[\mathbf{P}\times \mathbf{Q} =

\left[

\begin{matrix}

0 & -P_z & P_y \\

P_z & 0 & -P_x \\

-P_y & P_x & 0

\end{matrix}

\right]

\left[

\begin{matrix}

\mathcal{Q}_x \\

\mathcal{Q}_y \\

\mathcal{Q}_z

\end{matrix}

\right]

\qquad (3)

\]

2 旋转变换 (Rotation Transforms)

先看二维空间中的旋转。

图2 x-y平面中向量P旋转90度

如上面图2,在x-y平面上把向量\(\mathbf{P} = \left \langle x, y \right \rangle\)逆时针旋转90度,变成了向量\(\mathbf{Q} = \left \langle -P_y, P_x \right \rangle = \left \langle -y, x \right \rangle\)。向量\(\mathbf{P}, \mathbf{Q}\)形成了x-y平面的一个正交基,因此我们可以用这两个向量表示x-y平面的任意向量。

图3 x-y平面中向量P旋转theta度

如上面图3,向量\(\mathbf{Q}\)是向量\(\mathbf{P}\)逆时针旋转90度后得到的向量,向量\(\mathbf{P'}\)是向量\(\mathbf{P}\)旋转\(\theta\)度得到的向量,则:

\[\mathbf{P'} = \mathbf{P}\cos\theta + \mathbf{Q}\sin\theta .

\]

\[P'_x = P_x\cos\theta - P_y\sin\theta \\

P'_y = P_y\cos\the

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值