192 points · by squashToffee · 3y ago · 42 comments
Some of the perceived complexity of complex numbers and quaternions seems to stem from not knowing the bigger picture.
#2: Quaternions as a powerful tool for representing orientations and rotations. Applicable whenever you're programming something that uses these concepts. Most common are computer graphics and robotics, but you can imagine other uses like biometrics, scientific models of molecules etc.
The visualizations you might use for type 2 are standard 2D and 3D space operations. You don't need to directly map the 4 quaternion parameters. You need these building blocks; find from a library, article, first-principles etc.
- Rotate a vector using a quaternion
- Find the quaternion that specifies the shortest rotation from one vector to another
- Find the quaternion that rotates around a given axis a given amount
- Rotate an orientation and/or composing rotations
- Find the quaternion that rotates one orientation to another
Using these building blocks (And maybe one or 2 I left out), you can do any sort of work with rotations and orientations. If you can visualize the rotations, either in your head, or with physical objects or a computer render, you won't forget the principles.Warning: There are 2 types of quaternions (JPL and Hamilton). Every article/lib etc uses one, but they rarely annotate which! Mixing the 2 will produce incorrect results.
The fascinating thing, to me, is that for so many geometrical objects, you can start with a short list of straightforward properties, and show that they exactly correspond to the collection-of-numbers concept over an arbitrary basis. Oftentimes, if you want to do something to the stuff on your screen, if you can describe it in terms of the abstract objects with no reference to the basis, you can then transliterate that to operations on a bunch of floats in a way that is simpler and more robust than working with the floats from the beginning.
(although you can assign whichever axis to whichever quaternion you want, and you can arbitrarily swap i<>-i, j<>-j, k<>-k. From googling it looks like the JPL convention is to swap k<>-k, such that ij = -k instead of ij = k).
But once you get into something more sophisticated like using rotations in a dynamical system, statistical filtering, optimizing a rotation, etc., the abstractions begin to leak.
Until I tried to do animations, by linearly interpolating between the "start" and the "end" matrices. It resulted in truly funky transformations that deformed objects in bizarre ways. This in turn led me down the rabbit hole of decomposing matrices into Euler angles, interpolating between them, then struggling with gimbal locks and non-uniformity of polar coordinates, and finally to quaternions.
I wish I had these tutorials back then...
https://www.youtube.com/watch?v=zjMuIxRvygQ https://www.youtube.com/watch?v=d4EgbgTm0Bg
Quaternions that are not normalized do not form a representation of the spin group Spin(3).
Using quats for orientation is useful in part precisely because of the added dimension - it’s what makes interpolating quaternion orientations better than other representations - you naturally get the minimal and most direct motion. Interpolating any of 3 component orientations doesn’t work as well. So don’t let it irk you, instead find the utility and beauty in the extra dimension.
Why do you say that?
For example, we could represent any point on the sphere {x^2 + y^2 + z^2 = 1} by two numbers, but for most purposes, three numbers is a lot nicer.
And graphics programmers use homogeneous coordinates for everything, mainly because they make translations and perspective projections nicer. (Coincidentally, quaternions are also a kind of homogeneous coordinates, since the space of 3D rotations is (diffeomorphic to) 3D real projective space.)
So there are lots of places where adding extra variables makes things cleaner.
Basically you have an extra degree of freedom because you can multiply the whole thing by a scalar that just scales whatever vector it multiplies. But if you just want to represent rotations, you want it to have unit magnitude, so you ensure that a = cos θ and |v| = sin θ. (or θ/2 on each if you want to use the two-sided qpq^{-1} rotation).
When describing rotation of of a sphere projected onto a 2d plane, having two variables (X,Y) isn't enough. Because the sphere could rotate about the axis between the origin and that point. There's an an entire degree of freedom you could describe for a complete rotation about that axis.
In the same way, having 3 variables to describe a quaternion rotation is not enough. You again, have an entire degree of freedom you could rotate the quaternion about.
But they are mathematically useful.
X0 ops X1(another number system ) where X0, X1 is real
You can have complex number or a+ bi where i^2 = -1 And you can have split complex number a+bj where j^2 = 1 etc
The next move may be then not to q but to try
x0 ops x1n1 ops x2n2 ops … xi is all real but ni is a different number system represent things not on the real number. Of course you can do q here. But ..
The natural course is to cliff geometry, where it dimension meant something else.
Or even more other systems.
You can then see that rotations using rotors (from geometric algebra aka "quaternions") are then basicaly two consequitive mirror operations across two vectors.
thats it! theres no more magic than that.
just like complex numbers encode a rotation in 2d due to the way the algebra is structured.
olinde rodrigues wrote about axis-angle rotations before hamilton discovered quaternions, and i think euler and gauss may have been involved too. anyway, its a fascinating story about the meeting of algebra and geometry.