Math Dopers... Quaternions? (a primer, please?)

I’ve started inheriting some old software which uses quaternions to (apparently) determine the relative position(s) and orientation of 2 objects in a (simulated) space. I’m mystified as to how this works. Although I’ve done quite a bit of programming involving object orientation, (not talking about OOP here) I’ve never used quaternions before. Previous stuff is mainly converting from one co-ordinate system to another (matrix math) or changing x,y,z to distance/bearing (from the origin).

Can any of you mathematicians recommend a book (or website, even) that would serve as an introductory lesson in this? My CRC standard is silent on the subject.

Humble thanks in advance.


PS. My college math went through basic calculus, and some linear algebra, but that’s all

You are probably used to using 4x4 real transformation matrices. You can do exactly the same thing using 2x2 complex matrices. That’s all that quaternions are (i.e., in effect, 2x2 complex matices). The number and type of operations required to do the transformation using either the real or complex matrices are exactly the same.

If you really need a textbook, there’s an enormous list of them here:

IMHO, theres not much need to know exactly how Quaternions work if you just treat them as a 4 element vector with certain nice properties. As long as you can convert between Quats and axis-angle representations or 4x4 matrices, theres little need to actually look AT the values of a quaternion.

Quaternions are nice because, IIRC, theres a unique representation for every rotation. This means that you can compare 2 different rotations and see if they are the same or not. Euler angles can’t do it and axis-angle representation can’t do it. Transformation matrices can but high performance simulations and game engines don’t like using them because they take up more room. You can also do stuff like interpolate between two angles.

Thanks ya’ll. I’m perusing the web link now. I’m glad I can treat them as a sort of black-box. It’s entirely possible I’ll never need to change them; I was just uncomfortable poking around code I don’t understand.

Quaternions are to complex numbers as complex numbers are to real numbers. In fact, starting with the reals, there’s a construction you can apply to get complex numbers, and then you can define addition and multiplication in the usual way. Then you can take the exact same construction to get quaternions, and apply the same notions of addition and multiplication. Do it again, and you get the octonions.

Take a look here for more details.

Octonions? Sounds like something I’d use to fuel my 1920’s-style “Death Ray”, as I assault the infinium-armoured fortress of Kang… :slight_smile:

Aren’t octernions non-associative, though? It seems to me that that would make them very clumsy to work with.

Brief introduction to quaternions: In the real numbers, you have one unit, 1. Any real number can be expressed as the product of a real number and 1. In the complex numbers, you have two units, 1 and i. Every complex number can be expressed as the sum of products of real numbers with the units. That is to say, any complex number can be expressed as a1 + bi. In order to add complex numbers, you just add the parts, but to multiply them, you need to know an additional rule for multiplication, that is that ii = -1. Then, you multiply two complex numbers just like you’d multiply any polynomials (using the good old FOIL rule or equivalent), and whenever you have ii in your answer, replace that by -1.

In the quaternions, you have four units (hence the name), 1, i, j, and k. Again, we need some new multiplication rules: ii = jj = kk = -1, and ij = k, jk = i, and ki = j. In order to make quaternions associative (a very desireable propery, meaning that x*(yz) = (xy)z for any x, y, and z), it turns out that you need to also set ji = -k, kj = -i, and ik = -j. So quaternions are not commutative: It’s not always true that xy = yx. Commutivity is a useful property, but it’s not actually as important as associativity, and hey, you can’t have everything.

Any system of objects which follows those multiplication rules and vector addition rules are quaternions. It’s not necessary to have any particular representation for them; you can just call them 1, i, j, and k if you like. It happens, though, that one can choose a set of matrices which behave in exactly this manner, and it’s often convenient to do so, since there’s a lot of work already done for working with matrices. The matrices themselves are sometimes called the quaternions, but that’s not strictly accurate: They’re just one of many ways of representing quaternions.

Aren’t quaternions used (partly) because they don’t suffer from Gimbal lock? Or is that something else?

Even worse, in the 16-onions, not every non-zero element has a multiplicative inverse. I think that makes them not an integral domain, but my algebra is kinda rusty.

Interestingly enough, there’s a chain of failures going on here, due to the fact that the same transformation gets you from reals to complexes, complexes to quaternions, quaternions to octonions, and so on and so forth. The 16-onions are not an ID because multiplication in the octonions is not associative, and that’s because multiplication in the quaternions is non-commutative, and that’s because complex numbers are not self-conjugate, and that’s because R is not of characteristic two. I saw a proof of this online once, but can’t seem to find it.

Found it.

Yes, AFAIK, it’s proven that, even though rotation has 3 degrees of freedom, no 3 elements is enough to define rotation without it suffering from gimbal lock. ie: There are some rotations which it can’t represent and some which have multiple representations.

Octonions indeed form a non-associative algebra. This actually isn’t a problem at all. You should know what a Lie algebra is, Chronos. There are many immensely useful non-associative algebras.

As to the OP’s request for a book, John Conway and Derek Smith recently wrote On Quaternions and Octonions.

More accurately: the group of unit quaternions is a 3-sphere, which forms a double-cover of SO(3), the group of rotations of 3-dimensional space. Every rotation corresponds to two unit quaternions. This is related to… well, quite a huge lot, really. Among other things, the existence of particles of spin 1/2, the self-duality of the fundamental representation of U[sub]q/sub

Think about Z itself… does 2 have a multiplicative inverse? Yes, you lose inverses. This makes them fial to be a division algebra.

If you can remember it and it’s not too ad hoc I’d love to see it. This is reminding me a lot of k-monoidal n-categories, particularly the way that “adding another multiplication” acts by adding properties to the existing one(s). For example: a category with one object is a monoid (obviously), but if the category is monoidal (or “tensor”, some people say) then the monoid structure is commutative.

That’s one of the reasons they are used in games. Though more essential is simply that, at base, Euler angles (which are the ones which get Gimbal lock) are mostly useful because they hold data in a way that is easily understood by a human. But beyond that, they really don’t lend themselves to things like multiplication by a matrix, interpolation, and such.
When trying to build my own miniature 3D engine and going through my book “3D Math Primer for Graphics and Game Development”, I entirely left out all of the Euler stuff. Outside of debugging, it really didn’t seem useful–and of course I was largely copying and pasting from the book, so debugging the actual equations wasn’t an issue (…except for a typo.)

Can tell you that an Arm 7 processor can do real-time 3D though :cool: (Though I never got beyond a spinning cube with solid color faces.)

I can’t find it, but it was a fairly simple proof. Basically, if you have a field F and F’ is the result of applying the Cayley-Dickson construction to it, the following are true:

Multiplication in F’ is associative -> Multiplication in F is commutative
Multiplication in F’ is commutative -> F is self-conjugate
F’ is self-conjugate -> F is of characteristic two

Verifying each of those is pretty much just a matter of simple algebra.

This I’d like to see…

It’s less interesting than you might think. Under Cayley-Dickson, (a, b)* is defined as (a*, -b). If (a*, -b) = (a, b), then a*= a and b = -b.

Well, if the link given above is accurate, then a conjugate in the Cayley-Dickson construction is given by
(a,b)* = (a*,-b)

Thus, for F ’ to be self-conjugate, it must be the case that for every element a of F, a = a* and a = - a.

The first of those says F is self-conjugate, and the second says it’s of characteristic two. (Since 1 = -1 implies 1 + 1 = 0).

Or am I missing something here?

[On preview, I see that ultrafilter already responded, but oh well.]

The proofs of all the statements I posted are conceptually simple, but there’s a lot of algebra involved in some of them.

Also, I have those of the form “F’ has property P -> F has property Q”, but you could also write “F’ has property P -> F has properties P and Q”. It’s just that that’s not necessarily as interesting here.