Conversion between quaternions and Euler angles: Difference between revisions

Content deleted Content added
Replace all q_0/1/2/3 with q_w/x/y/z (vector rotation section needs some work)
Vector rotation: Use consistent notation for the vector rotation section "Q = (Q_w,vec(Q))" hope I got it right
Line 261:
== Vector rotation ==
 
Let us define scalar <math>q_0q_w</math> and vector <math>\vec{q}</math> such that <math>\mathbf{q} = (q_0q_w,\vec{q}) = q_0q_w+iq_x+jq_y+kq_z</math>.
 
Note that the canonical way to rotate a three-dimensional vector <math>\vec{v}</math> by a quaternion <math>q</math> defining an [[#Conversion|Euler rotation]] is via the formula
:<math>\mathbf{pv}^{\,\prime} = \mathbf{qpqqvq}^\ast</math>
where <math>\mathbf{pv} = (0,\vec{v}) = 0+iv_x+jv_y+kv_z</math> is a quaternion containing the embedded vector <math>\vec{v}</math>, <math>\mathbf{q}^\ast=(q_0q_w,-\vec{q})</math> is a [[Quaternion#Conjugation, the norm, and reciprocal|conjugate quaternion]], and <math>\mathbf{pv}^{\,\prime} = (0,\vec{v}^{\,\prime})</math> is the rotated vector <math>\vec{v}^{\,\prime}</math>. In computational implementations this requires two quaternion multiplications. An alternative approach is to apply the pair of relations
:<math>\vec{t} = 2\vec{q} \times \vec{v}</math>
:<math>\vec{v}^{\,\prime} = \vec{v} + q_0q_w \vec{t} + \vec{q} \times \vec{t}</math>
where <math>\times</math> indicates a three-dimensional vector cross product. This involves fewer multiplications and is therefore computationally faster. Numerical tests indicate this latter approach may be up to 30% <ref>{{cite journal |pmc=4435132|year=2015|last1=Janota|first1=A|title=Improving the Precision and Speed of Euler Angles Computation from Low-Cost Rotation Sensor Data|journal=Sensors|volume=15|issue=3|pages=7016–7039|last2=Šimák|first2=V|last3=Nemec|first3=D|last4=Hrbček|first4=J|doi=10.3390/s150307016|pmid=25806874|bibcode=2015Senso..15.7016J |doi-access=free}}</ref> faster than the original for vector rotation.
 
Line 274:
:<math>
\begin{align}
\mathbf{q_xq_yp q} & = (r_1p_w,\vec{vp}_x)(r_2q_w,\vec{vq}_y) \\
& = (r_1p_w r_2q_w - \vec{vp}_x \cdot \vec{vq}_y, r_1p_w \vec{vq}_z + r_2q_w \vec{vp}_x +
\vec{vp}_x \times \vec{vq}_y) \\
\end{align}
</math>
Using this relation one finds for <math>\mathbf{pv} = (0,\vec{v})</math> that
:<math>
\begin{align}
\mathbf{pv q^\ast} & = (0,\vec{v})(q_0q_w,-\vec{q}) \\
& = (\vec{v} \cdot \vec{q}, q_0q_w \vec{v} - \vec{v} \times \vec{q}) \\
\end{align}
</math>
Line 289:
:<math>
\begin{align}
\mathbf{q pv q^\ast} & = (q_0q_w,\vec{q})(\vec{v} \cdot \vec{q}, q_0q_w \vec{v} - \vec{v} \times \vec{q}) \\
& = (0, q_0q_w^2 \vec{v} + q_0q_w \vec{q} \times \vec{v} + (\vec{v} \cdot \vec{q}) \vec{q} + q_0q_w \vec{q} \times \vec{v} +
\vec{q}\times(\vec{q}\times\vec{v} )) \\
\end{align}
</math>
where anti-commutivity of cross product and <math>\vec{q}\cdot \vec{v} \times \vec{q} = 0</math> has been applied. By next exploiting the property that <math>\mathbf{q}</math> is a [[#Definition|unit quaternion]] so that <math>q_0q_w^2 = 1 - \vec{q}\cdot\vec{q}</math>, along with the standard vector identity
:<math>
\vec{q}\times(\vec{q}\times\vec{v}) = (\vec{q}\cdot\vec{v})\vec{q} - (\vec{q}\cdot\vec{q})\vec{v}
Line 301:
:<math>
\begin{align}
\mathbf{pv}^\prime & = \mathbf{q pv q^\ast} = (0, \vec{v} + 2 q_0q_w \vec{q} \times \vec{v} +
2\vec{q}\times (\vec{q}\times\vec{v} )) \\
\end{align}
Line 307:
which upon defining <math>\vec{t} = 2\vec{q} \times \vec{v}</math> can be written in terms of scalar and vector parts as
:<math>
(0, \vec{v}^{\,\prime}) = (0, \vec{v} + q_0q_w \vec{t} + \vec{q} \times \vec{t} ).
</math>