Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Extracting Euler angles from a quaternion

This topic is 5803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post

Link to post
Share on other sites
Hmmm. I would recommend that you take a look at source code and documentation from Dave Eberly @:


In particular, these documents:



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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!