Advertisement

Quaternions to rotate an object in a circle

Started by June 18, 2002 01:42 AM
0 comments, last by executor_2k2 22 years, 8 months ago
How do you do it? Im using the slerp algorithm to interpolate quaternions. A problem comes up when you are rotating a circle at a constant rate. How do I get around the fact that you cant interpolate between 2 similar quaternions? Do I just increase the angle? Thanks in advance. Well, that was a waste of 2 minutes of my life. Now I have to code faster to get ''em back...
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
You cannot interpolate between quaternions representing the same rotation, if that''s what you mean by ''similar'': you need to start with two distinct quaternions. If you''re just rotating about a known axis you can generate the quaternion directly from the axis and changing angle and this will be quicker than SLERP.

If you mean "how do you interpolate over a full circle?", e.g. go between two quaternions the long way, SLERP will do this easily if you force it to use the right quaternions. One property of quaternions is that both q and -q represent the same rotation. Normally this doesn''t matter but it does make a difference to SLERP. Interpolating between Q and q is different from between Q and -q.

The usual thing to do is choose the shortest route, bu ensuring the angle in 4D between the quaternions is < 90 degrees. This is done by calculating the inner product of Q and q, and using the property

Q.q = |Q| |q| cos a

the angle is < 90 if Q.q is positive. If it is negative -q is used instead.

To get a rotation the long way around just do the opposite, i.e. work out Q.q and if it''s negative use q, otherwise use -q. This probably means just flippping a ''<'' in your SLERP implementation.

John BlackburneProgrammer, The Pitbull Syndicate

This topic is closed to new replies.

Advertisement