旋转向量_旋转矩阵_四元数_欧拉角

6 篇文章 1 订阅

0.引言

经常查,总结一下。推导看原论文。

1.旋转矩阵与旋转向量

1.1.旋转向量转旋转矩阵(指数映射)

旋转向量(角速度乘以 Δ t \Delta t Δt
v = ω Δ t = ϕ u \mathbf{v}=\boldsymbol{\omega} \Delta t=\phi \mathbf{u} v=ωΔt=ϕu旋转向量转旋转矩阵,指数映射: Exp ⁡ ( v ) ≜ exp ⁡ ( [ v ] × ) \operatorname{Exp}(\mathbf{v}) \triangleq \exp \left([\mathbf{v}]_{\times}\right) Exp(v)exp([v]×)即是: R = e ϕ [ u ] × = I + ϕ [ u ] × + 1 2 ϕ 2 [ u ] × 2 + 1 3 ! ϕ 3 [ u ] × 3 + 1 4 ! ϕ 4 [ u ] × 4 + … \mathbf{R}=e^{\phi[\mathbf{u}]_{\times}}=\mathbf{I}+\phi[\mathbf{u}]_{\times}+\frac{1}{2} \phi^{2}[\mathbf{u}]_{\times}^{2}+\frac{1}{3 !} \phi^{3}[\mathbf{u}]_{\times}^{3}+\frac{1}{4 !} \phi^{4}[\mathbf{u}]_{\times}^{4}+\ldots R=eϕ[u]×=I+ϕ[u]×+21ϕ2[u]×2+3!1ϕ3[u]×3+4!1ϕ4[u]×4+整理得(罗德里格斯公式):
R = I cos ⁡ ϕ + [ u ] × sin ⁡ ϕ + u u ⊤ ( 1 − cos ⁡ ϕ ) \mathbf{R}=\mathbf{I} \cos \phi+[\mathbf{u}]_{\times} \sin \phi+\mathbf{u u}^{\top}(1-\cos \phi) R=Icosϕ+[u]×sinϕ+uu(1cosϕ)

1.2.旋转矩阵转旋转向量(对数映射)

log ⁡ : S O ( 3 ) → s o ( 3 ) ; R ↦ log ⁡ ( R ) = [ u ϕ ] × \log : S O(3) \rightarrow \mathfrak{s o}(3) ; \mathbf{R} \mapsto \log (\mathbf{R})=[\mathbf{u} \phi]_{\times} log:SO(3)so(3);Rlog(R)=[uϕ]× log ⁡ ( R ) ≜ ( log ⁡ ( R ) ) ∨ \log (\mathbf{R}) \triangleq(\log (\mathbf{R}))^{\vee} log(R)(log(R)) ϕ = arccos ⁡ ( trace ⁡ ( R ) − 1 2 ) \phi=\arccos \left(\frac{\operatorname{trace}(\mathbf{R})-1}{2}\right) ϕ=arccos(2trace(R)1) u = ( R − R ⊤ ) ∨ 2 sin ⁡ ϕ \mathbf{u}=\frac{\left(\mathbf{R}-\mathbf{R}^{\top}\right)^{\vee}}{2 \sin \phi} u=2sinϕ(RR)

2.四元数与旋转向量

2.1.旋转向量转四元数(指数映射)

旋转向量(角速度乘以 Δ t \Delta t Δt
v = ω Δ t = ϕ u \mathbf{v}=\boldsymbol{\omega} \Delta t=\phi \mathbf{u} v=ωΔt=ϕu
指数运算(为啥要除以2参考原论文推导):
Exp ⁡ ( v ) ≜ exp ⁡ ( v / 2 ) \operatorname{Exp}(\mathbf{v}) \triangleq \exp (\mathbf{v} / 2) Exp(v)exp(v/2) q ≜ Exp ⁡ ( ϕ u ) = e ϕ u / 2 = cos ⁡ ϕ 2 + u sin ⁡ ϕ 2 = [ cos ⁡ ( ϕ / 2 ) u sin ⁡ ( ϕ / 2 ) ] \mathbf{q} \triangleq \operatorname{Exp}(\phi \mathbf{u})=e^{\phi \mathbf{u} / 2}=\cos \frac{\phi}{2}+\mathbf{u} \sin \frac{\phi}{2}=\left[\begin{array}{c} \cos (\phi / 2) \\ \mathbf{u} \sin (\phi / 2) \end{array}\right] qExp(ϕu)=eϕu/2=cos2ϕ+usin2ϕ=[cos(ϕ/2)usin(ϕ/2)]即是: q = [ cos ⁡ ϕ 2 , u x sin ⁡ ϕ 2 , u y sin ⁡ ϕ 2 , u z sin ⁡ ϕ 2 ] T q=\left[\cos \frac{\phi}{2}, u_{x} \sin \frac{\phi}{2}, u_{y} \sin \frac{\phi}{2}, u_{z} \sin \frac{\phi}{2}\right]^{T} q=[cos2ϕ,uxsin2ϕ,uysin2ϕ,uzsin2ϕ]T

2.2.四元数转旋转向量(对数映射)

log ⁡ : S 3 → H p ; q ↦ log ⁡ ( q ) = u θ \log : S^{3} \rightarrow \mathbb{H}_{p} ; \mathbf{q} \mapsto \log (\mathbf{q})=\mathbf{u} \theta log:S3Hp;qlog(q)=uθ log ⁡ ( q ) ≜ 2 log ⁡ ( q ) \log (\mathbf{q}) \triangleq 2 \log (\mathbf{q}) log(q)2log(q) ϕ = 2 arctan ⁡ ( ∥ q v ∥ , q w ) u = q v / ∥ q v ∥ \begin{aligned} \phi &=2 \arctan \left(\left\|\mathbf{q}_{v}\right\|, q_{w}\right) \\ \mathbf{u} &=\mathbf{q}_{v} /\left\|\mathbf{q}_{v}\right\| \end{aligned} ϕu=2arctan(qv,qw)=qv/qv

3.四元数与旋转矩阵

q ⊗ x ⊗ q ∗ = R x \mathbf{q} \otimes \mathbf{x} \otimes \mathbf{q}^{*}=\mathbf{R} \mathbf{x} qxq=Rx

3.1.四元数转旋转矩阵

q ⊗ x ⊗ q ∗ = [ q ∗ ] R [ q ] L [ 0 x ] = [ 0 R x ] \mathbf{q} \otimes \mathbf{x} \otimes \mathbf{q}^{*}={\left[\mathbf{q}^{*}\right]_{R}[\mathbf{q}]_{L}}\left[\begin{array}{l} 0 \\ \mathbf{x} \end{array}\right]=\left[\begin{array}{c} 0 \\ \mathbf{R} \mathbf{x} \end{array}\right] qxq=[q]R[q]L[0x]=[0Rx]

R = [ 1 − 2 q 2 2 − 2 q 3 2 2 q 1 q 2 + 2 q 0 q 3 2 q 1 q 3 − 2 q 0 q 2 2 q 1 q 2 − 2 q 0 q 3 1 − 2 q 1 2 − 2 q 3 2 2 q 2 q 3 + 2 q 0 q 1 2 q 1 q 3 + 2 q 0 q 2 2 q 2 q 3 − 2 q 0 q 1 1 − 2 q 1 2 − 2 q 2 2 ] \boldsymbol{R}=\left[\begin{array}{ccc} 1-2 q_{2}^{2}-2 q_{3}^{2} & 2 q_{1} q_{2}+2 q_{0} q_{3} & 2 q_{1} q_{3}-2 q_{0} q_{2} \\ 2 q_{1} q_{2}-2 q_{0} q_{3} & 1-2 q_{1}^{2}-2 q_{3}^{2} & 2 q_{2} q_{3}+2 q_{0} q_{1} \\ 2 q_{1} q_{3}+2 q_{0} q_{2} & 2 q_{2} q_{3}-2 q_{0} q_{1} & 1-2 q_{1}^{2}-2 q_{2}^{2} \end{array}\right] R=12q222q322q1q22q0q32q1q3+2q0q22q1q2+2q0q312q122q322q2q32q0q12q1q32q0q22q2q3+2q0q112q122q22 R = ( q w 2 − ( q v ⊤ q ) ) I + 2 q v q v ⊤ + 2 q w [ q v ] × \mathbf{R}=\left(q_{w}^{2}-\left(\mathbf{q}_{v}^{\top} \mathbf{q}_{\mathbf{}}\right)\right) \mathbf{I}+2 \mathbf{q}_{v} \mathbf{q}_{v}^{\top}+2 q_{w}\left[\mathbf{q}_{v}\right]_{\times} R=(qw2(qvq))I+2qvqv+2qw[qv]×

3.2.旋转矩阵转四元数

q 0 = tr ⁡ ( R ) + 1 2 , q 1 = m 23 − m 32 4 q 0 , q 2 = m 31 − m 13 4 q 0 , q 3 = m 12 − m 21 4 q 0 q_{0}=\frac{\sqrt{\operatorname{tr}(R)+1}}{2}, q_{1}=\frac{m_{23}-m_{32}}{4 q_{0}}, q_{2}=\frac{m_{31}-m_{13}}{4 q_{0}}, q_{3}=\frac{m_{12}-m_{21}}{4 q_{0}} q0=2tr(R)+1 ,q1=4q0m23m32,q2=4q0m31m13,q3=4q0m12m21

4.欧拉角与旋转矩阵

4.1.欧拉角转旋转矩阵

某次旋转绕固定坐标轴X-Y-Z旋转(γ,β,α)或者说绕自身坐标轴Z-Y-X旋转(α,β,γ),对应的旋转矩阵如下

R = R Z ( α ) R Y ( β ) R X ( γ ) = ( c o s α c o s β c o s α s i n β s i n γ − s i n α c o s γ c o s α s i n β c o s γ + s i n α s i n γ s i n α c o s β c o s α c o s γ + s i n α s i n β s i n γ s i n α s i n β c o s γ − s i n γ c o s α − s i n β c o s β s i n γ c o s β c o s γ ) R = R_{Z}(\alpha)R_{Y}(\beta)R_{X}(\gamma)=\begin{pmatrix} cos\alpha cos\beta & cos\alpha sin\beta sin\gamma - sin\alpha cos\gamma & cos\alpha sin\beta cos\gamma + sin\alpha sin\gamma\\ sin\alpha cos\beta & cos\alpha cos\gamma + sin\alpha sin\beta sin\gamma & sin\alpha sin\beta cos\gamma - sin\gamma cos\alpha\\ -sin\beta & cos\beta sin\gamma & cos\beta cos\gamma \end{pmatrix} R=RZ(α)RY(β)RX(γ)=cosαcosβsinαcosβsinβcosαsinβsinγsinαcosγcosαcosγ+sinαsinβsinγcosβsinγcosαsinβcosγ+sinαsinγsinαsinβcosγsinγcosαcosβcosγ

4.2.旋转矩阵转欧拉角

有旋转矩阵

R = ( r 11 r 12 r 13 r 21 r 22 r 23 r 31 r 32 r 33 ) R=\begin{pmatrix} r_{11} & r_{12} & r_{13}\\ r_{21} & r_{22} & r_{23}\\ r_{31} & r_{32} & r_{33} \end{pmatrix} R=r11r21r31r12r22r32r13r23r33

可求出各轴的旋转角为

θ Z = a t a n 2 ( r 21 , r 11 ) θ Y = a t a n 2 ( − r 31 , r 31 2 + r 33 2 ) θ X = a t a n 2 ( r 32 , r 33 ) \begin{matrix} \theta_{Z}= atan2(r_{21},r_{11})\\ \theta_{Y}= atan2(-r_{31},\sqrt{r_{31}^{2}+r_{33}^{2}})\\ \theta_{X}= atan2(r_{32},r_{33}) \end{matrix} θZ=atan2(r21,r11)θY=atan2(r31,r312+r332 )θX=atan2(r32,r33)

atan2为C++中函数,atan2(y,x)的做法:当 x 的绝对值比 y 的绝对值大时使用 atan(y/x);反之使用 atan(x/y)。这样就保证了数值稳定性。需要注意的是,旋转顺序必须要是Z、Y、X。

5.欧拉角与四元数

5.1.欧拉角转四元素

将Z-Y-X欧拉角(或RPY角:绕固定坐标系的X-Y-Z依次旋转α,β,γ角)转换为四元数:

q = ( q 0 q 1 q 2 q 3 ) = ( c o s ( α 2 ) c o s ( β 2 ) c o s ( γ 2 ) + s i n ( α 2 ) s i n ( β 2 ) s i n ( γ 2 ) s i n ( α 2 ) c o s ( β 2 ) c o s ( γ 2 ) − c o s ( α 2 ) s i n ( β 2 ) s i n ( γ 2 ) c o s ( α 2 ) s i n ( β 2 ) c o s ( γ 2 ) + s i n ( α 2 ) c o s ( β 2 ) s i n ( γ 2 ) c o s ( α 2 ) c o s ( β 2 ) s i n ( γ 2 ) − s i n ( α 2 ) s i n ( β 2 ) c o s ( γ 2 ) ) \textbf{q}=\begin{pmatrix} q_{0}\\ q_{1}\\ q_{2}\\ q_{3} \end{pmatrix}=\begin{pmatrix} cos(\frac{\alpha}{2})cos(\frac{\beta}{2})cos(\frac{\gamma}{2})+sin(\frac{\alpha}{2})sin(\frac{\beta}{2})sin(\frac{\gamma}{2})\\ sin(\frac{\alpha}{2})cos(\frac{\beta}{2})cos(\frac{\gamma}{2})-cos(\frac{\alpha}{2})sin(\frac{\beta}{2})sin(\frac{\gamma}{2})\\ cos(\frac{\alpha}{2})sin(\frac{\beta}{2})cos(\frac{\gamma}{2})+sin(\frac{\alpha}{2})cos(\frac{\beta}{2})sin(\frac{\gamma}{2})\\ cos(\frac{\alpha}{2})cos(\frac{\beta}{2})sin(\frac{\gamma}{2})-sin(\frac{\alpha}{2})sin(\frac{\beta}{2})cos(\frac{\gamma}{2}) \end{pmatrix} q=q0q1q2q3=cos(2α)cos(2β)cos(2γ)+sin(2α)sin(2β)sin(2γ)sin(2α)cos(2β)cos(2γ)cos(2α)sin(2β)sin(2γ)cos(2α)sin(2β)cos(2γ)+sin(2α)cos(2β)sin(2γ)cos(2α)cos(2β)sin(2γ)sin(2α)sin(2β)cos(2γ)

5.2.四元数转欧拉角

由四元数 q = ( q 0 , q 1 , q 2 , q 3 ) q=(q0,q1,q2,q3) q=(q0,q1,q2,q3) q = ( w , x , y , z ) q=(w,x,y,z) q=(w,x,y,z) 到欧拉角的转换为

α = a r c t a n ( 2 ( q 0 q 1 + q 2 q 3 ) 1 − 2 ( q 1 2 + q 2 2 ) ) β = a r c s i n ( 2 ( q 0 q 2 − q 1 q 3 ) ) γ = a r c t a n ( 2 ( q 0 q 3 + q 1 q 2 ) 1 − 2 ( q 2 2 + q 3 2 ) ) \alpha = arctan(\frac{2(q_{0}q_{1}+q_{2}q_{3})}{1-2(q_{1}^{2}+q_{2}^{2})})\\ \beta = arcsin(2(q_{0}q_{2}-q_{1}q_{3}))\\ \gamma = arctan(\frac{2(q_{0}q_{3}+q_{1}q_{2})}{1-2(q_{2}^{2}+q_{3}^{2})}) α=arctan(12(q12+q22)2(q0q1+q2q3))β=arcsin(2(q0q2q1q3))γ=arctan(12(q22+q32)2(q0q3+q1q2))

由于arctan和arcsin的取值范围在−π/2 - π/2之间,只有180°,而绕某个轴旋转时范围是360°,因此要使用atan2函数代替arctan函数。

α = a t a n 2 ( 2 ( q 0 q 1 + q 2 q 3 ) , 1 − 2 ( q 1 2 + q 2 2 ) ) β = a r c s i n ( 2 ( q 0 q 2 − q 1 q 3 ) ) γ = a t a n 2 ( 2 ( q 0 q 3 + q 1 q 2 ) , 1 − 2 ( q 2 2 + q 3 2 ) ) \alpha = atan2(2(q_{0}q_{1}+q_{2}q_{3}),1-2(q_{1}^{2}+q_{2}^{2}))\\ \beta = arcsin(2(q_{0}q_{2}-q_{1}q_{3}))\\ \gamma = atan2(2(q_{0}q_{3}+q_{1}q_{2}),1-2(q_{2}^{2}+q_{3}^{2})) α=atan2(2(q0q1+q2q3),12(q12+q22))β=arcsin(2(q0q2q1q3))γ=atan2(2(q0q3+q1q2),12(q22+q32))
最后这个网站 可以动态展示四元数与欧拉角的对应关系和变化情况,便于理解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值