Quaternions

Runitai

Newcomer
What's a good way to get a rotation of one quaternion on another when you want to rotate more than 90 degrees at a time?
 
Are you looking for the difference in the rotation of two quaternions?
If so the difference is:
Code:
qd = (q1^-1) * q2
It's good enough for up to 180 degrees rotation.
To get back the angle you do:
Code:
angle = 2 * acos(qd.w);
if (angle > PI)
    angle -= 2*PI;
 
No, I'm looking to apply one quaternion to another in the same manner you'd multiply two matrices together.

i.e. if I have a quaternion pointing along the x axis and I rotate it by a quaternion that represents a 90 degree rotation about the y axis, the result should be a quaternion pointing along the z axis. See what I mean?

The method I'm using now (normalizing and multiplying) only works for small rotations (< 1 radian) and isn't accurate across cumulative rotations (i.e. rotating 0.01 radians 314 times is visibly off the 180 degree rotation).

The specific problem: users will be writing code for entities who's facing is described by a quaternion, and their only interface to modifying that quaternion is a rotate method that accepts a quaternion as a paramter:

public void rotate(float x, float y, float z, float w)

yes, it's Java but don't worry, the body is implemented in C.

Basically, if the user calls rotate(0.0f, 1.0f, 0.0f, 180.0f) then the entity should do an about face. An acceptable alternative method would be to call a rotate(x,y,z) method, where x,y,z specify the axis of rotation, and the magnitude of <x,y,z> specifies the amount of rotation.

I know my current method works for small rotations, because these balls:
http://www.rit.edu/~dmp9199/pics/roller.JPG
use it to spin about the vector normal to their velocity and the triangle they're rolling over, but it doesn't work for large rotations, as the limit of actual rotation as supplied parameters approach infinity is +/-90 degrees.

Perhaps a book would be helpful? Any suggestions?
 
There is a multiplication operation defined for quaternions, which does essentially what you want: if two quaternions represent rotations, the result of the multiply is one of the rotations applied to the other one. More explanation and the actual multiplication operation itself can be found e.g. here.
 
Back
Top