views:

76

answers:

2

I use slerp to interpolate between two quaternions representing rotations. The resulting rotation is then extracted as Euler angles to be fed into a graphics lib. This kind of works, but I have the following problem; when rotating around two (one works just fine) axes in the direction of the green arrow as shown in the left frame

here

the rotation soon jumps around to rotate from the opposite site to the opposite visual direction, as indicated by the red arrow in the right frame.

This may be logical from a mathematical perspective (although not to me), but it is undesired. How could I achieve an interpolation with no visual flipping and changing of directions when rotating around more than one axis, following the green arrow at all times until the interpolation is complete?

Thanks in advance.

+2  A: 

Your description of the problem is a little hard to follow, quite frankly. But it sounds like you need to negate one of your quaternions.

Remember, each rotation can actually be represented by two quaternions, q and -q. But the Slerp path from q to w will be different from the path from (-q) to w: one will go the long away around, the other the short away around. It sounds like you're getting the long way when you want the short way.

Try taking the dot product of your two quaternions (i.e., the 4-D dot product), and if the dot product is negative, replace your quaterions q1 and q2 with -q1 and q2 before performing Slerp.

Peter Milley
If I recall correctly, this can be avoided by keeping your quaternions normalized.
Alan
Normalization has nothing to do with this; both q and -q have the same magnitude. Normalizing only keeps q from scaling the object in addition to rotating it.I think Peter's interpretation of the question is correct. When slerping between two rotations q0 qnd q1, Dot(q0, q1) must be positive. If not, replace q1 with -q1.
SuperElectric
A: 

How far is the total rotation? You may be asking for an interpolation for two orientation too far apart in angle. The math, quaternions or not, has trouble deciding which way to go, in a sense. Like not having enough keyframes in animation.

Determine a good intermediate orientation about halfway along, and make separate interpolations from the initial orientation to that intermediate one, and from the intermediate to the final.

DarenW