Extracting Euler angles from a quaternion

Started by
0 comments, last by Prospero 21 years, 3 months ago
Hi all, I'm looking for a way (and preferably a really easy-to-follow code example) to *RELIABLY AND ACCURATELY* extract Euler angles from a quaternion. For reference, I am using standard aeronautical convention. Hence I am working in exclusively right-handed coordinate frames where my Euler angle rotation order is yaw, then pitch, then roll. Here is a brief summary of the method I am using at the moment, showing the main problem with it: From reading on the net, and from books like "Aircraft Control and Simulation" by Stevens, I first take the attitude quaternion and build from it the 3x3 direction cosine matrix. So, let's say my attitude quaternion consists of elements _q1, _q2, _q3 and _q4. Having normalized the quaternion in the standard way, the direction cosine matrix would be built like this: _m11 = _q1^2 + _q2^2 - _q3^2 - _q4^2 _m12 = 2 * (_q2 * _q3 + _q1 * _q4) _m13 = 2 * (_q2 * _q4 - _q1 * _q3) _m23 = 2 * (_q3 * _q4 + _q1 * _q2) _m33 = _q1^2 - _q2^2 - _q3^2 + _q4^2 Note that I have only bothered to build those elements of the matrix I will need. And I'm not trying to optimize the code in any way. For now, that's besides the point. OK. Now, the Euler angles can be determined like this: _roll = _m23 atan2 _m33 _pitch = asin(-_m13) _yaw = _m12 atan2 _m11 Which is all fine and dandy, but what if the divisors _m33 or _m11 in the atan2 functions are zero (or very very close to being zero). This happens when the aircraft's nose is pointing either straight up or straight down. I simply can't visualize what sort of divide-by-zero trap to make - because we're talking about quaternions! Some people seem to think it's just not worth bothering about this (owing to the statistical improbability of the aircraft's nose pointing straight up or straight down) - but what if I want to initialize the aircraft flight-model with such an attitude? I'd be scuppered. So my question (or rather, plea) is to ask whether some nice person could tell me what to do Pretty please! I need an accurate and reliable quaternion to Euler angle conversion under ALL circumstances, and preferably a method that works for the right-handed conventions I'm using (because I'm very dumb). Thanks and best regards, Anthony [edited by - Prospero on January 19, 2003 12:13:22 PM] [edited by - Prospero on January 19, 2003 12:20:10 PM] [edited by - Prospero on January 19, 2003 4:12:10 PM]
Advertisement
Hmmm. I would recommend that you take a look at source code and documentation from Dave Eberly @:

www.magic-software.com

In particular, these documents:

www.magic-software.com/Documentation/EulerAngles.pdf

www.magic-software.com/Documentation/RotationIssues.pdf

He doesn''t answer your question directly, but you can use his (free) quaternion and matrix source code to get the result, e.g., convert the quaternion to a rotation matrix and extract Euler angles from the rotation matrix.



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement