Sign in to follow this  

quaternions and heading

This topic is 3463 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

I have created a rotation of a model with quaternions. (with 6dof) Now, I want to move it along the direction it is heading. I use the following formulas to find out what heading, pitch and roll are: roll = atan2(2.0 * (local_x * local_y + local_z * local_w),(sq_x - sq_y - sq_z + sq_w)) ; heading = asin(-2.0 * (local_x * local_z - local_y * local_w)); pitch = atan2(2.0 * (local_y * local_z + local_x * local_w),(-sq_x - sq_y + sq_z + sq_w)); My problem is that there appears to be something wrong with this. For instance when I change the heading by more then 90 degrees, both pitch and roll instantly change 180 degrees. Also, when using pitch to rotate 180 degrees (upside down) the heading remains same. Is there something wrong with my fomula's, or is there something else I am mistaking about? (or am I going about it the wrong way completely and is there an easier way to move along the models heading?) Thank you for any insight!

Share this post


Link to post
Share on other sites
Why are you trying to extract the Euler angles from the quaternion? Rotate the orientation vector of the object by the quaternion and move the object along the result.

Share this post


Link to post
Share on other sites
I dont know how to change the orientation vector... :$

Is it then also possible to know the x,y,z position in the world? I would expect this to be necessary to perform distance calculations between objects?

Thank you for your fast reply

Share this post


Link to post
Share on other sites
Quote:
Original post by Locutusborg
I dont know how to change the orientation vector... :$

Quaternion q(blah, blah, blah);
Vector new_heading = q * old_heading * ~q;
Quote:
Is it then also possible to know the x,y,z position in the world? I would expect this to be necessary to perform distance calculations between objects?

Vector new_position = old_position + (heading * velocity);

Share this post


Link to post
Share on other sites
When I try to multiply a vector and a quaternion, I get an error:

error C2678: binary '*' : no operator found which takes a left-hand operand of type 'D3DXQUATERNION' (or there is no acceptable conversion)

Did I do something wrong?
also, what do you mean by ~q? Is that the inverse quaternion?
thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Locutusborg
When I try to multiply a vector and a quaternion, I get an error:

error C2678: binary '*' : no operator found which takes a left-hand operand of type 'D3DXQUATERNION' (or there is no acceptable conversion)

Did I do something wrong?
also, what do you mean by ~q? Is that the inverse quaternion?
thanks
Typically the 'v' in 'q*v*~q' is converted to quaternion form by setting the imaginary part to the vector you want to rotate and the real part to zero. As for ~, it refers to the conjugate (which, for a unit-length quaternion, returns the same value as the inverse).

Usually though you don't need to perform 'manual' quaternion rotation of vectors to do what you're wanting. Assuming the object moves along the cardinal basis vectors in local space ([1,0,0], [0,1,0], [0,0,1]), you can simply convert the orientation quaternion to a matrix and extract the direction vectors therefrom.

Share this post


Link to post
Share on other sites

This topic is 3463 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.

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