   Troubles with Quaternion rotations
  In my animation system I have what I call an "animation difference". Having three animations states A1, A2 and A3 the result would be A = A1 + ( A2 - A3 ). A1 is the current animation state of the object. A2/A3 are two animation states retrieved from a specially crafted animation sequence. For example at t=0s the object pointing down, at t=0.5s pointing straight ahead and at t=1s pointing upwards. So the difference from some t to t'=0.5s gives the rotation required to get from A3 to the given A2. This can be used to apply an animation over another animation. This works only in certain situations but that's not the problem right now.I want to do this now with proper quaternion math since obviously the following is not really mathematically correct ( where q1,q2,q3,qr are unit quaternions ):qr = q1 + ( q2 - q3 )Correct would be to multiply quaternions since this adds rotations. So I tried this:qr = q1 * ( q2 * q3.conjugated() )Since they are unit quaternions the conjugation is the inverse rotation and the difference rotation is the same as rotating around q2 and then by the inverse of q3. For some reason though this doesn't work out at all and especially doesn't look like the incorrect addition approach above. That said it works if q3 is the identity quaternion but not otherwise.Any ideas where I cranked up the math? Where do I make a mathematical incorrect step? How is it done correctly to apply the difference between two quaternions as a rotation to a base state?   
  The order in which you multiply quaternions is very important. If you want to first apply q1 and then apply q2/q3, you should useqr = q2 * q3.conjugated() * q1;  Thought about that problem too since I read the application of q1 followed by q2 is q2*q1 but doing the order you mentioned caused a much bigger mess than before. But in general this should be correct to do this application like that?EDIT: Little correction. I noticed your way is different than what I did. I used the following:qr = ( q3.conjugated() * q2 ) * q1Why did you inverse q1 and q2/q3 but not q2 and q3 themselves?   ;  You'll just have to think hard about what order you want your rotations to apply, and be consistent. If you don't get it to work, post a specific example (as simple as you can make it), so we can follow the steps and see what went wrong where.I suggested using q2*q3.conjugated()*q1 because, if I understand correctly, you want to compose q1 with a rotation r that, when applied to q3 will give you q2. That rotation r is q2*q3.conjugated(). If that's not what you wanted, please try to explain it as clearly as possible.;  In words this would be:Apply the relative rotation from q3 to q2 to the base absolute rotation q1.With Euler angles this would look like the first example I used so far:Ar = A1 + ( A2 - A3 )So for example if a bone has in A1 a rotation of ( 10, 0, 0 ) written in degrees as rotation around the axes (x,y,z) and in A2 it's ( 30, 0, 0 ) and in A3 ( 15, 0, 0 ) then this would give:Ar = (10,0,0) + ( (30,0,0) - (15,0,0) )Ar = (10,0,0) + (15,0,0)Ar = (25,0,0)   ;Quote:Original post by RPTDIn words this would be:Apply the relative rotation from q3 to q2 to the base absolute rotation q1.The formula I gave you from the beginning should work. Did you try it?Quote:With Euler angles this would look like the first example I used so far:Ar = A1 + ( A2 - A3 )This is sort of irrelevant. The single-angle case is so trivial (all rotations commute) that anything will work.;  The formula of yours seems to work. At last it looks okay so far. What I don't get though is why only one term is inverse. Because a rotation by definition is q2*q1 yielding rotation first about q1 then about q2. So if I first rotate around q2 then around q3.conjugated and then around q1 I get:( q3.conjugated() * q2 ) * q1but you get:( q2 * q3.conjugated() ) * q1Why are the terms in the parenthesis not inversed too? I'm just trying to understand what's wrong so I can avoid it in the future.The example I gave had been to simply show in principle what I want to do for the case that I did not explain it in an understandable way.   ;Quote:Original post by RPTDThe formula of yours seems to work. At last it looks okay so far. What I don't get though is why only one term is inverse. Because a rotation by definition is q2*q1 yielding rotation first about q1 then about q2. So if I first rotate around q2 then around q3.conjugated and then around q1 I get:( q3.conjugated() * q2 ) * q1but you get:( q2 * q3.conjugated() ) * q1Why are the terms in the parenthesis not inversed too? I'm just trying to understand what's wrong so I can avoid it in the future.The example I gave had been to simply show in principle what I want to do for the case that I did not explain it in an understandable way.Your other explanation ("Apply the relative rotation from q3 to q2 to the base absolute rotation q1") is pretty clear.Let me see if I can explain how I got the formula. You need a rotation that would convert q3 into q2, right? I claim that this rotation is `q2 * q3.conjugated()'. Let's apply it to q3 and see why. Remember that you apply a rotation by multiplying by it on the left:(q2 * q3.conjugated()) * q3 = q2 * (q3.conjugated() * q3) = q2So that's the rotation we want to apply to q1, which we do by doingq2 * q3.conjugated() * q1Is that clear now?EDIT: By the way, if you try to do the same thing with matrices, you'll get the exact same result, except instead of `conjugated' you would say `transpose'. Perhaps a linear algebra text might help you think about transformations and how they are composed.   