Visualizing quaternions (2018)
eater.net
eater.net
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.
(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).
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.
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).
- First of all, this is minor, but you cannot call them east and west poles, because the east one is only to the east from one side. One the other side, the “east pole” would be to the west of the “west” pole.
- Bigger problem but related: traveling along latitudes is no longer traveling north or south, and no longer traveling in great arcs. When you stay in one latitude in your system, you have to know where you are in order to know what compass heading you’re traveling (or vice versa - if you start with a heading, you don’t know whether your longitude or latitude is either increasing or decreasing), it cycles through all direction on the compass without passing the north or south pole.
- That means that latitudinal navigation by the stars is no longer an option, and latitudinal travel by the compass (!) is no longer an option either. Your east-west-pole idea would require GPS for sailing. (Might be technically fine today, but should be pretty obvious by now why earth coordinates could never have evolved this way and would be extra bad for pre-computer navigation.)
- You lose the property that longitude lines and latitude lines are perpendicular to each other on the surface - except at the two non-poles - the two spots on the axis in between the 4 “poles”. Longitude and latitude in this system are no longer orthogonal, and in some places you can specify ways to travel from one longitude to another via either longitude or latitude, in other places you can’t.
- You add two more singularities to your coordinate system. And now you have a 3-dimensional coordinate system, but only 2 axes. Why have 4 poles and not 6? That feels asymmetric somehow. How do you pick the location of these east & west poles (and what would you call them instead of east & west?)
- Finally, think about how you’d draw a map. If you get rid of the north-south axis, then which way is up on the map? How do you flatten your coordinate system and put it on a 2d rectangle? Do you want the lat/long lines to look straight and perpendicular, or faithfully represent the local surface while letting lat/long lines curve all over the map? Could you actually do either of those things with this system? The existing solutions aren’t great, but it seems like this would be even worse. There are very good reasons, for example, that nobody uses a 4-pole system for texture-mapping spheres.
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.
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).
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.
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.