Sign in to follow this  
remdul

euler to quaternion not working

Recommended Posts

remdul    176
Hi, Trying to convert euler angles to quaternion (see code) but doesn't seem to work properly (a rotation of 90 degrees on any axis rotates an object about ~1 degree, but never more). Can anyone spot an error?
quat EulerToQuat(const float3 &rot)
{
 const float p = PI / 180;
 float c1, s1, c2, s2, c3, s3, c1c2, s1s2;
 quat q;
 
 c1 = cos( (rot.y * p) * 0.5f);
 s1 = sin( (rot.y * p) * 0.5f);
 c2 = cos( (rot.x * p) * 0.5f);
 s2 = sin( (rot.x * p) * 0.5f);
 c3 = cos( (rot.z * p) * 0.5f);
 s3 = sin( (rot.z * p) * 0.5f);
 c1c2 = c1 * c2;
 s1s2 = s1 * s2;
 
 q.w = c1c2 * c3 - s1s2 * s3;
 q.x = c1c2 * s3 + s1s2 * c3;
 q.y = s1 * c2 * c3 + c1 * s2 * s3;
 q.z = c1 * s2 * c3 - s1 * c2 * s3;
 return q;
}
Thanks.

Share this post


Link to post
Share on other sites
remdul    176
Hmm.

I got the code from this site (nice resource btw):

http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/

So I assume the method works correctly. The only thing I added is the conversion of degrees to radians.

Perhaps that's what I'm doing wrong?


* Can someone point me to a piece of code that does the conversion and also takes in account singularities?

[Edited by - remdul on May 20, 2006 7:50:31 AM]

Share this post


Link to post
Share on other sites
remdul    176
Ack, I've got it solved. It was caused by an unrelated problem (some mixup in my matrix class).

The code I posted above is correct though.

As far as singularities concerned...doesn't seem to be a problem either.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this