Quaternions: A Practical Guide
anyleaf.org
anyleaf.org
For all of my personal applications, I have found that good old fashioned 4x4 homogeneous matrices are a really good way to deal with all of the transforms I am concerned with. I do recognize the utility of quaternions in dealing with certain specialized transforms, but these are not applicable in my simple DIY/hobby use cases (i.e. Q3A-tier graphics).
From a math perspective, I think quaternions are fantastic and far more elegant way to do certain things. I did recently discover Microsoft has all of this neatly wrapped up in System.Numerics, a SIMD-accelerated library for .NET: https://docs.microsoft.com/en-us/dotnet/api/system.numerics....
This reminds me of something (seen here) that I thought somewhat interesting.
Orthographic projects of cones an n-dimensional euclidean space can be used to generate (n - 1)-dimensional voronoi diagrams.
The author of the page that I looked at hadn't generalised to weighted diagrams, but that's trivially implementable by altering the gradients of the cones.
The dimensionality issue is significantly nastier - with higher dimensional forms lacking GPU support, so the page only covered 2D voronois.
It seemed like the idea could make for an interesting voxel engine, if 4D depth clipping were a possibility.
I never fully grokked complex numbers nor quaternions until I read those articles
(HN discussion 8 months ago https://news.ycombinator.com/item?id=29512302 )
No it doesn't. Please stop repeating this. Quaternions are literally a part of geometric algebra. His page uses the algebra Cl_{3,0}, whose even subalgebra is Cl_{0,2}, which is the quaternions.
Just to clarify what he's actually saying, because he said it poorly: He's not criticising the quaternions at all. He's criticising a philosophy of the quaternions that goes back to Hamilton: That they are formally scalars plus vectors. He's instead promoting a view that they're formally scalars plus bivectors. You can go from the author's POV to Hamilton's POV by replacing the word "bivector" with "vector" and "exterior product" with "cross product". Mathematically, this replacement constitutes an isomorphism, which shows that the author's algebra is isomorphic to - which for mathematicians means the same as - Hamilton's quaternions. The author's philosophy has the advantage that it shows that the quaternions are a subalgebra of Geometric Algebra. But this is only a different way of talking about the quaternions from Hamilton's. And Hamilton's view isn't even wrong - it leads to the octonions, which the GA approach doesn't - and it doesn't need you to know what a bivector is.
Hamilton’s view (and later the view of Gibbs, Heaviside, et al.) is wrong insofar as in models of the 3-dimensional physical world we have two kinds of "vectors" which behave fundamentally differently under reflection (because one type are actually bivectors called by the wrong name). Physics textbooks usually consider these both “vectors” but call one type “pseudovectors” (or call them “axial” and “polar” vectors), and (ideally) keep careful track of which vector is of each type. If you take the cross product of two regular vectors (yielding a pseudovector), it is fundamentally meaningless to add that to another ordinary vector, even though that seems like an entirely reasonable thing to do, algebraically.
Hamilton got there by trying to generalize “complex numbers” – mathematicians had been eliding the difference between points in the plane, vectors in the plane, and quotients of vectors in the plane (“complex numbers”) for a century or so by his time, and didn’t yet know the territory well enough to understand which points they were confused about.
Even in the plane, separating vectors from complex numbers is very powerful and useful. Nearly any time you see something like z̄w between complex numbers you can profitably consider z and w to be vectors u and v and use the geometric product instead (by comparison, when you see zw that implies a scalar+bivector was the kind of object you wanted already). Being able to use the dot and wedge products of planar vectors u·v and u∧v is clearer than the version mathematicians use, Re(z̄w) = ½(z̄w + zw̄) and Im(z̄w)i = ½(z̄w – zw̄), and makes the other applicable vector identities a lot easier to learn, recognize, and use. Bonus: they keep working in higher dimensional spaces or spaces of other signature.
The “cross product” is sort of interesting as a historical curio or abstract puzzle, but it is an abomination of a tool to teach to students, because it (1) creates widespread conceptual confusion, and leads people to make wrong inferences about the world, and (2) completely fails to generalize to the obvious analogous situations like the Euclidean plane or 4-dimensional spacetime (so people end up needing to learn a new notation for each new context they find). Replacing the cross product with the wedge product (as the anti-commuting part of a geometric product) clears up the confusion and builds up a whole shed full of effective general-purpose tools.
In fact Ken Shoemake, who was responsible for originally popularizing quaternions as a robust rotation/orientation representation[1], wrote his own tutorial of this stuff back in the late 80's sometime, and it's really, really great: https://www.ljll.math.upmc.fr/~frey/papers/scientific%20visu...
Folks should start with that one before trying to rewrite it, IMHO.
[1] Here's a copy of the 1985 paper: https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf
- Hidden Markov Models
- Kalman filters
Things which have tutorials that continually fail to explain the tao of the thing.
It doesn't seem like you can just drop in a library, in the general case, or if you can, it doesn't seem to be common practice.
Usually things that need an actual understanding are either totally novel, or solved problems with existing tools.
Kalman filters are where you find out that you really did need math all along, if you're like me and don't really see math in everyday life.
I suspect there's still a way to fake your way through if you need to and have a day or two to study, but the first time you see it it really shows what you don't know.
It's like when you see non physicists talking about physics and feel amazed at how they managed to seemingly understand maxwells equations just for fun.
I was indeed specifically responding to the suggestion that the speech be read first. If it's the first thing one reads on the subject, then one has no context in which to take Hestenes's remarks, and it is easy to take very literally his claims about the primacy and universality of geometric algebra—so I wanted to give some of that context first.
In physics there was some uptake where appropriate, but mathematicians for the most part scoff (“this is just a different notation for structures that were studied in the 19th century, there’s nothing new here” kind of thing).
But being able to multiply and divide vectors is a big deal, and GA is packed with incredibly useful identities. Working coordinate-free in a rich enough language of geometric relationships makes it (a) a lot easier to solve gnarly geometric problems, and (b) a whole heck of a lot easier to demonstrate and explain those solutions.
The change of perspective has been most impactful in fields where the details can’t be hand-waved away because they are getting interpreted by a computer, so streamlining them helps a lot. In particular, computer graphics, computer vision, robotics, physical simulation, and the like.
Over and over again, spread out over maybe a decade, I would try solving some problem in the languages I learned in school – Gibbs-style vectors, matrices, differential forms, complex numbers, trigonometric functions, synthetic geometry, etc. – and fill pages of scratch paper with equations that balloon in size making it hard to spot patterns or avoid mistakes, and eventually I would get entirely stuck somewhere. Then I would slap my head, try rewriting the problem in GA terms, and end up replacing like 2 pages of completely incoherent scratch work with about 3–5 lines of concise and easily geometrically interpretable GA manipulations, yielding both a clear answer to my problem and a clear and intuitive demonstration of why it should be right. In particular, dividing by vectors is an unbelievably underrated idea.
I don’t know about “one true language” as some kind of crusade, and I am not a physicist or mathematician, but in my opinion every engineer, scientist, and mathematician would benefit tremendously from becoming substantially fluent with GA,† ideally starting with the basic ideas in high school. It is a very clear and expressive language, substantially better for many purposes than the tools currently taught to students in their technical coursework.
† Including you, if you ever solve geometric problems. Give it a serious try sometime.
I just vaguely remember them as something super abstract, that you can work through with about the same effort as a sudoku puzzle, but you have to go actually learn Haskell to understand why you'd want one.
Then they say something about function composition, but it seems like have to already be a functional expert to know why you would care about composing functions in a consistent way instead of just calling them from a new function.
We've taken "Show HN" out of the title now.
Quaternions are still important for building intuition for dual quaternions.
Dual quaternions haven’t really taken over. While there’s no universal way that people end up handling rigid body transforms, SO(3) + R3 for rigid body transforms are the norm in robotics.
Some robotics orgs choose a single representation for SO(3) — usually quaternions or matrices — and use it everywhere. Note that quaternions are more space efficient and easier to normalize, but require 2x more operations to rotate a vector [1]. So you might see a quaternion shop use matrices in a hot loop for transforming 3D points. And a matrix shop might use quaternions in a hot loop for composing many transformations. Usually you have many fewer rigid body links than points in an e.g. pointcloud so it is performance favorable to use matrices.
A final comment: Most users in a codebase should interact with rotations through a rotation library like Sophus or Manif. That library should implement left/right lerp, splines, “rotate a vector” and “compose a transformation”. There is basically never a need for a developer to know what rotation representation is being used to compute the rotation.
If such a library is correctly implemented, you can even use Euler Angles as the underlying representation and never experience gimbal lock.
[1] https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotati...
Arbitrary not gonna work. The cross product will sometimes be zero vector, and the algorithm will fail. The cross product will sometimes be a vector of very small length, not long enough to give accurate direction, and the algorithm will glitch.
One reliable way is finding index of the smallest absolute coordinate of the input vector, and using that unit vector.
Another minor thing, I think most libraries are storing these 4 numbers in xyzw order, while this article uses wxyz order for the formulae.
...you never know with this stuff