Jump to content
  • Advertisement

Archived

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

cmdkeen

Quaternion interpolation isssue

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

Hello, when using quaternions for rotations I faced a problem: when I interpolate between two quaternions with different axes the path of the rotated object is buckled. Example: when I have a rotation with axis = (0, 0, 1) and 90 degree and rotate to (1, 0, 0) and 180 degree I run through the inbetween states (1/3, 0, 2/3), 120 and (2/3, 0, 1/3), 150. Thus the path of the rotation is not straight.. I interpolate between the two quaternions by interpolating the angle and the axis independently and then creating a new quaternion from the result. I thought about the problem and came to the conclusion that this follows directly from the involved math. It seems to be a consequence of the interpolation between both axes. Has anyone an idea how to fix this? [Edited by - cmdkeen on May 19, 2008 8:32:08 PM]

Share this post


Link to post
Share on other sites
Advertisement
OK, I only really know enough about quats to get me by, but heres some ideas:

you say you interpolate the axis and angle independantly - thats probably where the problem is. Just interpolate the quat directly (not that I can tell you how to that! but check out the code in the docs at http://math3d.sf.net for ideas). As far as I know the fact the the quat is 4d is what lets it represent orderless rotations, and be interpolated smoothly.

Oh yeah, might want to look at spherical interpolation rather than linear. Again I know enough to use use them, but couldn''t exaplin how to implement them.

Share this post


Link to post
Share on other sites
Something like this:

inline void EQuat::SLerp(EQuat *out, EQuat *q2, float ratio)
{
float omega, cosom, sinom, scale0, scale1;

// calc cosine

cosom = x * q2->x + y * q2->y + z * q2->z + w * q2->w;

// adjust signs (if necessary)

if ( cosom < 0.0 )
{
cosom = -cosom;
scale1 = -1.0f;
}
else
{
scale1 = 1.0f;
}

if ( (1.0 - cosom) > 0.0001f/*DELTA*/ )
{
// standard case (slerp)

omega = acosf(cosom);
sinom = sinf(omega);
scale0 = sinf((1.0f - ratio) * omega) / sinom;
scale1 *= sinf(ratio * omega) / sinom;
}
else
{
// "from" and "to" quaternions are very close

// ... so we can do a linear interpolation

scale0 = 1.0f - ratio;
scale1 *= ratio;
}

// calculate final values

out->x = (EFloat) (scale0 * x + scale1 * q2->x);
out->y = (EFloat) (scale0 * y + scale1 * q2->y);
out->z = (EFloat) (scale0 * z + scale1 * q2->z);
out->w = (EFloat) (scale0 * w + scale1 * q2->w);
}

Share this post


Link to post
Share on other sites
And if you use it only for animation you can try the linear interpolation (it is approximately like SLERP), it is a lot faster.

inline xxquaternion lerp_unit(const xxquaternion& q1, const xxquaternion& q2, float t ){
xxquaternion r;
float inner = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z +q1.w*q2.w;
if(inner < 0 ){
r = q1 - (q2+q1)*t;
}else{
r = q1 + (q2-q1)*t;
}
r.normalize();
return r;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!