Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Disclaimer: I am a professional games programmer, and use quaternions most days but they are close to black magic to me. I am relatively at home with math but imaginary numbers always confused me. I tend to treat quats as useful and end up reversing multiplications more than once. I try to reason about them like I would with matrices with limited success.

Anyhow....

What baffles me, is the following. When I want to rotate an object around it's local axis I multiply its rotation with the quaternion that represents the rotation I want to apply. It is therefore a rotation in local space.

Now if I want to rotate it around an axis in world space, my reasoning would be: Take the rotation in world space as a quaternion. Multiply the inverse of my object rotation with this quaternion. This will bring my world rotation in local space. Multiply my rotation with this new quaternion. ie: newRot = oldRot * (inverse oldRot * worldRot)

However, what I need to do is newRot = oldRot * (inverse oldRot * worldRot) * oldRot.

Why do I, after multiplying with the inverse quat still need to multiply with my own quat before applying it? I know there must be a perfect valid reason, but I can't reason my way out of it and it's frustrating as heck to me. I tried the various faqs and whatnot, but most go to deep in the math, making it less clear to me.

Anyone who can explain this to me like I'm a 5 year old?

share|improve this question
    
Isn't it a bit like matrix translations and roatations (ie. you need to move your object to the center, rotate and then move back when you want to rotate an item around it self: Minv_transl * Mrot * Mtransl) –  Valmond Aug 20 '11 at 8:20
    
I try to reason about them like I would with matrices - then you are on the right track. If you understood how to rotate around object's axes and world's axes using matrices, you can do the same using quaternions. The multiplication order is the same for both, matrices and quaternions. –  Maik Semder Aug 20 '11 at 15:57

1 Answer 1

up vote 8 down vote accepted

Quaternions are associative:

you mention that your solution is:

newRot = oldRot * (inverse oldRot * worldRot) * oldRot

which is the same as:

newRot = oldRot * inverse oldRot * worldRot * oldRot

which is the same as:

newRot = identity * worldRot * oldRot
newRot = worldRot * oldRot

which actually brings you back to what's really happening:

localTransformed = oldRot * rot
worldTransformed = rot * oldRot

The order of application is changing, that is all. Going back to matrices, when you apply an object matrix to a transform matrix and store that as your new object matrix, that's your local space transformation. When you apply the transform matrix to the object matrix and store that, that's you world transformation. It's all about the order of application and nothing more.

share|improve this answer
1  
+1 for the first part, the second part is a bit misleading. If you'd only use 'rot' in the last code sample, rather than 'localRot' and 'worldRot', the example becomes clearer. Otherwise it implies that the rots itself are anyhow different. But the difference lies only in the multiplication order, as you showed, rather than in different quaternions ('localRot' and 'worldRot'). 'localTransformed' and 'worldTransformed' would be better as: 'rotatedAroundLocalAxis' and 'rotatedAroundWorldAxis'. That itself would explain the equations and make the last paragraph obsolete, which has some flaws. –  Maik Semder Aug 20 '11 at 16:33
    
Flaws in the last paragraph: the distinction between matrix and transform (both are the same here and interchangeable, so its better to use just matrix to prevent confusion) and the terms "local space transform" and "world transform": it would be more correct to say, the first equation gives you the 'local-to-world matrix' after being rotated around the object's local axis, the second one gives you the 'local-to-world matrix' after being rotated around world's axis. In both cases, what you get is simply the 'local-to-world matrix'. However, the first part has my +1 anyway for the analysis. –  Maik Semder Aug 20 '11 at 16:39
    
+1 @Maik perhaps you could write a seperate answer to make the indifference between rotations and the issue of multiplication order even clearer? Thanks for the comment either way! –  Max Dohme Aug 20 '11 at 17:28
    
Ah, now it makes sense. I didn't know (ouch, that woulda been in FAQs) that quaternion multiplication was associative, so indeed the rotation and it's inverse cancel eachother out, giving me the insight I needed, one has the local rotation on the right and one on the left which basically say 'apply rotation in parent space' or 'apply rotation in local space'....no different than matrices. Pretty elementary once you see it! Thanks! –  Kaj Aug 20 '11 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.