设四元数为:
q
=
(
w
,
x
,
y
,
z
)
q = (w, x, y, z)
q=(w,x,y,z)
对应欧拉角为:
- 俯仰角(pitch): θ \theta θ
- 滚转角(roll): ϕ \phi ϕ
- 偏航角(yaw):
ψ
\psi
ψ
则四元数到欧拉角的转换公式为:
欧拉角到四元数
w = cos ( θ 2 ) cos ( ϕ 2 ) cos ( ψ 2 ) + sin ( θ 2 ) sin ( ϕ 2 ) sin ( ψ 2 ) x = sin ( θ 2 ) cos ( ϕ 2 ) cos ( ψ 2 ) − cos ( θ 2 ) sin ( ϕ 2 ) sin ( ψ 2 ) y = cos ( θ 2 ) sin ( ϕ 2 ) cos ( ψ 2 ) + sin ( θ 2 ) cos ( ϕ 2 ) sin ( ψ 2 ) z = cos ( θ 2 ) cos ( ϕ 2 ) sin ( ψ 2 ) − sin ( θ 2 ) sin ( ϕ 2 ) cos ( ψ 2 ) \begin{aligned} w &= \cos(\frac{\theta}{2})\cos(\frac{\phi}{2})\cos(\frac{\psi}{2}) + \sin(\frac{\theta}{2})\sin(\frac{\phi}{2})\sin(\frac{\psi}{2}) \\ x &= \sin(\frac{\theta}{2})\cos(\frac{\phi}{2})\cos(\frac{\psi}{2}) - \cos(\frac{\theta}{2})\sin(\frac{\phi}{2})\sin(\frac{\psi}{2}) \\ y &= \cos(\frac{\theta}{2})\sin(\frac{\phi}{2})\cos(\frac{\psi}{2}) + \sin(\frac{\theta}{2})\cos(\frac{\phi}{2})\sin(\frac{\psi}{2}) \\ z &= \cos(\frac{\theta}{2})\cos(\frac{\phi}{2})\sin(\frac{\psi}{2}) - \sin(\frac{\theta}{2})\sin(\frac{\phi}{2})\cos(\frac{\psi}{2}) \end{aligned} wxyz=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ψ)
四元数到欧拉角
θ = arcsin ( 2 ( w ⋅ y − z ⋅ x ) ) ϕ = arctan 2 ( 2 ( w ⋅ x + y ⋅ z ) , 1 − 2 ( x 2 + y 2 ) ) ψ = arctan 2 ( 2 ( w ⋅ z + x ⋅ y ) , 1 − 2 ( y 2 + z 2 ) ) \begin{aligned} \theta &= \arcsin(2(w \cdot y - z \cdot x)) \\ \phi &= \arctan2(2(w \cdot x + y \cdot z), 1 - 2(x^2 + y^2)) \\ \psi &= \arctan2(2(w \cdot z + x \cdot y), 1 - 2(y^2 + z^2)) \end{aligned} θϕψ=arcsin(2(w⋅y−z⋅x))=arctan2(2(w⋅x+y⋅z),1−2(x2+y2))=arctan2(2(w⋅z+x⋅y),1−2(y2+z2))