Upcoming Events
Southwest Gaming Expo
11/20 - 11/22 @ Dallas, TX

Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

Global Game Jam
1/29 - 1/31  

More events...


Quick Stats
6633 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

  Contents

 Introduction
 Let's Get Started
 Quaternions
 Converting from
 Quaternions

 Multiplying
 Quaternions

 Conversion to
 Quaternions

 Demo
 Conclusion

 Printable version

 


Multiplying Quaternions

Since a unit quaternion represents an orientation in 3D space, the multiplication of two unit quaternions will result in another unit quaternion that represents the combined rotation. Amazing, but it's true.

Given two unit quaternions

Q1=(w1, x1, y1, z1);
Q2=(w2, x2, y2, z2);

A combined rotation of unit two quaternions is achieved by

Q1 * Q2 =( w1.w2 - v1.v2, w1.v2 + w2.v1 + v1*v2)

where

v1= (x1, y1, z1)
v2 = (x2, y2, z2)

and both . and * are the standard vector dot and cross product.

However an optimization can be made by rearranging the terms to produce

w=w1w2 - x1x2 - y1y2 - z1z2
x = w1x2 + x1w2 + y1z2 - z1y2
y = w1y2 + y1w2 + z1x2 - x1z2
z = w1z2 + z1w2 + x1y2 - y1x2

Of course, the resultant unit quaternion can be converted to other representations just like the two original unit quaternions. This is the real beauty of quaternions - the multiplication of two unit quaternions in 4D space solves gimbal lock because the unit quaternions lie on a sphere.

Be aware that the order of multiplication is important. Quaternion multiplication is not commutative, meaning

q1 * q2    does not equal    q2 * q1

Note: Both quaternions must refer to the same coordinate axis. I made the mistake of combining two quaternions from different coordinate axes, and I had a very hard time wondering why the result quaternion fails in certain angles only.




Next : Conversion to Quaternions