# Quaternions

Printable View

• 09-05-2003
Lurker
Quaternions
Quote:

Any number of the form a + bi + cj + dk where a, b, c, and d are real numbers, ij = k, i2 = j2 = -1, and ij = -ji. Under addition and multiplication, quaternions have all the properties of a field, except multiplication is not commutative.
That is what dictionary.com says about quaternions. I have read up on them to start with 3D programming, with great thanks to confuted. So where do a, b, c, d, i, j, and k come from? After I study more about these, I will most definetely have more questions, but please stick with me for it!! Thanks all :D !
• 09-05-2003
confuted
a, b, c and d are real numbers.
i=j=k=sqr(-1). These are defined to represent the three axes, much like vectors can be represented as a scalars times unit vectors... example:

Code:

```| j axis (length 1) | | | L__________k axis (length 1)     /   /  / * can be represented by a*j + b*k```
With quaternions, the axes are just i, j and k, and happen to be imaginary... So a is the real number representing the amount of rotation (usually called w when dealing with rotation...), and b, c and d (usually x, y, and z) are coefficient scalars for the i, j and k axes...

did that make sense?
• 09-05-2003
Perspective
>> i=j=k=sqr(-1)

are you sure about that? typically in 3-space, the following is considered standard.

i = <1,0,0>
j = <0,1,0>
k = <0,0,1>

thus a*i + b*j + c*k represents the vector <a, b, c>. Using i, j, k is just another notation. At least thats how i learned it my linear algebra courses.

>> the axes are just i, j and k, and happen to be imaginary

i dont see why the three unit vectors would be imaginary numbers. Im not tryin to rag on you but can you show some verification of this?
• 09-05-2003
confuted
Sure enough Perspective. We're dealing with quaternions here, not just normal 3d vectors. If we were doing normal 3d vectors, you would be absolutely correct.

Here, I wrote this for this site, which probably explains this in a bit more depth (OP mentioned that)

From Gamasutra:
Quote:

In the eighteenth century, W. R. Hamilton devised quaternions as a four-dimensional extension to complex numbers. Soon after this, it was proven that quaternions could also represent rotations and orientations in three dimensions. There are several notations that we can use to represent quaternions. The two most popular notations are complex number notation (Eq. 1) and 4D vector notation (Eq. 2).

From GameDev:
Quote:

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.

And, just for fun...
3d Quaternions
OpenGL tutorials
How-to: Quaternions
Geometric Algebra FAQ
Some USENET thing...
and more!

:D I think I supported my case.
• 09-05-2003
Lurker
Thanks guys, this is a big help.
So confuted,
Quote:

i=j=k=sqr(-1). These are defined to represent the three axes, much like vectors can be represented as a scalars times unit vectors.
the programmer defines these, but what does he use to do so?
• 09-05-2003
confuted
Quote:

Originally posted by Lurker
Thanks guys, this is a big help.
So confuted,

the programmer defines these, but what does he use to do so?

Naw, that's just an interesting math curiosity. You don't need to worry about the imaginary parts when programming, just the real coefficients, which you can store in a float (or double).
Code:

```struct Quaternion {     float w, x, y, z; }```
And remember that w^2 + x^2 + y^2 + z^2 = 1 if you're programming rotations with quaternions (keep 'em normalized)

Was something confusing in the quaternion tutorial I wrote?
• 09-05-2003
Lurker
Quote:

Originally posted by confuted

And remember that w^2 + x^2 + y^2 + z^2 = 1 if you're programming rotations with quaternions (keep 'em normalized)

Sorry, but does ^ mean XOR or to the power of in this case? Sorry for my insolence!! :D
Quote:

Was something confusing in the quaternion tutorial I wrote?

No, but I'm slowly moving into 3D (well I guess going from no 3D knowledge to quaternions isn't really slow :p ) and I'm learning the basic concept of them first. Thanks for the info tho :D !
• 09-06-2003
confuted
^ means power in this case. I was using mathematical notation, not programming notation :)
• 09-06-2003
Lurker
OK, that's all for now then. Thanks all :D !
• 09-06-2003
Perspective
cool, thanx for the info confuted . Quaternions seem very interesting, they've definatly got my attention now. ill have to look into them sometime soon. :)