6 ms·
Quaternions: A Practical Guide
- ogogmad 4y agoHaven't dual quaternions taken over for their ability to represent all rigid body motions? Quaternions are still important for building intuition for dual quaternions.
- meheleventyone 4y agoMostly in jointed hierarchies like robotics and skeletal animation in my experience. Otherwise quaternions dominate for representing rotation and translation and scale are kept separately. Even further in an editor you might represent the rotation as Euler angles.
- ajkjk 4y agoI don't think so? Most game engines for instance implement quaternions for ie slerp, but wouldn't mention dual quaternions, which are much more niche (used for translation + rotation at the same time).
- ajkjk 4y ago* ie -> eg
- mrjet 4y agoI can only answer for robotics: 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_rotation#Performance_comparisons https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotati...
- percentcer 4y agoAs you pointed out, you still need regular ol' quaternions if you're dealing with non-rigid transforms (e.g. in animation where there's some scaling transform involved as well)
- bodhiandpysics1 4y agowhich is very very very common (squatch and stretch)
- bodhiandpysics1 4y agoIn graphics, dual quaternions are used in skinning, but rarely for orientation and translation.
- gfxgirl 4y agogeometric algebra is replacing quaternions because GA handles tons of edge cases that quaternions don't?
- ngvrnd 4y agoWant to read "Sedenions: a Practical Guide" ("Trigintaduonions", anyone?)
- ajross 4y agoQuaternions are one of those subjects where the community sees a steady stream of tutorial content, which really doesn't seem to be adding much to the discourse to my eyes. It's like a "yet another git tutorial" kind of thing. 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%20visualisation/Shoemake%20K.,%20Quaternions.pdf 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 https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf
- keepquestioning 4y agoAdd to the list - Hidden Markov Models - Kalman filters Things which have tutorials that continually fail to explain the tao of the thing.
- pklausler 4y agoDon't forget monad tutorials!
- wwweston 4y agoAre there any tutorials successfully convey the tao of those things?
- keepquestioning 4y agoNo
- eternityforest 4y agoKalman filters are so interesting. As far as I can tell they are one of the very simplest things one can do that requires a real understanding of math. 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.
- dang 4y agoI'm sure this is a fine article, but an article is not a valid Show HN. Please see the rules: https://news.ycombinator.com/showhn.html https://news.ycombinator.com/showhn.html. We've taken "Show HN" out of the title now.
- the__alchemist 4y agoI wrote this article over the past few weeks, while building a structural chemistry model. I found most sources available either dive into quaternion mathematics and reasoning without building intuition useful in applications, or are documentation for specific computer graphics libraries. I'm using this article as a personal reference; perhaps others will find it useful too.
- KboPAacDA3 4y agoThank you for writing this article and especially skipping the unneeded proofs that a programmer usually has to step over to apply quaternions.
- Grustaf 4y agoAre the long variable names intentional or some kind of Latex artifact? I find it hard to read.
- the__alchemist 4y agoIntentional, but I don't know how I feel about them. I often find math computation terse, to the point where it's difficult to understand how to implement it in code. I took a hybrid approach where I used descriptive names and individual steps; will likely to revise, perhaps by splitting into pure math/latex, and code.
- sxp 4y agoWhenever quaternions come up, I always recommend https://acko.net/blog/how-to-fold-a-julia-fractal/ https://acko.net/blog/how-to-fold-a-julia-fractal/ and https://acko.net/tag/quaternions/ https://acko.net/tag/quaternions/ I never fully grokked complex numbers nor quaternions until I read those articles
- thunkle 4y agoI can't thank you enough for the Julie fractal link. It was super enlightening to someone who has enjoyed fractals and seen the formula but has never grasped the mechanics.
- bob1029 4y agoIn the realm of (real-time) computer graphics, I have recently developed a perspective that Quaternion representation is simply another "space" that you have to spend finite resources transforming to and from. I am not aware of a rasterizer that can operate directly with quaternions, nor a way to apply perspective or orthographic projections to them. 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.quaternion?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.numerics....
- yarg 4y ago> I am not aware of a rasterizer that can operate directly with quaternions, nor a way to apply perspective or orthographic projections to them. 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.
- eloisius 4y agoI use quaternions in 3D geometry contexts a lot right now. Manipulating point clouds, describing camera orientations etc. But I kind of agree, a standard 4x4 rotation matrix would most likely be just as useful. I use them because it’s how Colmap represents camera extrinsics. They might use them just because serializing q{xyzw} is more elegant than dumping a matrix to text.
- taneq 4y ago
- kilovoltaire 4y agoGeometric Algebra provides a compelling alternative to quaternions: https://marctenbosch.com/quaternions/ https://marctenbosch.com/quaternions/ (HN discussion 8 months ago https://news.ycombinator.com/item?id=29512302 https://news.ycombinator.com/item?id=29512302 )
- ogogmad 4y ago> Geometric Algebra provides a compelling alternative to quaternions 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.
- hgomersall 4y agoThe GA view is IMO much easier to understand if you think visually. The fact you can subsume complex numbers and quaternions into a common framework is incredibly neat.
- deleted 4y ago[deleted]
- jacobolus 4y ago> Hamilton's view isn't even wrong 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.
- deleted 4y ago[deleted]
- Const-me 4y ago> You can construct the orthonormal vector by taking the cross product between our first bond, and an arbitrary unit vector. 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.