Spherical Coordinates vs Quaternions?

I’m up to Chapter 7 of Modern 3D Graphics Programming but I’ve gotten slightly confused. It mentions using spherical coordinates for rotations around a vector, however I’ve heard that quaternions are preferred. What’s the difference between the two and when is one used over the other?

Edit: Ahh I just browsed through the next chapter and I see that it has a whole topic devoted to quaternions. I might as well just keep this question here though; the maths is quite confusing and multiple explanations will probably help me understand.

Using Quats instead of Euler Angles will save you from the problem of Gimbal Lock.

Essentially quaternions are 4d complex numbers - I they are 4 numbers with funky ways of multiplying them, adding them etc. - and it just so happens that they can represent 3d rotations much like a 3d matrix but these have only 4 numbers and are computationally simpler to work with. The only problems are a) you have to generate a rotation matrix to actually use them b) you have to keep them normalised the whole time. c) unless you have a PhD in Mathematics or are simply extremely gifted in mathematics they make absolutely no sense. One of those things that simply works. Fine until it doesn’t.

It isn’t correct, it’s more complicated. There are only 2 solutions to avoid gimbal lock:

  • Euler angles + non linear corrections for singularities on poles (implemented in Ardor3D)
  • Unitary quaternions + non Eulerian transforms

If you use quaternions with Eulerian transforms, you don’t avoid gimbal lock. I wrote a report about that at the end of my bachelor degree several years ago but I never translated it into English. Quaternions are easier to interpolate.

Quaternions are dead easy (as far as math beyond Reals is concerned). People just insist on making them hard.

No…they are exactly complex numbers in 3 dimensions. The require 4 elements because a bivector (plane element) is one element in 2D and three in 3D. So in math speak they are a 4d vector space which is just saying they require 4 elements.

They only add one new rule…for multiplication.

No they can be used directly. In fact the so-called quaternion to matrix conversion is simply applying the direct formula three times, one for each: (1,0,0),(0,1,0)&(0,0,1) and shoving the result into a matrix.

Not really required but it is desirable. Pretty much all code bases will make some simplifying assumptions of unit magnitude and moreover the “structure” of the quaternion product make compounding of errors (in the scale) grow very lowly.

This shouldn’t be the case. One could argue that they are easier than vectors and are certainly easier than linear algebra (for basic operations).

@gouessej:
I have no clue about what you mean by “Eulerian transforms”, (it can’t be anything invented by Euler) but the equivalent of gimbal lock is impossible with quaternions…the structure of the product doesn’t allow it.

http://www.iquilezles.org/www/articles/quaternions/quaternions.htm

I mathematically proved that if you use 3 unit quaternions and if you combine them exactly like you would do with Euler angles, you will still be bothered by the gimbal lock. The Professor Pascal Mignot wrote this formula to combine quaternions by using non eulerian transforms:


Sorry, Google Translate might help you.

It’s impossible to lose a degree of freedom with quaternions. Anyone that says differently doesn’t really understand them. A combination of Euler angles (which are really due to Roderigues not Euler) is equivalent to a composition of three local coordinate changes. The local part doesn’t really matter (it’s just the order of the terms). The three part doesn’t really matter either.

Cayley proved that any quaternion (other than zero) can represent a rotation using the formula: p’ = qp(1/q) (by showing it’s the same as the Roderigues equation) . Where ‘q’ is a quaternion which represents the rotation, p is a bivector which represent the coordinate of the point and p’ is the point after the rotation. So the set of all quaternions which represent the same rotation vary only by their magnitude, so they only have 3 degrees of freedom (are 3D embedded in 4D)…visually they form a line through the origin (if you’re choosing to think of them as a coordinate in 4D). In the same paper he proved that the conjugate of q and 1/q are the same if ||q|| = 1 (unit magnitude) and if you’re limiting yourself to unit quaternions then the equation can be reformed as p’ = qpq*. Also in the same paper he proves that the product is equivalent to the composition of rotations.

So let’s say we have 3 unit quaternions (a,b,c), to be able to have gimbal lock means:

ab=a, when b != 1 or ab=b when a != 1. Both of these conditions are impossible. Or it means that (ab)c != a(bc), which is also impossible. These are all very basic proven facts.

So if you see something like gimbal lock that means one of two things: either you’re mixing and matching representations or there’s a flaw in your math.