#### Archived

This topic is now archived and is closed to further replies.

# quaternion multiplication order changes rotation direction?

This topic is 5164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm learning about quaternions and how they're used for rotations. In the proof that they represent a rotation b/v they're equivalent to the angle-axis formula, if you multiply this whole thing out (a lot easier using vectors): q*p*~q, where q = (cos t/2, w*sin t/2), ~q = conjugate of q, p = (0, v), |w|=1, N(q)=1, and v is the vector being rotated about w by theta (t). Well, I was doing the proof myself, but instead of starting by multiplying p times ~q and then q times the former, respectively, I did q times p and then (qp)*~q, which is the intuitive left-right approach. Well, it turns out that the order in which you do them, one or the other of the above, changes the direction of the angle of rotation. The first one mentioned becomes the axis-angle formula, which is: v' = v*cos t + (1-cos t)(w.v)w + (vxw)sin t ie, q(p*~q) = v' while the latter one mentioned becomes v'' = v*cos t + (1-cos t)(w.v)w + (wxv)sin t ie, (q*p)*~q = v'', note the bold part. Basically, instead of adding the final vector offset in the "right" direction derived by the axis-angle method using the righ-hand rule for everything, it rotates in the -t direction, hmm... Does this become confusing when you actually implement it and expect to rotate in the same direction, or is it the de facto practice just to multiply quaternions in the "backwards" order (the first mehtod, q(p*~q). I'll post the proof if you want it, or you can just believe me. edit: if i'm a little sketchy, say so. I forgot to mention, but you probably know, wxv = -vxw. [edited by - temp_ie_cant_thinkof_name on May 25, 2004 1:45:23 PM]

##### Share on other sites
Yeah, the order of multiplication does matter. This problem is actually discussed specifically in ''3D Math Primer.'' IIRC, there are a couple of different ways to set up your quaternion mult function, the ''mathematically correct'' way, and the ''wrong'' way. They choose the ''wrong'' way because it allows you to multiply quaternions in the order that is most intuitive. With the mathematically correct way you have to multiply them in reverse order. It sounds like you''re doing it in the mathematically correct way.

##### Share on other sites
If I understand what you write then I must say I don't agree.

Quaternion multiplication is not commutative but it is _associative_. This means:

p,q,r quaternions, then

p*q != q*p, but (p*q)*r == p*(q*r)

This behaviour is similar to matrices'.

So if q represents a transformation then it transforms p to:

p' = q*p*~q = (q*p)*~q = q*(p*~q)

If r is another transformation then it transforms p' to:

p'' = r* p' *~r = r*q*p*~q*~r = (r*q)*p*(~q*~r)=s*p*~s, where s=r*p, the composite transformation.

So you have to multipy p backwards with the transformation quaternions (like in OpenGL).

If I misunderstood, what you wrote, then sorry.

[edited by - szinkopa on May 25, 2004 6:51:15 PM]

##### Share on other sites
quote:

So if q represents a transformation then it transforms p to:
p' = q*p*~q = (q*p)*~q = q*(p*~q)

This is what I found did not hold.

Let Q=(Wq, Vq) P=(Wp, Vp) ~Q=(Wq, -Vq)

Then Q*(P*~Q) != (Q*P)*~Q

Proof:
Q'=Q*P=(Wq*Wp - Vq.Vp, Wq*Vp + Wp*Vq + Vq^Vp)
Q'*~Q=(Wq*(Wq*Wp-Vq.Vp) - (Wq*Vp+Wp*Vq+Vq^Vp).(-Vq),

//--------------------------------------------------------------
(Wq*Wp-Vq.Vp)*(-Vq) + (Wq*Vp+Wp*Vq+Vq^Vp)*Wq + (Wq*Vp + Wp*Vq + Vq^Vp)^(-Vq))
=
(Vq.Vp)Vq + (Wq^2)Vp + Wq(Vq^Vp) - Wq(Vp^Vq) - (Vq^Vp)^Vq

//--------------------------------------------------------------

Q"=P*~Q=(Wq*Wp + Vq.Vp, Wq*Vp - Wp*Vq + Vp^Vq)
Q*Q"=Wq*(Wq*Wp + Vq.Vp) - (Wq*Vp-Wp*Vq+Vp^Vq).Vq,

////////////////////////////////////////////////////////////////
(Wq*Wp+Vq.Vp)*Vq + (Wq*Vp-Wp*Vq+Vp^Vq)*Wq + Vq^(Wq*Vp-Wp*Vq+Vp^Vq))
=
(Vq.Vp)Vq + (Wq^2)Vp + Wq(Vp^Vq) + Wq(Vq^Vp) + Vq^(Vp^Vq)

////////////////////////////////////////////////////////////////

The above, bolded parts in the two commented out blocks are not equal. The cross product is not commutative. You can reverse the cross product in the parentheses of the first bolded part giving you a negation, so

-(Vq^Vp)^Vq = (Vp^Vq)^Vq (A)
and the bolded part in the second comment block is

Vq^(Vp^Vq) != (A) (?)

[] (box thing)

I've also read that quaternions are associative, but as far AFAIK, in two proofs i've done they're not. Wtf is going on here? Did I break math!? According to many googled papers, they're multiplicatively associative! Could someone plz check my proof.

[edited by - temp_ie_cant_thinkof_name on May 25, 2004 10:09:40 PM]

##### Share on other sites
I use the left to right multplication, and everything is OK.
I will check your proof in a day.

##### Share on other sites
I haven''t done this yet but given the identities:
a^(b^c) = (a.c)b - (a.b)c (B)

a^(b^c) != (a^b)^c

http://planetmath.org/encyclopedia/TripleCrossProduct.html

I think i have to do a nother proof to make sure and then one with the quaternion q=(cos(t), w*sin(t)) which is what i was working with, b/c the last triple cross product was not where i found the inequality, if there is one.

##### Share on other sites
quote:

//--------------------------------------------------------------
(Wq*Wp-Vq.Vp)*(-Vq) + (Wq*Vp+Wp*Vq+Vq^Vp)*Wq + (Wq*Vp + Wp*Vq + Vq^Vp)^(-Vq))
=
(Vq.Vp)Vq + (Wq^2)Vp + Wq(Vq^Vp) - Wq(Vp^Vq) - (Vq^Vp)^Vq

//--------------------------------------------------------------

Q"=P*~Q=(Wq*Wp + Vq.Vp, Wq*Vp - Wp*Vq + Vp^Vq)
Q*Q"=Wq*(Wq*Wp + Vq.Vp) - (Wq*Vp-Wp*Vq+Vp^Vq).Vq,

////////////////////////////////////////////////////////////////
(Wq*Wp+Vq.Vp)*Vq + (Wq*Vp-Wp*Vq+Vp^Vq)*Wq + Vq^(Wq*Vp-Wp*Vq+Vp^Vq))
=
(Vq.Vp)Vq + (Wq^2)Vp + Wq(Vp^Vq) + Wq(Vq^Vp) + Vq^(Vp^Vq)

////////////////////////////////////////////////////////////////

Also, the second and third to last crosses don't match up.

edit: I will post a cleaner proof, b/c it's hard to decrypt everything in that formatting.

[edited by - temp_ie_cant_thinkof_name on May 25, 2004 11:13:34 PM]

##### Share on other sites
The quaternion and matrix multiplications have same math order of multiplications.

From left to right -> transformations goes in LOCAL object FRAME
From right to left -> transformations goes in GLOBAL WORLD FRAME

Here i explanation :

taken from there:

The math equation writen

T = T1 * T2 (where T, T1, T2 - transformations)

MUST be read from left to right as :
Transform Object by T1
AND THAN
Transform Object By T2 in OBJECT LOCAL FRAME (that is already transformed relatively to world).

//-------
Personaly i don''t like to transform my mind with transformations, and it is simpler for me to do all transforms in GLOBAL world frame.

So i like to think such:
"Rotate the object by 30 degrees around X axis"

when it mean

That object will rotate about WORLD X axis
to keep all transformations in WORLD FRAME we can just read the math equation from right to left. Than it will look like:

T = T1 * T2 (where T, T1, T2 - transformations)

Transform Object by T2 in WORLD FRAME
AND THAN
Transform Object (already transformed by T2) By T1 in WORLD FRAME.

http://www.euclideanspace.com/maths/geometry/rotations/for/

Global Frame-of-Reference -> Reading math equations from Right to Left

Local Frame-of-Reference -> Reading math equations from Left to Right ( as mathematicians like )

//----------------------------------
Both views can be used depending of situation.

Read here plesse the introduction :
http://vered.rose.utoronto.ca/people/david_dir/GEMS/GEMS.html

It is about many possible ways to combine rotations , and one of parameters is called static/local frame rotation.

##### Share on other sites

http://mathworld.wolfram.com/DivisionAlgebra.html

says that quaternions are associative and non-commutative. They form a division ring. If they were commutative, they would form a field (like the complex numbers).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

##### Share on other sites
temp_ie_cant_thinkof_name:
You are wrong:

3 quaternions: q1=(s1,v1), q2=(s2,v2), and q3=(s3,v3) (s is scalar, v is 3D vector)

 q1*q2=(s1 * s2 - v1 * v2, s1 * v2 + s2 * v1 + v1 x v2) (q1*q2)*q3=(s1 * s2 * s3 -            v1 * v2 * s3 -            s1 * v2 * v3 -             s2 * v1 * v3 -          (v1 x v2) * v3,  s1 * s2 * v3 -(v1 * v2) * v3 +   s3 * s1 * v2 +   s3 * s2 * v1 +   s3 * v1 x v2 +    s1 * v2 x v3 +    s2 * v1 x v3 +  (v1 x v2) x v3   ) q2*q3=(s2 * s3 - v2 * v3, s2 * v3 + s3 * v2 + v2 x v3) q1*(q2*q2)=(s1 * s2 * s3 -            s1 * v2 * v3 -        v1 * s2 * v3 -        v1 * s3 * v2 -        v1 * (v2 x v3),s1 * s2 * v3 +s1 * s3 * v2 +s1 * v2 x v3 +  s2 * s3 * v1 -(v2 * v3) * v1 +v1 x (s2 * v3) +v1 x (s3 * v2) +v1 x (v2 x v3)) Now comparing:The scalar component is the same because v1 * (v2 x v3)=(v1 x v2) * v3 For the vector components I have eliminated the same expressions, I get this: -(v1 * v2) * v3 + (v1 x v2) x v3   =?=   -(v2 * v3) * v1 + v1 x (v2 x v3) Now as a x (b x c)=(a * c) * b - (a * b) * c, and (a x b) x c = -c x (a x b) = -c x (-b x a) = c x (b x a) = (c * a) * b - (c * b) * a = (a * c) * b - (c * b) * a = a x (b x c) + (a * b) * c - (c * b) * a Using this: -(v1 * v2) * v3 + (v1 x v2) x v3  =?=  -(v2 * v3) * v1 + v1 x (v2 x v3) -(v1 * v2) * v3 + v1 x (v2 x v3) + (v1 * v2) * v3 - (v3 * v2) * v1  =?=  -(v2 * v3) * v1 + v1 x (v2 x v3)

And they are the same, so the vector part is also the same, consequently multiplication of quaternions is associative.

[edited by - szinkopa on May 26, 2004 9:45:40 AM]

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 27
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001790
×