• 14
• 12
• 9
• 10
• 13

quaternion multiplication problem

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

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]	);
}



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.]