Conversion between quaternions and Euler angles: Difference between revisions

Content deleted Content added
Vector rotation: Remove irrelevent mention of ijk
The set of equations using "arctan" is wrong and should be removed to avoid confusion with the correct "atan2" implementation. Example of new paper citing the incorrect equations because of Wikipedia: https://www.sciencedirect.com/science/article/pii/S0926580523003400?via%3Dihub
Line 191:
A direct formula for the conversion from a quaternion to Euler angles in any of the 12 possible sequences exists.<ref>{{cite journal |last1=Bernardes |first1=Evandro |last2=Viollet |first2=Stéphane |title=Quaternion to Euler angles conversion: A direct, general and computationally efficient method |journal=PLOS ONE |date=10 November 2022 |volume=17 |issue=11 |pages=e0276302 |doi=10.1371/journal.pone.0276302 |pmid=36355707 |pmc=9648712 |bibcode=2022PLoSO..1776302B |language=en |issn=1932-6203|doi-access=free }}</ref> For the rest of this section, the formula for the sequence '''Body 3-2-1''' will be shown.
If the quaternion is properly '''normalized''', the Euler angles can be obtained from the quaternions via the relations:
 
:<math>\begin{bmatrix}
\phi \\ \theta \\ \psi
\end{bmatrix} =
\begin{bmatrix}
\mbox{arctan} \left(\dfrac {2(q_w q_x + q_y q_z)} {1 - 2(q_x^2 + q_y^2)}\right)\\
- \pi/2 + 2 \, \mbox{arctan} \sqrt{\dfrac {1 + 2(q_w q_y - q_x q_z)} {1 - 2(q_w q_y - q_x q_z)}} \\
\mbox{arctan} \left(\dfrac {2(q_w q_z + q_x q_y)} {1 - 2(q_y^2 + q_z^2)}\right)
\end{bmatrix} </math>
 
However the [[arctan]] functions implemented in computer languages only produce results between −π/2 and [[right angle|π/2]], to generate all the orientations one needs to replace the arctan functions in computer code by [[atan2]]:
 
:<math>\begin{bmatrix}
Line 212 ⟶ 201:
\end{bmatrix} </math>
 
HoweverNote that the [[arctan]] functions implemented in computer languages only produce results between −π/2 and [[right angle|π/2]], which is why [[atan2]] is used to generate all the correct orientations. oneMoreover, needstypical toimplementations replace theof arctan functionsalso inmight computerhave codesome bynumerical disadvantages near zero and one. [[atan2]]:
Moreover, typical implementations of arctan also might have some numerical disadvantages near zero and one. Some implementations use the equivalent expression:<ref>{{cite journal|last1=Blanco|first1=Jose-Luis|title=A tutorial on se (3) transformation parameterizations and on-manifold optimization|journal=University of Malaga, Tech. Rep|date=2010|citeseerx=10.1.1.468.5407}}</ref>
 
Moreover, typical implementations of arctan also might have some numerical disadvantages near zero and one. Some implementations use the equivalent expression:<ref>{{cite journal|last1=Blanco|first1=Jose-Luis|title=A tutorial on se (3) transformation parameterizations and on-manifold optimization|journal=University of Malaga, Tech. Rep|date=2010|citeseerx=10.1.1.468.5407}}</ref>
:<math> \theta = \mbox{arcsin} (2(q_w q_y - q_x q_z)) </math>