95 comments

[ 3.2 ms ] story [ 163 ms ] thread
This seems a very good and in-depth. I recently had to learn a bit of this stuff and coming from very basic math Quats are a bit of funny concept at first. This video does an amazing job at explaining what they are https://www.youtube.com/watch?v=4mXL751ko0w and the pro/cons over euler angles. The whole channel has some pretty good resources for anyone looking for a "soft approach" at math.
Anyone interested in such topics should check out geometric algebra, a.k.a. Clifford algebra. Start with http://geocalc.clas.asu.edu/pdf/OerstedMedalLecture.pdf

Matrices and trigonometry are in my opinion a pedagogically, conceptually, and practically poor way of understanding and using quaternions; furthermore, cross products (and the associated confusion about a right hand rule and polar vs. axial vectors and so on, not to mention a total failure to generalize to higher dimensions) need to vanish from the earth.

More generally, this is a topic that should be explained first using pictures, ideally interactive ones. The algebraic manipulations to formally prove what the pictures explain visually should just fill in the bookkeeping details.

Finally, perhaps the most important reason geometric (Clifford) algebras should be used for pedagogy, even if you plan to write code which only uses quaternions per se, is that they make the “sandwich” multiplication of versors as operators on vectors completely obvious as composition of reflections.

Say what you want about geometric algebra, if it has a least one merit, it's that it makes rotations in 3D space and their link with quaternions very simple to understand.

Also check out my implementation in Perl 6:

https://github.com/grondilu/clifford

With it, quaternions become:

    use Clifford;

    constant I = @e[1]*@e[2];
    constant J = @e[2]*@e[3];
    constant K = @e[1]*@e[3];
    
    say I² == J² == K² == I*J*K == -1;
The subalgebra of 3D Clifford using the scalar and the 2-blades represents quaternions.

The subalgebra using the pseudoscalar and the 1-blades can also represent quaternions.

You have to be careful using other people's implementations, because certain operations are anticommutative, so sign conventions and operand ordering matters a lot more. For instance, choosing whether K is defined as e3 * e1 rather than e1 * e3 depends on whether your base vectors square to 1 or -1.

Geometric Algebra is cool. It lets you say things like "the intersection of two spheres that don't touch is a circle with negative radius." You can't even represent a circle with negative radius in regular geometry.

> You have to be careful using other people's implementations, because certain operations are anticommutative, so sign conventions and operand ordering matters a lot more. For instance, choosing whether K is defined as e3 * e1 rather than e1 * e3 depends on whether your base vectors square to 1 or -1.

Sure. For my implementation I thought a lot about how to deal with signatures and stuff. It's technically easy but making it simple and elegant is not obvious. I first thought about defining a @signature array, but then it occurred to me that it's much simpler to create two infinite spaces : one euclidean and one anti-euclidean. Later I've learned that Hestenes and others have considered this as well, they called it the mother of all geometric algebras, or universal geometric algebra[1]. Conveniently, Perl 6 deals with infinite lists very well, so it was very appropriate.

So in my implementation, @e[$i]² is +1 for all $i. If you want vectors with negative squares, use the @ē basis.

With geometric algebra, there are indeed several ways to represent quaternions. In fact there are several ways to represent complex numbers as well. I don't think it's a pitfall. As long as notations are clear and simple, it should be fine, I think.

1. https://en.wikipedia.org/wiki/Universal_geometric_algebra

No, not a pitfall. it is more like a small pothole in the road: the problem is easily avoided if you already know that it exists.
> Geometric Algebra is cool. It lets you say things like "the intersection of two spheres that don't touch is a circle with negative radius." You can't even represent a circle with negative radius in regular geometry.

For some notion of "regular geometry". Desargues could produce this result in the early 17th century by lifting the circles into right cones in three dimensions, though he would probably tell you that the circle with negative radius was meaningless.

I was going to ask how your implementation compares to Versor[0] but I see you link from it in your readme. My next question was going to be if there are any license issues, since Versor was for a long time only free for non-commercial use, but I see their github is a bit more recently updated than their home page and mentions it's now under the BSD (yay!). Lastly, are you concerned about the patent on the conformal method? [1]

There are a lot of great resources linked in this thread. My memory of the last time I took a dive into GA was that there was a split in the resources for representation -- one side tried to do everything axiomatically and symbolically, the other side had some concrete numbers but it was mysterious how they all worked together. Have you seen a super-basic resource that goes through the same sorts of modeling problems middle school and high school students do when first learning trig and classic geometry?

[0] http://versor.mat.ucsb.edu/

[1] https://www.google.com/patents/US6853964

> Lastly, are you concerned about the patent on the conformal method?

I did not know it was patented. My module does not specifically implement the conformal method, though. I did create two nul vectors and I called them no and ni, as in the conformal method, but that's about it. It's very much possible to do conformal geometric algebra with my module, but it's just not nearly as optimized as Versor is.

I've tried many times to implement Versor in Perl 6, but for various reasons I never succeeded. It's just kind of hard I guess. Also I'm not completely sure the optimization method I implemented is much worse, so it's hard for me to convince myself into doing the effort to improve it.

Also, I'm slightly skeptical the method used by Versor is the best that can be done, so again that dissuades me to do the effort.

I would love to see it done, though.

I am told that in some modules in the Cambridge undergraduate mathematics degree there are always questions that are trivial to solve using Clifford Algebras, but a complete pig in the usual formulations. I didn't take such a module so I can't comment from first-hand experience, but knowing some of the lecturers I can well believe it. The take-away is that they are a powerful tool in the right circumstances.

Whether they can replace the usual formulations in toto is another question, but they are certainly interesting.

Anyone trying to study rotating objects (precession, fictitious forces in rotating reference frames, complicated problems about angular momentum, collisions of rigid objects etc.) will find that the geometric algebra approach cuts the work and conceptual overhead by an order of magnitude.

Here’s the book to work through for anyone who wants to deeply understand rotation in classical mechanics problems: http://geocalc.clas.asu.edu/html/NFCM.html

Do you have a link to a worked out example that is made much easier by this?
Unfortunately Hestenes’s book is not online. I don’t know of any comparative examples online to link to.

I do still have vivid memories of working such problems out painfully using matrix/tensor methods in a college mechanics course 12 years ago though. :-)

Is there a video lecture one can watch? What background is required to understand this?
GA notation is compact, and it allows for more expressiveness when dealing with geometry. Rotors are pretty intuitive. The software libraries and hardware need to be put in place for it to find more practical use. There has been work on custom hardware, or implementing them in PROLOG [1 PDF].

Hestenes book "New Foundations in Classical Mechanics" is a great start, and there are books on GA in computer graphics. It is only a matter of time until there are solid software libraries and dedicated hardware for GA for it to really take off.

The current method is fine, and has done its job, however, when you read the history, and study GA, you realize the turn mathematics took. It was not based upon the better road, but on historical incidents.

[1 PDF] http://www.gaalop.de/dhilden_data/fccm09.pdf

Some years ago Wildberger gave some excellent lectures explaining quaternions using rational geometry, which, if I am not mistaken, is related to Clifford algebra in the way it is presented.

Lectures start out by explaining the relation between complex numbers and rotations in the 2D plane, then discuss rotations in 3D using quaternions.

https://www.youtube.com/watch?v=uRKZnFAR7yw

https://www.youtube.com/watch?v=0_XoZc-A1HU

https://www.youtube.com/watch?v=g22jAtg3QAk

https://www.youtube.com/watch?v=MkNfQtINEjo

I've noticed Wildberger getting some grief about some of his unconventional ideas. I very much enjoy his lecture style, but as a layperson I'm never sure when he's straying away from accepted areas into controversial ones. Any feedback there?
Yes, he sure is controversial. He does not acknowledge the existence of irrational numbers for example. In his lectures he avoids the use of any transcendental functions for the same reason, so no square roots, sine, or cosine.

I'm no mathematician, so I'm not qualified to comment on this either. Would love to hear other opinions on this too.

My personal opinion on this is that his rational approach does produce beautiful math, in the sense that it is really simple and intuitive.

>the existence of irrational numbers for example.

I think most of cases of "non acknowledging" are deeply personal aesthetic considerations. One likes to play with one set of objects and only with them.

In the widest sense existence in mathematics means that mathematical object is well-defined and the system used is consistent (you can't derive contradictions).

Of course mathematicians are free do limit themselves into any subset of axioms or concepts they feel is "natural" or "real" and work only with them. But if they make philosophical arguments against other using irrational numbers, axiom of choice etc. I think they should argue that they are not consistent or well defined.

> In his lectures he avoids the use of any transcendental functions for the same reason, so no square roots, sine, or cosine.

Square roots are algebraic, not transcendental.

The general consensus is that his videos are very good. It's just his insistence that the real numbers shouldn't be used that is not accepted. Some mathematicians (1% of 1% of mathematicians) agree with him, most don't.

edit: Doing math without the real numbers is less elegant and harder, but it's philosophically more sound. It essentially means restricting yourself to math that can be described as a (possibly infinite) algorithm.

The lay person is more likely to agree with what Wildberger has to say than a mathematician. In fact, most people think that infinity in math is a process (potential infinity). But in math, we use absolute infinity. A completed infinity. 0.999... does not tend to 1, it _is_ 1. Infinity is completed.

> It essentially means restricting yourself to math that can be described as a (possibly infinite) algorithm.

I'm confused. My impression is that it is the other way around where irrational numbers and operations like sine, square root etc. are infinite 'algorithms'?

Yeah, but there's a difference between saying there exists in reality some exact value for the square root of 2, and saying that it's possible to calculate the square root of 2 to arbitrary precision.
Thanks for that first link, it looks very promising. My problem is that I already idiosyncratically try to understand spacetime in terms of spin-vectors,* so this is going to take a bunch of trying to map out a Rosetta stone to translate between them!

* In brief, you can convert a world vector v^μ into a Hermitian 2D complex matrix V by adjoining σ_0 = I to the standard Pauli matrices σ_{1,2,3} and then V = σ_μ v^μ, when you do this you find that actually det V = v_μ v^μ under the (+ − − −) signature. This means that for nullvectors det V = 0 and therefore V is a projection V = φ φ^†, else V is merely Hermitian with eigenvalues v_0 ± √(v_1² + v_2² + v_3²) (because it has trace 2v_0) and there's not much more you can say. Lorentz transforms are linear and preserve Hermitianness and the determinant, with the parity-reversing stemming from V → -V and V → (det V) V^{-1} and the rest being V → L V L^† for some L such that det(L) = 1. The special case where L^† L = 1 (which is SU(2)) of course corresponds to 3D rotations because it preserves trace hence v_0, so if it's also preserving det V then it must be preserving the eigenvalues and hence the Euclidean metric √(v_1² + v_2² + v_3²). In turn L can be seen to act directly on the φ of the null vectors, φ → L φ, so call those "spin vectors" and confirm that they are spinors by finding out that L = -I for any 360-degree rotation. This is the most direct way I know of to see that the Lorentz transforms are the group SL(2, C) with this nice SU(2) group embedded in there. Then you can square-root the metric into an orientation tensor on the C^2 vector space as [0, -1; 1, 0] and build up the rest of the algebra in reverse from that starting point.

Cross products likely won't vanish, precisely because they're heavily linked to the Clifford algebra, and are essentially all you need for the most common case.

By the way, it is possible to generalize the cross product to higher dimensions, it just won't be a nice binary product, in n dimensions you need n-1 vectors to uniquely determine one orthogonal to all of them. Of course you can achieve pretty much the same thing with the Clifford algebra, or with wedge products.

This is a question of what it "means". It's origins can be traced to problems dealing with SO(n), and in this sense it's uniquely defined by the Lie-algebra of \mathfrak{so}(n), but in the Clifford-algebra world they become blades (more appropriate for CG).

I consider the cross-product to be one of the most abused objects in Physics; my first course in Newtonian mechanics was a nightmare, filled as it were, with the ghosts of all the characters killed so as to make the plot ostensibly "simple".

I haven't thought about it before but once you start thinking of complex numbers as "numbers that want to turn" (every unit complex number is isomorphic to a rotation on R^2), the concept of quaternions analoguously representing rotations in R^3 becomes pretty intuitive even if you don't quite grok the details.
Hmm, but I would think that a quaternion represents a rotation in R^4 (for which I lack intuition).
===== EDIT: this is mostly wrong - see jblow's reply. Sorry for misleading you into thinking I know what I'm talking about :D =====

I think of it like this: a complex number represents a rotation in a plane. You need two "coordinates" to do that. 2d has one plane, but 3d has two planes - think about how an anti-air cannon rotates left-right and up-down. So, if we've got two rotations to represent, you must need two complex numbers - that's four "coordinates", or one quaternion.

> but 3d has two planes

Why not 3 planes?

Okay, my wording wasn't the best here. 3d doesn't "have" 2 planes. But, for some reason, you can look in any direction in 3d by turning in two planes. Test it yourself: turning your head left-right is rotation in one plane, turning it up-down is rotation in the other plane. here's my shot at illustrating this: https://goo.gl/photos/Cxt7KPbos5o2QnkD9

to be completely honest, I'm not sure if this intuition is correct. But it seems to make sense

It's correct that you can look in any direction with only two planes, but that's not enough; you need to be able to control your orientation around that final axis. You need 3 planes for that (3 "rotational degrees of freedom"). The idea that a quaternion is somehow two complex numbers is wrong.
Thanks. I did some research and found out that, indeed, my vague understanding of quaternions was wrong. I remember skimming the Wikipedia article and seeing this: https://en.m.wikipedia.org/wiki/Quaternion#Quaternions_as_pa...

I then assumed that my idea with two rotations is how quaternions work. Here's to actually reading about a concept before I start explaining it next time...

I think you can do that using two rotation axis only (cf. proper Euler angles).

And quaternions are made of two complex numbers.

edit: typo.

>And quaternions are made of two complex numbers.

I don't pretend to grok quaternions (I only use them), but I'm fairly sure a quaternion consists of three imaginary numbers plus a real number.

Sure, but the way they play together can also be expressed by the means of two complex numbers (which makes 4 real numbers in total).
This is not true. You can't factor a quaternion into two complex numbers. Please don't spread misinformation.
I don't think that's correct. You can also rotate around the direction you are looking.

Rotations in 2D are one-dimensional. Complex numbers are two-dimensional but we fix one degree of freedom by fixing the length.

Rotations in 3D are there-dimensional. Quaternions are four-dimensional but we fix the length again.

Unfortunately you got it wrong, and your AAA example shows it very well.

Just as in 2d with a complex, in 3d you can encode rotations with a 3d vector. The problem is that to reach any point from any other arbitrary point you can't use a single rotation, but a combination of two, sometimes three. Think about how your AAA gun operates or FPS viewpoint controls. Thus you start to use rotations along the three axes of a base which gives you a typical rotation matrix.

As soon as you start to compose rotations along axes you introduce a terrible phenomenon known as gimbal locking, where discontinuities appear especially near north and south poles.

And so, just as a 2D rotation in a plane can be represented by a vector orthogonal to that plane (i.e in a space outside the plane), the gimbal lock and all artifacts that are cumbersome when constraining ourselves in 3D can be dealt with by going up a dimension... Hence quaternions which encode+ a rotation by putting an arbitrary but well chosen axis and an amplitude in a space grown othrogonally to our 3D space.

+ Or isomorohically so

Your analogy is incomplete because you forget rotating the cannon about its barrel.
If you only want to represent a rotation there's some extra information in a quaternion, just like there is in a complex number - an arbitrary number in C actually represents rotation-and-scale where the magnitude of the number is the scale factor. If you stick to numbers with unit magnitude, given one part you can calculate the other, up to reflection. Similarly, with a unit quaternion you can calculate any one component given the other three, again up to reflection.

In general the number of real numbers needed to describe a rotation is the number of rotational degrees of freedom. This number is n(n - 1) / 2 in n dimensions, or C(n, 2), basically the number of orthogonal (2-)planes of rotation in R^n.

[0] https://en.wikipedia.org/wiki/Degrees_of_freedom_(mechanics)

So in 3d that becomes 3(2)/2 = 3. Quaternions have 4 parts. That's what has always made it hard for me to understand.
And in 2D it is 1 but complex numbers have two parts. As I tried to explain, there's simply some redundancy in the representations because it's just unit complex numbers/quaternions that we're interested in. We accept that because it makes the math prettier. Heck, matrices, the de facto standard for representing rotations, have much more redundancy - four and nine elements in 2D and 3D respectively.
We use quaternions in R^3 to avoid gimbal lock.
The constraints between the numbers, when the quaternion is defined as a rotation, end up having three degrees of freedom, spread over four numbers. You can't change any one of them without also changing another or violating the constraints of the rotation definition.

Similarly, when a quaternion is defined as representing a translation, that is likewise 3 degrees of freedom in 4 numbers. The four numbers would be similar to a real cartesian translation with dX, dY, dZ, and a fourth number = sqrt( dX^2 + dY^2 + dZ^2 ).

It's like the 4th number is a checksum for the other 3. You are adding a fourth number to use a more elegant mathematical calculation, which automatically keeps the dependent data relationships intact, like magic.

> Similarly, when a quaternion is defined as representing a translation

How do you encode translations with quaternions? Don't you need dual quaternions for that?

No. You need dual quaternions to encode rotation and translation at the same time.
Ok this I know, but how to do translations only? (apart from the obvious vector space structure in R4)
There are multiple ways that will work. The simplest I can think of is to fix the real part at zero and use i, j, and k to represent deltas along the x, y, and z axes. Then point + translation = point.

There may also be a representation that also encodes distance from the origin, but I am probably confusing this in my memory with something else.

Similarly, Euler's Identity (e^i*pi = -1) becomes a lot more intuitive. The exponential function is continuous (edit: proportional) growth, i is turning sideways, sideways continuous growth traces out a circle, and pi is halfway around a circle.
... what?

I guess if it makes sense to you, ok, but "continuous growth in a circle" to explain the complex exponential sounds like cloud-gazing to me: the human mind making up patterns where there are none.

The only way it makes sense to me is by looking at the power series and seeing how the exponential power series is almost the same as the sine and cosine power series (alternatively and equivalently: all of the exponential, hyperbolic, and circular functions satisfy almost the same differential equation).

"Continuous growth in a circle" may indeed be a personal visualization, but "complex numbers are deeply connected to rotation" is a mainstream point of view in mathematics.
Sure, complex multiplication is rotation, no problem with that part. To multiply two complex numbers you add their angles and multiply their lengths.
Parent is referring to the ODE \dot{z} = i z.
I think I was a bit loose in the wording in order to try to get the phrasing as compact as I could. The exponential function is continuous proportional growth - the limit of adding a part of a vector to itself proportional to the current vector and the "step size" as you take the step size to zero. (Real numbers are just the one-dimensional special case of vectors here).

Anyway, my point is that Euler's identity generalizes to any number that encapsulates "sideways" in Euclidean geometry. Any quaternion "x" that is a unit of rotation will satisfy "e^pi*x = -1". You can't get that easily from the power series understanding.

No, it makes sense. exp(i epsilon) = 1 + i epsilon, to first order, i.e. when epsilon is near 0. You can think of 1 + i epsilon as a tiny rotation, when you multiply by it. exp(i t) = the product of a lot of tiny rotations, just as in real numbers exp(x) = the product of a lot of tiny scalings. The product of rotations equals one rotation by the sum of their (individually tiny) angles. As t increases continuously, exp(i t) rotates around from 1 continuously. The unchanging speed of rotation corresponds to how in e.g. bacterial growth, exp(t), the population gets some constant factor bigger in every equal interval.

(I first got this picture from the Feynman lecture on algebra, http://www.feynmanlectures.caltech.edu/I_22.html, which doesn't seem to ever explain it that way explicitly. It's funny how memory works.)

Okay, this makes a little more sense to me, since it's just the power series again. But I don't think that calling a rotation a growth makes sense. Also, to me, the approximation e^(i epsilon) ~ 1 + i epsilon kind of begs the question.
e^(epsilon) ~ 1 + epsilon in general, because of the definition of the derivative and the fact that d/dx (e^x) = e^x
Right, the latter fact is equivalent to considering exp the solution of a differential equation, which is a much bigger fact. Treating the approximation as an innocent brute fact is what I considered begging the question, because why should this differential equation be valid for complex values?
I was trying to make a geometric intuition accessible to high schoolers who haven't mastered calculus -- though I haven't tried it on an actual teenager.

Of course there's also value in looking deeper into the foundations.

Quaternions are much easier to grasp once you are familiar with basic Lie group theory, in particular the adjoint representation of the group over its Lie algebra.

Then the link with rotations becomes obvious and it gets very easy to transport geometric operations from the unit sphere to the rotation group (spherical linear interpolation, averaging, etc...)

Unless I'm missing something, this feels like trying to understand a less complicated thing by first understanding a more complicated thing?
Sometimes this is the math way ;)

More seriously, Lie group theory puts the light exactly on the shared structure between quaternions and rotations (both are smooth groups related in some way) and ignore the secondary details, so you spend time understanding what matters.

It may be more abstract, but you get more from your efforts in my opinion.

So much js on that page that it took almost a minute to finish loading, and then my phone's browser froze.
Nice, lots of detailed explanation!

For people interested, to use them in a C/C++ context, feel free to have a look at my Quaternion-Library.

https://github.com/MauriceGit/Quaternion_Library

This looks like C. Why do you call it "C/C++"? It could just as well be C/ObjC, right?
C and C++ share the same memory model and can be called quite easily form each other with the use of an 'extern "C"'.

It's a common practice to write libraries in C for flexibility, (many languages can ingest C) and use the 'extern "C"' for use in C++ code.

You can also write a thin C++ class wrapper for a more native object oriented interface.

But all of this is true for ObjC too. How come people write C/C++ to describe pure C code but not C/ObjC? C is as much of a subset of ObjC as it is a subset of C++.

It's funny people don't do this as much with other languages. For example, nobody describes pure Javascript as "js/html" even though you can have lots of js inside HTML code.

True. I'll skip the C++ mentioning, as it is clear for any C++ developer, that you could just use it as extern C.
If you intend for your library to be used in both C and C++ then your doing yourself a favor by using C/C++ for the simple fact that this is marketing to C++ programmers that they can use the library who may not be aware that that is the case.

so at the bare minimum C/C++ will possibly increase your user base.

(edit)

You should not assume that C++ programmers are going to wade through your library code and rewrite your library with the proper signatures. You as the library writer should have done that and tested it, then advertised to prospective users that your library is ready for use with C++.

Its an interesting point.

C is actually part of of the C++ standard. Within the ISO C++11 standard there is the C99 standard with some adjustments and exclusions. The integration is quite tight. So one can say C/C++ with some clarity.

Library writers often go thorough a lot of work to write extensive object oriented interfaces around C libraries. And they intend that the user use the C++ version not just import the C version in there C++ code. So in that case it is a necessity to use C/C++ because there are two separate interfaces.

In the general case I would guess that 'most' C programmers write some C++ and vise versa. So you have a very large overlap of C/C++ programmers. Objective C on the other hand is probably a significantly smaller group and is simply not big enough for C/C++ communities to think to much about.

> In the general case I would guess that 'most' C programmers write some C++ and vise versa.

That's not what I've seen. People usually either write C++ exclusively or C exclusively and hate the other language (probably more C writers that hate C++ than C++ writers that hate C).

Some people write very C-accented C++, with mallocs and frees instead of news and deletes and so forth (these are usually people who prefer C over C++ but are writing C++ for whatever reason). I guess those people could be said to be writing "C/C++". But in general I think people overestimate how close the two language communities are. What I have seen is that people like one language and deride the other.

There are some people that probably get to worked up about it especially on the internet as you said. But in a professional environment where you have deadlines and a budget you don't have the luxury to be a language purist. You have to use libraries and choose from whats available and whats the best choice often that means mixing C and C++. I'm not saying that people necessarily like to code in C if they prefer C++ or the other way around but they will often have to. And so have some competency weather they like it or not.
That was my thinking. But as most C++ developers already know this, I'll skip the C++ mentioning :)
For anyone who hasn't been exposed to this problem before, like me, there are countless applications for this sort of mathematical operations in game development.

Back a few years ago a friend and I were attempting to write a game engine. We hit many road blocks but what often killed us was fixing gimble lock. This isn't an issue for many things like FPSs or side scroller but when you get into the realm that we wanted to tackle (first person space flight) it becomes a challenge.

Quaternions, from my position as the ultimate laymen, take up the slack that Euler coordinates/angles have. The issue comes from rotating an object. Once the object is upside down, it's coordinate system stops working as you would expect. If you are head-to-floor upside down then your up relative to the world is down. When applying rotations that are based on shifts in pitch, yaw, and roll it is difficult to have correct behavior.

If instead of this, you implement quaternion rotations for all objects, this entire class of headache melts away. The problem is finding a good explanation of how this works or even yet how to implement it. It's what's stopped me dead in my tracks many times as the implementations often available still have many bugs (when in Space Engineers if you rotate your cursor a circle quickly you'll slowly rotate your character, this is a common bug in many implementations I've found)

I'm definitely going to read through all of this when I get back from uni today.

PS: Mathematicians/dark arts practicers, if I'm incorrect about anything I've said here please let me know and point me to where I can learn more

How familiar are you with the complex plane?

It helped me a lot to be explained quaternions starting from the complex plane. More specifically, by constructively inspecting their properties. There's a great interactive article that gets the pedagogy of teaching such a complex concept (pun definitely intended). Unfortunately, I can't seem to dig it up.

I recall the author's blog using all kinds of CSS and/or WebGL trickery to make 3d backgrounds – anyone know which blog I'm referring to?

I'm in no way informed about any of the dark arts, or as others call them "mathematics"

Any reading will be helpful. Hope someone knows what you're referring to.

Isn't there some theorem stating that all 3 coordinate reps of rotations in R^3 have a singularity? But bumping up to 4 coordinates (or 9 if you like rotation mats) eliminates the singularity.

Edit: seems kind of like latitude and longitude. At latitude + or - 90, all longitudes map to the same point so that coordinate has no information.

Yes, R^3 and the rotation group SO(3) are not homeomorphic (they have different topologies), meaning you can not cover SO(3) with a single chart. So any representation of rotations by 3 numbers is singular somewhere.
Yup, quaternions are also at the root of any good skeletal animation system as you won't find a better/faster way to do pose/animation blending/interpolation.
I don't think the Space Engineers thing is actually a bug, as opposed to just a counter-intuitive behavior.

In the general case Euler coordinates work much closer to our intuitions about rotation and orientation because the world we live in has a well-defined "down," as defined by gravity. Thus if you have a fixed "up" direction for the "camera", then any point on the sphere has a single corresponding orientation as long as you're not actually looking up/down (analogous to gimbal lock). This has the property that no matter what path your mouse takes, if you return to the same point, you will be oriented the exact same way you started.

This is not true with accumulating rotations in general. Try this with a paper airplane:

1. Hold it in the "flat" position at eye level and imagine the x, y, and z axis so that the x axis points out to the right, y points up, and z points down the tail and into your eye.

2. Pitch it 45 degrees nose up (counter-clockwise about the X axis).

3. Adjust your own perspective so that even though the plane is pitched up relative to the ground, you're looking at it as if once again x points right, y points up, and z points into your eye.

4. Now in this perspective, turn 45 the plane degrees counter-clockwise about the new Y axis. Note that this is not the same as "yaw", because new the Y axis you're using is actually 45 degrees off vertical from step #2.

5. Now without rotating the plane, reset your perspective. Notice how in addition to having pitched up and yawed left, your paper plane has also rolled slightly relative to the ground.

What you see in Space Engineers is probably this exact phenomenon. It's not so much a bug as it is a side effect of trying to come up with an intuitive rotation scheme when there is no "up".

You will eventually regret any use of Euler angles. - John Carmack
I would agree if it said "most" instead of "any". Euler angles are useful. Just be very careful with them. Convert to quaternion as soon as possible and convert back to euler as late as possible when needed.

However, you will never entirely avoid them because they are just too practical. Under careful constraints, they make code interfaces simpler.

This is especially important if you are to expose that code to a multidisciplinary team. There is no way you're going to teach an artist how quaternions work just so they can rotate their stuff around the up axis, when simple yaw-pitch angles cover 99% of their use cases.

(comment deleted)