#### Archived

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

# Quaternion To Euler

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

## Recommended Posts

How to convert/extract a quaternion to euler angles? thanks very much... xee..

##### Share on other sites
Go to Darwin 3D and look at the GDC papers on Inverse Kinematics (2001 i believe). He''s provided an extension to 3D which uses a Quaternion to Euler function but it''s a bit messy. However, it''s te only on I could find.

Sander Maréchal

GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

##### Share on other sites
Why would you want to? Not to start a quaternion/euler debate, but it should be pointed out that rotations on 2 axii(sp) (the 3rd axis having no rotation value specified) converted to a quaternion and then back will result in a rotation on all 3 axii. This is because there are obviously several sets of euler angles that achieve the same quaternion. I''d be interested in knowing how to solve for the other sets, if someone has a bright idea. I''m sure I could figure it out, in time.

I could post my function for doing this conversion, if you wanted.

##### Share on other sites
I went to Darwin3D to see if what they had was close enough to what I had, because I remember reading about it on Darwin3D when I was researching the same problem.

Darwin3D's code:
http://www.darwin3d.com/gamedev/quat2eul.cpp

the Code I'm using, based on a few different snippets I've seen but modified for my uses:
void QuatToEuler(const quat_t *quat, double *rotx,  double *roty, double *rotz){	double sqw;	double sqx;	double sqy;	double sqz;		double rotxrad;	double rotyrad;	double rotzrad;		sqw = quat->w * quat->w;	sqx = quat->x * quat->x;	sqy = quat->y * quat->y;	sqz = quat->z * quat->z;		rotxrad = (double)atan2l(2.0 * ( quat->y * quat->z + quat->x * quat->w ) , ( -sqx - sqy + sqz + sqw ));	rotyrad = (double)asinl(-2.0 * ( quat->x * quat->z - quat->y * quat->w ));	rotzrad = (double)atan2l(2.0 * ( quat->x * quat->y + quat->z * quat->w ) , (  sqx - sqy - sqz + sqw ));		*rotx = rad2deg(rotxrad);	*roty = rad2deg(rotyrad);	*rotz = rad2deg(rotzrad);		return;}

I used double because single wasn't cutting the mustard.

[edited by - Wudan on July 8, 2003 2:43:08 PM]

##### Share on other sites
quote:
Original post by Wudan
Why would you want to? Not to start a quaternion/euler debate, but it should be pointed out that rotations on 2 axii(sp) (the 3rd axis having no rotation value specified) converted to a quaternion and then back will result in a rotation on all 3 axii.

Well, I''ve been playing with quaternions myself for use in Inverse Kinematics and I have come across one good reason to convert back to eulers. You''re right, it''s ugly but I could not find any other way.

In my IK implementation I needed to limit the degrees of freedom of joints, represented by quaternions (like the IK papers at Darwin3D). I needed to limit the rotation around the X and Z axis to 25 degrees and around the Y axis to 15 degrees (I was making a 16 bone tentacle. Realtime 3D IK).

If you can figure out how to do this while staying in quaternion space then you''re my absolute hero I had to convert to Eulers, limit the DOF''s, and convert back to quaternions. Very messy, and it didn''t work properly.

Sander Maréchal

GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

##### Share on other sites
wudan: in what order is this euler system

xrot->yrot->zrot ? or a different way?

I''m also interested in gerenating a matrix from these euler angles.

earx

##### Share on other sites
AP: That''s the problem with Eulers. You don''t know the order. IIRC there are 6 or 12 different possibilities and you don''t know which one you need to get the correct rotation. Most people however just choose one order (usually xyz or zyx) and stick with it, which will give you gimble lock. Hence quaternions and matrices. Quaternions are slightly better though because they can be calculated faster and are numerically more stable.

Sander Maréchal

GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

##### Share on other sites
The order I use is XYZ. I wrote an animation scripting system that generates quats from euler angles, and from quats to euler angles, which is where I realized the true nature of the Gimbal problem. There''s oodles of papers about it if you Google it.

##### Share on other sites
wudan: thanx. i will also do some googling.

earx

##### Share on other sites
Hey Sander, is any of your IK stuff open-source? I''m working on an IK demo just so I can learn how to do it...What you are doing sounds kinda similar, so if you have anything for me I''d appreciate it!

Brian J
DL Vacuum - A media file organizer I made | Mumbling Miles - A band I was the guitarist/vocalist for

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007538
• ### Who's Online (See full list)

There are no registered users currently online

×