Sign in to follow this  

quaternion multiplication problem

This topic is 4383 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, I want to rotate a vector v with a quaternion q. I create a quaternion qv from v. Then I use my overloaded operator to rotate v: vrot = q*qv*qinv (all unit quaternions, qinv = q*) But the rotation doesn't work like expected. However if I write the equation like this it works: vrot = qinv*qv*q So my overloaded operator has to be wrong, right ? But I just can't find my mistake, maybe you could have a look:
[source lang='cpp']
quat quat::operator *( const quat &iq ) const
{
	return quat(	q[1]*iq[2] - q[2]*iq[1] + iq[3]*q[0] + q[3]*iq[0],
			q[2]*iq[0] - q[0]*iq[2] + iq[3]*q[1] + q[3]*iq[1],
			q[0]*iq[1] - q[1]*iq[0] + iq[3]*q[2] + q[3]*iq[2],
			q[3]*iq[3] - q[0]*iq[0] - q[1]*iq[1] - q[2]*iq[2]	);
}

Thanks for your help! quak

Share this post


Link to post
Share on other sites
At work atm so can't look at the code, but is the rotation going the opposite direction from what you expect? Quaternion multiplication can be defined one of two different ways (practically speaking), and if you got the function from a reference it may be that it doesn't match your prefered convention.

[Edit: Based on your description of the problem, it sounds like this is probably the cause. Again I'd have to look at the code more carefully to be sure, but try swapping the first two terms in the first three expressions and see if that fixes the problem.]

Share this post


Link to post
Share on other sites

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