452 points · by Glench · 8y ago · 175 comments
Interesting that the original complaint of that article/thread and this one are both the same - ie. quaternions are 'too hard to understand', and people 'use them without knowing how they work'. With this being posted so soon after https://news.ycombinator.com/item?id=18310788 , I feel like that complaint is less valid now than it ever has been, but it's kind of interesting to think about why quaternions in particular draw so much fire when, honestly, I found matrices to be equally challenging at first. Is it just an education thing, since matrices are generally taught much earlier? Or is there some intuition in matrices that isn't present in quaternions? Both of them seem to be just 'do this math, then magic happens' unless you think about them a fair bit, and that was pretty challenging for both the first time round imo.
The matrix:
adg
beh
cfj
maps the vector (1,0,0) to the vector (a,b,c), (0,1,0) to (d,e,f), etc... so if you write any other vector as a weighted sum of (1,0,0), (0,1,0), etc... the weights get mapped to the new vectors.As someone with a background in physics and geometry, it seems bizarre to me to use quaternions to reason about geometry. It's really unnatural. It's basically just a coincidence that the algebraic structure of rotations in 3d happens to look like this. It doesn't generalize to higher dimensions. There is no equivalent to quaternions for 4, 5, 6d [1].
Bivectors discussed in the article, on the other hand, easily generalize to higher dimensions, and are a completely natural geometric concept. (Of course if your thesis is about constructing 4d objects you care about that a whole lot more than if you build a 3d engine...)
Now that doesn't mean it's easier or harder to manipulate one or the other. As they all reference the same mathematical structure it's also not surprising that the code ends up being the same. And given that algebra is more natural for computers, I can see why quaternions might be useful here. But geometric they are not.
Quaternions are seen as this abstract 4D space somehow containing 3D space transformations, and people have a much harder time visualizing 4D space. I do not think spending a lot of time trying to visualize this 4D space, like this video does, is the right way to go. Rotors make that method obsolete.
Thinking about a scalar + bivector as the quotient of two vectors or as the composition of two reflections is easy enough. But that still doesn’t yield a solid understanding of how rotation works – 3D rotation is subtle and tricky, even for people who have pretty good spatial reasoning and a lot of experience working with solid geometry / 3D design.
I have been thinking about the best interactive diagram(s) for giving people a good intuition about that for a long time, and I have some ideas but I still haven’t implemented anything and I’m not sure how well it will work.
The real shame is that the best opportunity to introduce physicists to geometric algebra was a hundred years ago when we were first discovering spinors. First the Pauli algebra and then the Dirac algebra. If physicsts at the time had been made aware of the geometric algebra approach to these things, I think it could have been an appropriate motivation to switch to geometric algebra. Instead, people came up with matrix representations of the Pauli and Dirac algebras and the field is stuck using those and saying "meh. Good enough."
For most of the usecases associated with the examples you mention - Pauli and Dirac algebras - I don't think it matters very much. For instance, I haven't seen a decent QM course that doesn't devote at least a lecture or two to discussing the origin of Pauli matrices and the associated abstract algebra and group theory - as they should - but I don't think the course would be any more concise or useful (in terms of the physical content) if it then proceeded to treat QM in the language of geometric algebra. There's nothing wrong with the matrix representations (especially in a more computational context), though obviously one should know where the representation comes from and how to derive it.
I would argue that E&M and anything involving rotations (or Lorenzt boosts!) are two great examples where GA is miles ahead of anything other than differential forms but still has modest advantages of differential forms as well.
The main advantage I see in geometric algebra is that its a unifying framework. The same langauge used to understand E&M in GA is also useful in quantum mechanics, general relativity, complex analysis, linear algebra, etc. I'd argue that physicists don't mind this mish-mash of notations because they've already put in the work to learn them all separtely but I think there are real advantages (especially pedagogical) to unifying them into one framework.
Your first point got me curious, though. I found E&M in differential forms quite satisfying from an intellectual point of view (although of little practical benefit to the problems I was interested in compared to the classical approach, which I was plenty familiar with already). What advantages do you see for GA vs. differential forms in this context? This might make for a few interesting seminars with our math folks...
I'm a math professor. To me "geometric algebra" refers to any use of geometry in mathematics to illuminate algebraic principles. There are very very many of these -- this article illustrates one good example. I try to incorporate intuition from geometry into my teaching whenever possible.
It seems that the two of you are referring to some particular unifying framework, and/or set of definitions and notation. Could I ask you to elaborate on what you mean?
Thanks.
https://en.m.wikipedia.org/wiki/Geometric_algebra
https://en.m.wikipedia.org/wiki/Clifford_algebra
For teaching geometric algebra, there are curricula and textbooks available...
http://geometry.mrao.cam.ac.uk/home/introduction-to-ga/
https://arxiv.org/abs/1205.5935v1
http://www.faculty.luther.edu/~macdonal/GA&GC.pdf
http://assets.cambridge.org/052148/0221/sample/0521480221WS....
This looks a bit too high-level to inform my undergraduate teaching, but certainly I could learn something from this.
http://geocalc.clas.asu.edu/html/Evolution.html#References
under "Recent Books". Notably "Clifford Algebra to Geometric Calculus" and "New Foundations for Classical Mechanics" by Hestenes.
PD: if you ever attempt to read any of those two, I'd advise to go to the latest (corrected) reprint.
Less ambiguously called "Clifford algebras", though Clifford himself prefered the term geometric algebra.
Now consider relativity, which was originally motivated by Maxwell’s equations. We can describe flat spacetime as a 4D space with the Minkowski metric, which we can extend into a geometric algebra Cl_1,3(R). We can then describe field and current as multivectors, and we end up with the equation (singular!)
∇ F = µ_0 c J
This has the additional property that it captures how observations of electromagnetism change under Lorentz transforms. If you think of a Lorentz transform as just a change of basis in spacetime algebra, and if you think of electricity and magnetism as together being the basis for electromagnetism, then it’s obvious that (for example) a moving observer would see a magnetic field generated by a stationary charge.
This is obvious because the basis change from a stationary to moving observer will directly correspond to a basis change from an electric field to a magnetic field. This is simplifying a bit but I find it easier to remember and reason about the geometric algebra version of many of these formulas.
Also, I've seen several articles trying to convince me that alternative transformation representations like these are better, but I haven't seen much code. Has anyone written a library using these concepts that could replace a traditional vector math library like https://glm.g-truc.net/ for games?
This is because quaternions are a subalgebra of geometric algebra in 3-space.
You can prove, for two rotors R1 and R2, that slerp(R1, R2, t) = R1 (R1^-1 R2)^t.
I have not seen a clean version of the code online but it is almost the same as for a quaternion.
Those bivectors just explain (incredibly, amazingly well) what quaternions are and why they have properties they have. It doesn't seem to change how you crunch the numbers to get what you want.
...
It's really great that you wrote that post. I feel like for the first time I truly understand rotations in 3D and know why I felt something fishy was going on with results of vector product and expressing rotations with them.
The real power of the GA version is that you can more clearly geometrically explain what is going on, and you can generalize everything to pseudo-Euclidean spaces or to lower or higher dimensions. GA gives you some more algebraic tools to work with, so when you are trying to write your proofs they are clearer and more concise.
> The change is simple and the code remains almost the same. Anything you can do with a Quaternion, such as Interpolation and avoiding Gimbal lock, you can do on a Rotor. But the understanding grows a lot.
Yes, the C++ library you're looking for is here http://versor.mat.ucsb.edu/
If you use a scalar + bivector “rotor” representation, that is only a 4-dimensional representation, which is easy to normalize to unit magnitude.
Just letting you know that I think it's valuable to bring up matrices into this discussion, even if they do have problems in practice with rounding errors and efficiency.
Bivectors in general are conceptually great; it's just the geometric product which I think is conceptually flimsy. And it's surprisingly hard to compute or make sense of the geometric product in general which is why the writer of the first book cited on the OP wrote "I do not think it possible to give a quick definition of the general geometric product."[1]
As far as I can tell 95% of the usefulness of geometric algebra is the usefulness of the wedge product ∧, which is absolutely under-appreciated and appears in loads of places in disguise (for instance, the determinant of a matrix is the wedge product of all of its rows or columns together).
The last 5% of the usefulness of GA comes from using the geometric product in vector-rotation via -ava^-1, which is admittedly very useful (it's why physics and computer graphics represent rotation this way, albeit in disguised forms like Pauli matrices and quaternions.) You can express that form without the geometric product, but I haven't found a way that strikes me as very elegant.
I don't mean to condemn GA - I think what it's doing is massively important. The mathematical language for vector analysis deficient compared to what we could be using, and a lot of things are more intuitive and natural in better language. I just suspect that the, uh, ideal form of this stuff will look slightly different than GA, and might not include the geometric product at all, but will definitely include the wedge product absolutely everywhere.
(I've spent a lot of free time trying to figure this out but I don't really have a compelling result yet. I've been meaning to try blogging about it, though, since it's basically my favorite thing to study.)
[1] https://math.stackexchange.com/questions/444988/looking-for-...
In particular, it is what lets you take products, inverses and quotients (assuming the denominator is non-null) of arbitrary vectors.
> surprisingly hard to compute
Hm? No it isn’t....
Several times in the last few years I have done several pages of complicated calculations in terms of coordinates or matrices, where the intermediate steps were basically an indecipherable mess of symbols, and then sat down, really thought about what I was doing for a while, and re-written it using GA language and ended up simplifying my work down to a few lines of simple algebraic manipulations, where I could typically then give a nice geometrical interpretation to each step.
If you want to compute the geometric product using concrete numbers in terms of a basis, then it is straightforward to write the code (or work through by hand).
What is hard is not the geometric product. What is hard is geometry! There is a lot of depth and subtlety, and it takes years to really learn your way around. That is not the fault of the language though; there is a certain amount of irreducible complexity involved.
Personally I would love to get some people together and try to write a high-school-accessible geometry / vector algebra book using GA language. It would be a few years of hard work, because figuring out the right order for the curriculum, the right types of problems to build intuition, which tools to include or leave out of an introductory book, how to best show the work for a whole collection of worked examples (ideally with some interactive computer diagrams), and so on.
I'm arguing in favor of most of GA's language. I just keep finding that the wedge and inner product parts are fantastic, and the geometric product part isn't. And I think the reason people keep finding GA appealing is because they didn't have the wedge product before, so having that in their conceptual toolkit fixes a lot, while having the geometric product doesn't fix much on top of it. Anyway I've studied GA a lot and I still have basically no idea what 'AB' means when both are arbitrary-grade multivectors, and as far as I can tell most sources don't even try to explain it.
> I still have basically no idea what 'AB' means when both are arbitrary-grade multivectors
Any mathematical language (or any natural language) can express a bunch of nonsensical and useless things. What is the sine of the square root of the logarithm of the tangent of some polynomial applied to a scalar? Who knows?!
You can certainly make up nonsensical expressions using matrices, differential forms, etc.
In a concrete problem, sometimes you have to think a bit to figure out what the geometrical meaning is of a particular multivector, but if the problem came out of a physical situation, I haven’t yet found a case where I couldn’t explain it.
Your multivector might be an electromagnetic field. It might be a rotor. It might be a representation of a sphere in the conformal model, ...
Geometric algebra will be here waiting for when you get tired of resorting to the hodge dual to take an inner product ;)
I agree that the Hodge Dual is easily the worst part of exterior algebra. But you can treat the inner product as more fundamental, via *a ∧ b = <a,b> i. Either can essentially be constructed from the other (iirc).
Let {e1,e2} be an orthonormal basis for R^2.
Let i = e1e2.
Then i^2
= e1e2e1e2
= -e1e1e2e2 (anticommutivity)
= -(1)(1)
= -1.
Personally that alone is enough to justify learning more about geometric algebra.The student who is being advised to learn integrals might similarily protest that "everything people love about integrals, could much more easily be understood by just the desirable parts: limits, of summations, of products. It is unnecessary overkill to learn the theory of integrals like int(f(x), x=a..b)+int(f(x),x=b..c)=int(f(x),x=a..c)". So yes to prove the theory of integrals you will need to understand limits, sums, products, .. but the resulting properties like the identity above are undeniably invaluable ...
Imagine being a student in an alternate history, where integrals were never defined, of course they can still derive all the results (minus the results stating things about integrals themselves) which we arrive at through our current application of integrals by means of limits of sums of products. But then every derivation that in our world would sanely use integrals would be a long verbose derivation, which they might call "limited totalizations" without reifying this concept. So they are basically rederiving the same result over and over. That's when people normally add syntactic sugar to avoid repitition. Now imagine being this student following such a course, and further imagine that before following this course you had always been somewhat of an autodidact in high school etc, so half the time you are reading your course notes and half the time you are reading books out of curriculum. One day you stumble on some "integer math" book, and then while reading you realize this is not about integers, so you reread the title and it actually reads "math of integrals". After reading on you realize that all the verbose and highly redundant notation in "limited totalization" class can be avoided. Thats what I experienced: I was reading random books about "algebraic geometry" and one of them was totally whacky and off and not algebraic geometry, then I notice the title is actually "geometric algebra". I was in my 3rd year physics. So the people who are paid to teach me are giving me shitty calculitis, most of them are simply unaware of this field, some of them are but are daunted or simply lack the time to go back through all the knowledge they have learnt and rephrase them into this language, and even if they could, it would require the whole curriculum to change in "sync" (well, with a delay of one year per generation...). It really is inertia. The number of people who have come to understand and use geometric algebra are simply fewer than the number who have come to understand and use normal linear algebra, hence there are more books on normal linear algebra. Just like the number of people who have learnt to read and write is larger than the number of people who understand linear algebra, and hence there are more fiction books, magazines...
However I believe the situation is slowly changing in the right direction, computer science didn't have compilers either for a while, sooner or later people get bored of spaghetti code...
[0] A funny anecdote is that Maxwell -the king of unification in physics- was forced by his publisher to dumb down to this coordinate notation. His original submission used Hamilton quaternions, which had also been recognized by Clifford, who had based his work off of Grassman's "geometric algebra". Clifford called the algebra "geometric algebra", but readers of Clifford started calling the subject of Clifford's work "Clifford algebra". Or something like that, I don't pedantically check history claims...
I think Ben Lynn's approach is actually better: https://crypto.stanford.edu/~blynn/haskell/ga.html (Part 1)
It starts off more abstract, defining the geometric product simply as string concatenation (as in "free monoid" if you're familiar with that term, which you would if you have intermediate Haskell knowledge) plus a very natural constraint. From this natural constraint one can then deduce the sum-based interpretation that the OP gives.
The natural constraint is then further generalised and justified in more detail in Part 3: https://crypto.stanford.edu/~blynn/haskell/cga.html
The outermorphism of a linear transformation is a useful and convenient (but sometimes tricky) concept. It gives you not only determinants, but also the application of your linear transformation to arbitrary multivectors.
Also, it's really intuitive. At least I found it really intuitive when it was first explained to me.
Of course, the inner and outer products are also very useful, but I introduce them only at the last stage, as some extra notation, not to help understand new concepts.
Basicallt, quaternions are hard to understand but easy to use.
I think it's called gimbal lock?
Each video is interactive, just pause and tweak the 3d visualization. The videos are very good!
I have never really understood quaternions. All I knew is that I could use that instead of euler angles, avoid gimbal lock, and would blindly use them.
Exactly. And then you forget about them because...well, it's not like this stuff requires maintenance. Once you abstract all rotations and interpolations away, you just use them and forget you don't really grasp why they work.
And I don't see a case being made that demonstrates that for the purpose of a 3D engine, this actually "makes more sense". It's just a different way to compute the exact same results. If I'm writing a game, or simulation, or 3D visualisation, I literally don't are how the engine does what I tell it to do, as long as it does it.
At some point, people will have to write and maintain these 3D engines. Having easier to grok maths at that point is a Good Thing.
These are just two constructions of isomorphic Clifford algebras which really are the same thing.
This is just like how the complex numbers are isomorphic to the even subalgebra of the 2D geometric algebra.
The geometric algebra is richer, more powerful, more generalizable and more coherent than the quaternion algebra, all while being easier to understand because its so physical.
So what is the equivalent structure I'd use with trivectors to combine arbitrary 3D transformatinos into a single operation, like every 3D engine needs?
The linked Versor library was also not very helpful -- it has the rotate operation on a vector, but I found no 'make rotation' and 'make translation' and 'make frustrum' and 'apply transformation' and 'concatenate transformation' operations.
This way, one gets the wonderful properties of geometric algebra and the useful properties of dual quaternions together.
Also I believe that technically they call under Clifford algebra.
Also I believe that technically they call under Clifford algebra.
I think that there is a lot of useful structure in the geometric algebra that gets thrown out when one moves to talking about its subalgebras (ie. quaternions, dual quaternions, vectors, etc.).
Its ultimately up to taste but I often find that I prefer to use the full GA instead of its subalgebras. Often some unexpected beauty or useful result drops out!
In all seriousness, both rust and geometric algebra are really very cool; but their proponents are so ridiculously over-enthusiastic that it is easy to get tired of them before taking them seriously.
Likewise, if you needed to store or transmit spherical camera interpolations or non-player or player character transitions over a network this information would also have to be provided. You could perhaps do some optimization, e.g. only sometimes transmitting the origin once and then only sending the bivectors and angles in some cases which still would waste bytes and increase complexity. And, sometimes you couldn't so you'd have to send the whole thing.
But, with a quaternion you get this for free without any logical gymnastics via the previous four scalars to the next four scalars between delta frames. And, in the case of slerp only the lambda of time.
Now you can argue that a rotor could be used locally and then when storage/transmission is required you could convert to and use quaternion math to perform the necessary interpolations and thereby get the space savings. However, this article is specifically asking for the complete removal of quaternions from the field of computer science.
Unless I'm misunderstanding. Though I haven't seen a code example where rotors don't require this extra information. For example, in libvsr they have examples that require all these pieces for each frame. However, maybe that is an inefficient or naive implementation.
I did find this: http://geometry.mrao.cam.ac.uk/wp-content/uploads/2015/02/01...
Which provided a formula for rotor slerp: R(lambda) = (1.0 / sin(theta)) * (sin((1 - lambda) * theta) * R0 + sin(lambda * theta) * R1)
If that is the case, then the bare minimum information required is still more than a quaternion. We'd require the lambda, theta, and R0 (4 scalars), R1 (4 scalars).
It lives inside a geometric algebra which also includes vectors and trivectors, but those are not part of the rotor.
If you store a rotor as a general 3D multivector, it will have 8 entries 4 of which are always 0; this could be done to simplify your code (then you only need one multivector type), but is not a good idea for efficiency of computation/transmission if you need to represent large numbers of rotations and their transmission might be a bottleneck.
What’s going on?
You can work everything out by breaking it down to the unit basis vectors, for which the products are explicit. One way of writing it, which feels more comfortable to me possibly at the expense of being the "wrong" sort of intuition, is
u(v^w) = (u.v)w - v(u.w) + u^v^w
(using . for inner product and ^ for outer product). I guess you can also think of the first two terms as the rule for taking the inner product of a vector and a wedge product, though I haven't thought through this completely.
Because of the repeated vector in the reflection formula, that last trivector vanishes, so the result is just a vector, as it will be whenever the vector is coplanar with the bivector.
I suppose this could be answered if you explicitly stated what set the geometric product acted on. As a guess, and from skimming Wikipedia, it’s the direct sum of scalars, vectors, bivectors, etc, up through n-vectors. So 2 + x∧y + 3x∧y∧z is a valid output. And it’s probably straightforward to show that the geometric product is actually defined on this space.
(Hi Marc!)
So, you basically have three case: x (xx) = x (1) = x -> a vector
x (xy) = x (x.y + x^y) = x (x.y) + xxy = x (x.y) + y -> a vector
x (yz) = x (y.z + x^y) = x (y.z) + xyz -> a vector + a trivector. This only happens if the three vectors are independent, which can never be the case for -ava
However, as soon as you want a 3D rotation (eg. in a flight sim) then you really need a way to represent them that doesn't suffer from gimbal lock or have any singularities.
Note: even with an FPS, you do typically want some more complex camera movement (for certain actions or animations that tilt the camera) or need to orient something relative to the camera (like the gun). Euler angles do not allow you to compose rotations, and so for this you'll need to go via an intermediate representation such as quaternions or matrices. Probably this is handled by whatever engine you are using though.
But, I find that I often need smooth, arbitrary rotations for other things, so I just use quaternions everywhere. When using Euler angles as input, I immediately convert them to quaternions.
I had to calculate misorientations between many pairs of orientations. If I treated quaternions as a whole, I would find their quotient and then get the angle. But since I know what the components mean, and I know I can get the misorientation angle from just the cosine (the scalar component), and I know that I can get this value from a simple dot product, I can easily save a few operations to calculate every misorientation. And since I have to calculate many of them, this change supposed a big speedup.
Black boxes are nice when learning or thinking at a high level, but if you frequently use a black box, knowing what is inside will probably become useful at some point.
GA is less complicated and more intuitive than the maths of quaternions.
So your comparison does not really hold up.
There should be a way to write a library that translates geometric algebra notations into their corresponding quaternion ones, and reciprocally.
Geometric Fundamentals of Robotics - by J.M. Selig 1996, 2005 2nd Edition
Like what - they are the objectively best representation of rotations...
GA(3) use objects that are isomorphic to quaternions to represent rotations but is much more comprehensible and generalizable than quaternions.