Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
89 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Let's Get Started
 Quaternions
 Converting from
 Quaternions

 Multiplying
 Quaternions

 Conversion to
 Quaternions

 Demo
 Conclusion

 Printable version

 


What is a Quaternion?

A complex number is an imaginary number that is defined in terms of i, the imaginary number, which is defined such that i * i = -1.

A quaternion is an extension of the complex number. Instead of just i, we have three numbers that are all square roots of -1, denoted by i, j, and k. This means that

j * j = -1
k * k = -1

So a quaternion can be represented as

q = w + xi + yj + zk

where w is a real number, and x, y, and z are complex numbers.

Another common representation is

q=[ w,v ]

where v = (x, y, z) is called a "vector" and w is called a "scalar". Although the v is called a vector, don't think of it as a typical 3 dimensional vector. It is a vector in 4D space, which is totally unintuitive to visualize.

Identity Quaternions

Unlike vectors, there are two identity quaternions.

The multiplication identity quaternion is

q= [1,(0, 0, 0)]

So any quaternion multiplied with this identity quaternion will not be changed.

The addition identity quaternion (which we do not use) is

q= [0,(0, 0, 0)]

Using quaternions as orientations

The first thing I want to point out is that quaternions are not vectors, so please don't use your preconceived vector mathematics on what I'm going to show.

This is going to get very mathematical, so please bear with me.

We need to first define the magnitude of a quaternion.

|| q ||= Norm(q) =sqrt(w2 + x2 + y2 + z2)

A unit quaternion has the following property

w2 + x2 + y2 + z2=1

So to normalize a quaternion q, we do

q = q / || q || = q / sqrt(w2 + x2 + y2 + z2)

What is so special about this unit quaternion is that it represents an orientation in 3D space. So you can use a unit quaternion to represent an orientation instead of the two methods discussed previously. To use them as orientations, you will need methods to convert them to other representations (e.g. matrices) and back, which will be discussed soon.

Visualizing a unit quaternion

You can visualize unit quaternions as a rotation in 4D space where the (x,y,z) components form the arbitrary axis and the w forms the angle of rotation. All the unit quaternions form a sphere of unit length in the 4D space. Again, this is not very intuitive but what I'm getting at is that you can get the a 180 degree rotation of a quaternion by simply inverting the scalar (w) component.

Note: Only unit quaternions can be used for representing orientations. All discussions from here on will assume unit quaternions.




Next : Conversion from Quaternions