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

**URL:** <https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203>\
**Category:** Factual Questions\
**Created:** [May 10, 2005, 11:48am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203 "2005-05-10T11:48:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pullin](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pullin](https://boards.straightdope.com/u/pullin)\
**Post date:** [May 10, 2005, 11:48am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/1 "2005-05-10T11:48:23Z")

</div>

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.

Pullin

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

---

<div class="post-metadata">

**Author:** ![Desmostylus](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@Desmostylus](https://boards.straightdope.com/u/Desmostylus)\
**Post date:** [May 10, 2005, 12:39pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/2 "2005-05-10T12:39:22Z")

</div>

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:

[http://mathworld.wolfram.com/Quaternion.html](http://mathworld.wolfram.com/Quaternion.html)

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [May 10, 2005, 2:23pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/3 "2005-05-10T14:23:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pullin](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pullin](https://boards.straightdope.com/u/pullin)\
**Post date:** [May 10, 2005, 2:36pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/4 "2005-05-10T14:36:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 10, 2005, 2:55pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/5 "2005-05-10T14:55:41Z")

</div>

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](http://www.math.niu.edu/~rusin/known-math/95/octonions.phys) for more details.

---

<div class="post-metadata">

**Author:** ![Sunspace](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sunspace/32/1250_2.png) [@Sunspace](https://boards.straightdope.com/u/Sunspace)\
**Post date:** [May 10, 2005, 6:16pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/6 "2005-05-10T18:16:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [May 10, 2005, 8:52pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/7 "2005-05-10T20:52:33Z")

</div>

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 a_1 + b_i. 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 i_i = -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 i_i 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: i_i = j_j = k_k = -1, and i_j = k, j_k = i, and k_i = j. In order to make quaternions associative (a very desireable propery, meaning that x\*(y_z) = (x_y)_z for any x, y, and z), it turns out that you need to also set j_i = -k, k_j = -i, and i_k = -j. So quaternions are not commutative: It’s not always true that x_y = y_x. 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.

---

<div class="post-metadata">

**Author:** ![Capt.Ridley\_s\_Shooting\_Party](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Capt.Ridley\_s\_Shooting\_Party](https://boards.straightdope.com/u/Capt.Ridley_s_Shooting_Party)\
**Post date:** [May 10, 2005, 9:00pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/8 "2005-05-10T21:00:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 10, 2005, 9:28pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/9 "2005-05-10T21:28:50Z")

</div>

> [@Chronos](#):
>
> Aren’t octernions non-associative, though?

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.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 10, 2005, 10:36pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/10 "2005-05-10T22:36:04Z")

</div>

[Found it](http://math.ucr.edu/home/baez/octonions/node5.html).

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [May 11, 2005, 4:37am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/11 "2005-05-11T04:37:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mathochist](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Mathochist](https://boards.straightdope.com/u/Mathochist)\
**Post date:** [May 11, 2005, 5:26am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/12 "2005-05-11T05:26:32Z")

</div>

> [@Chronos](#):
>
> Aren’t octernions non-associative, though? It seems to me that that would make them very clumsy to work with.

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_](http://www.amazon.com/exec/obidos/tg/detail/-/1568811349/qid=1115789540/sr=1-1/ref=sr_1_1/104-3650737-2100747?v=glance&s=books).

---

<div class="post-metadata">

**Author:** ![Mathochist](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Mathochist](https://boards.straightdope.com/u/Mathochist)\
**Post date:** [May 11, 2005, 5:31am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/13 "2005-05-11T05:31:18Z")

</div>

> [@Shalmanese](#):
>
> 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.

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…

---

<div class="post-metadata">

**Author:** ![Mathochist](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Mathochist](https://boards.straightdope.com/u/Mathochist)\
**Post date:** [May 11, 2005, 5:39am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/14 "2005-05-11T05:39:01Z")

</div>

> [@ultrafilter](#):
>
> 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.

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

> [@](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Sage\_Rat](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sage_rat/32/399_2.png) [@Sage\_Rat](https://boards.straightdope.com/u/Sage_Rat)\
**Post date:** [May 11, 2005, 9:12am UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/15 "2005-05-11T09:12:11Z")

</div>

> [@+MDI](#):
>
> Aren’t quaternions used (partly) because they don’t suffer from Gimbal lock? Or is that something else?

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 🆒 (Though I never got beyond a spinning cube with solid color faces.)

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 11, 2005, 2:59pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/16 "2005-05-11T14:59:11Z")

</div>

> [@Mathochist](#):
>
> If you can remember it and it’s not too ad hoc I’d love to see it.

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.

---

<div class="post-metadata">

**Author:** ![Mathochist](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Mathochist](https://boards.straightdope.com/u/Mathochist)\
**Post date:** [May 11, 2005, 4:01pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/17 "2005-05-11T16:01:17Z")

</div>

> [@ultrafilter](#):
>
> F’ is self-conjugate -\> F is of characteristic two

This I’d like to see…

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 11, 2005, 4:44pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/18 "2005-05-11T16:44:29Z")

</div>

> [@Mathochist](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![tim314](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tim314/32/3468_2.png) [@tim314](https://boards.straightdope.com/u/tim314)\
**Post date:** [May 11, 2005, 4:49pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/19 "2005-05-11T16:49:43Z")

</div>

Well, if the [link](http://math.ucr.edu/home/baez/octonions/node5.html) 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.]

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 11, 2005, 4:51pm UTC](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203/20 "2005-05-11T16:51:30Z")

</div>

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.

[Next page](https://boards.straightdope.com/t/math-dopers-quaternions-a-primer-please/303203.md?page=2)
