627 points · by lelf · 6y ago · 326 comments
I worked in a game engine where a pair of mathy programmers fell in love with Geometric Algebra, and use this same argument that quarternions ought to be replaced to overhaul all of the math code in the engine using Geometric Algebra. The character rigging system removed matrices and used GA instead.
This caused several large problems in the code base:
For one, it slowed the code down a little because the GPU interface is all matrices, so there were conversions to matrices all over the place, rigging in particular.
And only two guys in the studio knew Geometric Algebra, and they didn’t invest time in teaching it or helping people understand it, they just hoisted it on everyone. All the rest of the programmers knew matrix math but not Geometric Algebra, so they would end up avoiding touching any of the GA code, i.e., any code that dealt in transformations. The two guys ended up with a lot of support of their own creation, but they were short with their answers, in part because they got so many questions, so the problem never went away.
The third problem is this whole rewrite was unnecessary. Fixing gimbal lock with quaternions is a tiny corner of the game engine, whereas using GA throughout is a massive rewrite. Matrices work really well for 98% of the code, and it’s not really a huge problem to have one or two routines that convert to quaternions and back while they do a rotation. It is a problem when any transform at all involves bivectors and rotors and you have no idea what the hell those are nor do you have time in your schedule to take a math class at work.
Personally, I’m intrigued by GA and have wanted to learn it for a while, but having used it in production, I’m mildly against replacing quaternions with GA, and very wildly against replacing matrices with GA.
Quaternions came into favor to solve the problem of gimbal lock in composed Euler rotation matrices. This happens when you create a rotation which rotates one axis into another, and end up with a matrix that loses one axis (it loses an eigenvector), and you become "trapped" in the new rotated frame and can't ever rotate out of it. Quaternions don't suffer from this problem, but they're also tricky to work with and reason about, and their rotations can become funny when composed - instead of rotating from orientation A to B, they'll go through a C in a very different place. You need to create heuristics to keep rotations looking sane with quaternions. In the games that I've worked on, we took other precautions to avoid gimbal lock in rotations and stuck to Euler matrices. For example, in a flight simulator, you always computed the final rotation matrix for the plane location directly from its heading, pitch and roll, and so, you'd never suffer gimbal lock.
Why stick to Euler matrices and not some better Geometric Algebra or Quaternions? Because it's really easy to interpolate, and think about plain old rotations about a vector, and you can teach anyone to avoid gimbal lock. It's easier to avoid that problem than to train a bunch of junior engineers on higher level math.
It's interesting to compare disciplines, since I've never worked on a game engine but have done a lot of simulation of physical systems: there, quaternions have been standard for at least fifteen years, and I've seen geometric algebra frequently for about the past five.
Interestingly, where we saw most gains from thinking about geometric algebra wasn't in simple rotations, but when starting to look at things like computing kinematic chains composed of dozens of joints: Now we're at 4x4 matrices to store each transformation, which is the traditional way and works well. From this, some seriously deranged mathematicians introduced the concept of an eight-element dual quaternion (essentially, pair of quaternions specially constructed) that can represent this. Again, super efficient, but even more intractable for newcomers than quaternions. At this point, starting to express both concepts in terms of geometric algebra has been able to keep most of the performance improvements as well as only having to teach one concept.
When I left that position a year ago, we were starting to see recent graduates that already had pre-exposure to geometric algebra concepts before even starting to work on the codebase.
Quaternion interpolation works well, but it introduces twist, which is sometimes not what you expect. When you start composing many quaterions, you get some wild rotations, going the long way, or doing an additional 360 twist, and whatnot. Mind you, I'm digging 20 years back in my brain here, I don't remember many specifics anymore.
Matrices and Euler angles are both horrific to interpolate.
That said, taking your argument to the extreme, we all probably should've stuck with PHP, since everyone understood it and, well, was it really worth the switching cost? Naturally that's dumb, so there's a certain amount of "how do we get there?" with any new technology that's probably a good idea.
That's probably not going to get answered by the principal engineer who says This Tech Is The Future. It's going to get answered by people like you who think about switching costs and the impact new tech has on people.
There are multiple paths for honing a new technology, without dumping it on a large group of developers while it's in its experimental stages:
- Use it for a series of side-projects
- Use it in a startup or startup-like team in which all the developers are bought into it, and happy to work through the obstacles
- Use it at an organization that's both able and willing to devote a large amount of resources to making it work (e.g. devoting a full-time team to its development & support & related training)
Once the kinks have been sufficiently worked out in one of those contexts, and a solid ecosystem with good documentation exists, then there's a much better chance that the benefits will be worth the switching costs for the average project.
I imagine AAA games are similar. You have 4 years and ship one monolithic game. Maybe you could prove out this idea in a small area like artist's tools or an engine fork (similar to the approaches above). Trying to incrementally adopt something would take 2 or 4 games (10+ years) and I just don't see technology roadmaps like that. Especially if it's not a huge win.
The problem with what they did, and what this article is doing, is suggesting we “fix” something that takes 2 or 3 math classes to understand by replacing it with something that takes an entire semester to understand.
I honestly believe that GA has insights to offer, but I don’t believe it will save any time to upgrade the use of quaternions in any 3d engine.
The major proponents of GA don't suggest doing this. I'm not an expert so I can't rule out the possibility that somebody, somewhere has done it successfully. Computer implementation of GA is still a research topic: http://geometry.mrao.cam.ac.uk/2016/11/ga-2016-lecture-7/
There is a very strong flavour in the computational GA literature of directly implementing the GA operations—not translating to vector algebra. jessermyers is expressing a minority opinion when he says "don't do that".
Finally (and this might be a bit rude) I'm dubious about your assessment of your coworkers fluency in GA. Maybe they seemed totally facile with the bits they knew. In general, though, non-speakers can't assess fluency (in any language, right?). Similarly, what are you actually saying when you say that you "believe" GA has insights to offer? What is that confidence/assessment based on?
Applying GA is an active research field—it's not something people attain practical mastery in, just yet.
Time spent -- You're probably right. For new technology, it's probably worth the research to see if code clarity is worthwhile...
Just look at something like a 50 year old IBM mainframe vs. the newest Sql Server with .Net Core running on the server of your choice. Is the latter the better choice for a new application? Yes. Yet many very successful businesses don't replace their mainframes because the benefits do not justify the costs.
Very fancy and neatly structured code but in the end you accomplish pretty much the same; and now nobody on the team understands a bit about what you're doing.
"Why would we use a framework that nobody understands but you, to accomplish the same stuff a few SQL statements can do?"
The former option never wins.
D3D API exposes a way to pass constant buffers to shaders. You can pass whatever you want there, even integers. There're couple limitations, size must be multiple of 16 bytes, and can't exceed 64kb, but I don't remember anything specific to matrices.
Now, the only place I can remember which specifically targets matrices - mul intrinsic in HLSL. But that thing is just a syntactic sugar, usually compiling into dp4 dxbc instructions.
The problem is that all libraries, drivers, etc. use matrices, quaternions and vectors. So you would have to constantly convert back and forth, which is both error-prone and a non-trivial performance problem.
Of course, you could build your own libraries for everything, but that's just crazy. Who has time for doing that?
Not to mention that writing a mathematical library like that is a highly non-trivial task. Not just the algebra part but also numerical stability and accuracy are a big deal. That requires a very skilled person, naive implementations will rapidly blow up in your face.
And doing all this what for, exactly? So that the GA explanation of rotations doesn't require 4 dimensions while the math complexity of rotor algebra ends up being the same as with quaternions? So there isn't really a performance benefit neither.
You can represent a lot of algebraic objects and operations using matrices and linear algebra operations. The most accessible example of that is probably complex numbers: https://en.wikipedia.org/wiki/Complex_number#Matrix_represen...
and I wouldn't say that "matrices are still required in complex numbers" any more than I'd say "matrices are still required in geometric algebra".
Huh? I thought quaternions don't have any problem with gimbal lock. That's a problem with Euler angles and matrices.
Edit: I think you meant using quaternions to fix gimbal lock problems with matrices, which makes sense.
Two years ago, my wife asked me, "If you had to get a math equation tattooed on your body, what would it be?" I answered, "i^2 = j^2 = k^2 = ijk = -1".
I felt a brief flush of anger when I saw this headline.
This is an extraordinarily good article that should be read by pretty much anyone doing graphics programming.
You're like this Irish bridge that has the notation inscribed on it as well.
I would like to own an OpenGL kettle with the expression on it.
If anyone's curious the story is here: https://en.wikipedia.org/wiki/Utah_teapot
Do you mean the Utah Teapot?
Could you explain why? For someone without a math background, it seems indeed like a pretty arbitrary thing to define.
(I can understand the idea behind complex numbers and how the multiplication rules followed from the desire to define the square root of a negative number - however, so far, I don't get the motivation of introducing even more "special" elements)
That's a bit reductionist. You don't just get the square root of a negative number, you get the Fundamental Theorem of Algebra (an Nth degree polynomial has N roots), which is a mathematical power tool if ever there was one.
Complex numbers dramatically simplify a bunch of proofs in linear algebra, give us tons of nifty integration techniques in complex analysis (the techniques are relevant for real numbers, they just use C), provide a representation of 2D rotations that can be manipulated using the rules of algebra (this is the most relevant to the thread), and give physicists, electrical engineers, and signal processing people an abstraction to represent oscillations (energy sloshing between two buckets = two elements of a complex number, which you can then do algebra with). They're a workhorse.
Quaternions are an attempt to do that in 3D. The dot and cross product of vector calculus are other pieces of those efforts. Unfortunately, vector calculus escaped the "math lab" before it was complete and got written into other fields and engineering books, so even though the underlying concepts were eventually sorted out (it's called Geometric Algebra), everybody just uses the half-baked abstractions (quaternions, dot product, cross product) which are Good Enough. It's a perfect example of "worse is better" affecting something other than software engineering.
I guess the question is, why does it then stop. Why not a 4D alternative. Or if you look at it going by scalars needed in a single value, it goes from 1 to 2 to 4. Why not 8 or 16 (or some other growth)? Why does it stop there?
Also, is there as easy of a problem to understand introducing the 3D technique (be it quarternions or be it Gemoetric Algebra) that works as well as using sqrt(-1) for imaginary numbers?
As for why one might want to consider such a noncommutative division algebra in the first place, the answer I suppose is just that it manages to pop up in a variety of areas in mathematics. We've already seen the connection with rotations in 3-space (the topic of this post). Here's another. The 3-sphere (that is, a sphere in 4-dimensional space whose surface is itself 3-dimensional) can be realized as the multiplicative group of unit quaternions spanned by {1,i,j,k}. Consider the circle H = {cos(theta) + i * sin(theta)} for real values of theta; H is a subset of the 3-sphere. If r is any unit quaternion, then the coset rH is another circle. But given a subgroup H of any group G, the left cosets of H in G form a partition of G. Therefore, these circles just described form a partition of all of the 3-sphere (the Hopf fibration).
Speaking of rotations, the involvement of quaternions should not be surprising. Indeed, complex numbers are intimately involved in rotations in 2-space (multiplication by a unit complex number e^(i*theta) corresponds to rotation about the origin by theta). Quaternions can similarly express rotations in 3-space, but one cannot just left- or right-multiply but must instead use conjugation. In general, one can generalize this using the techniques of geometric algebra.
His carving, if it ever existed, is gone. But there is a plaque on the bridge commemorating the event. It reads:
Here as he walked by on the 16th of October 1843 Sir William Rowan Hamilton in a flash of genius discovered the fundamental formula for quaternion multiplication i² = j² = k² = ijk = −1 & cut it on a stone of this bridge.
I got to the point where I needed to cite an original source for the quaternion equations, so I cited the bridge.
He got the message.
Why do I like it? I am, as klodolph notes [1], a dyed-in-the-wool algebraist. It's where I find the most beauty and joy in mathematics.
[1] https://news.ycombinator.com/item?id=22202606
This invention/discovery is a fundamental development in abstract algebra, not a terminal one. Quaternions are just a jumping-off point, and I've always found the Caley-Dickenson construction that pauldraper explains[2] absolutely beautiful.
[2] https://news.ycombinator.com/item?id=22202513
Why would I want it specifically as a tattoo? jfengel points out the special history of that specific equation[3]: it was (allegedly) carved into a bridge in Dublin when Hamilton stumbled onto it, but the carving is gone. Kinda fitting to give it new permanence.
[3] https://news.ycombinator.com/item?id=22202513
So, putting it all together: it's a fundamental development in abstract algebra, which is my jam. It's could have been permanently inscribed in a bridge, but that's been lost to time, so giving it new permanency seems fitting.
Also, it's practical. My first thought was actually the Cayley table for the Klein four-group[4], but that would be a lot harder to get tattooed in a nice visible way. How I went from there to Hamilton's quaternion equation is left as an exercise to the reader. (If you're new to Cayley tables, they're just fancy times tables. Replace "e" with 1.)
[4] https://en.wikipedia.org/wiki/Klein_four-group#Presentations
1. Complex numbers have associativity and communitivity of multiplication. (That is, (ab)c=a(bc) and ab=ba).
2. Quaternions have associativity but not communitivity.
3. Octonions have neither.
4. Sedenions [2], trigintaduonions, and not associative, commutative, nor even alternative [3]. (Alternative is associative specifically when the middle value is equal to one of the other's; i.e. a(ab)=(aa)b.)
[1] https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_constru...
If I had to get a math tattoo, I think I'd go for lim n→∞ Q_n^(1/n) = e^(ᴨ^2/(12 log 2)).
That comes from a theorem proved by Khinchin and Lévy. Khinchin proved that for almost all real numbers if you take the sequence of convergents of their continued fraction expansion, {P_1/Q_1, P_2/Q_2, ...}, then the sequence {Q_1, Q_2^(1/2), Q_3^(1/3), ...} approaches a limit, which is the same limit for almost all real numbers. Then Lévy determined the value of that limit, which is now called either Lévy's constant or the Khinchin–Lévy constant.
If not that, then this (in standard math notation rather than the verbose notation I'm using here):
Line 1: Let H_n = sum i=1 to n 1/n
Line 2: Hypothesis: sum d|n d < H_n + e^H_n log(H_n) for all n > 1
That's neat because that hypothesis is true if and only if the Riemann hypothesis [1] is true [2].
The Riemann hypothesis is a conjecture about complex numbers, and is widely considered to be the most important unsolved problem in pure mathematics. That it turns out to be equivalent to a such a simple conjecture involving just integers and a couple real functions from pre-calculus is a surprise.
It can go next to the skeletal formula for benzaldehyde on my imaginary nerd canvas.
picking one up to unique isomorphism should be good enough ;)
And Euler's formula is about rotations in a 2D plane and the way complex exponentiation describes it.
This looks like it loses important information ?
> Instead of using this thing you don't understand and investing the time to understand it, why don't you use this other thing you don't understand, and invest the time to learn that instead.
Indeed, later in the article the author says:
> We can notice that 3D Rotors look a lot like Quaternions ... In fact the code/math is basically the same! The main difference is that i, j, and k get replaced by y∧z, x∧z and x∧y, but they work mostly the same way.
Have I got that right?
He also gives a concrete reason: For 3D objects, rotors operate fully in 3D, whereas quaternions are in 4D. This means you can visualize rotors and imagine "how they work" whereas with quaternions, you have to more or less blindly trust the formulas.
This is a bit of a stretch -- by the same logic any operation on more than three numbers means I have to trust the formulas. We have many methods to understand, visualize, develop intuition, etc. in such cases, such as "fix a, look at what happens when you vary b, c and d". When I am working to understand dynamics of an object with three variables in MATLAB or similar, I seldom (probably never) plot it in 3D (which gets projected on the surface of a flat monitor anyway). Instead I usually play with numerous 2D and even 1D plots. My 2c.
By this, the author means: you can visualize a rotor FULLY in 3D, no extra dimension neccessary.
I suspect you never have tried to think about how quaternions work mechanically, I suggest this neat video:
In this case, a 3D visualisation is the right tool because the problem is all about objects in 3D space. So rotors let you mentally work with the same objects you're thinking about anyway instead of switching to some other concept or representation.
I don't see that "it's technically 2D anyway because it's projected to the surface of my monitor" is a valid argument. My visual system knows pretty well how to deal with pseudo-3D objects, thank you very much.
This is a very interesting point. Have you tried VR? Do you think this preference for 2d and 1d is just because 3d display technology is still inconvenient or is it something deeper than that?
If it means rotors can be used to give a simple formula for rotations in 3D space, then it also applies to quaternions.
If it means the space of rotors is three-dimensional, then it's false: rotors have 4 coordinates, a + b x^y + c y^z + d x^z, just like quaternions.
Does it mean something else? Something that applies only to rotors and not to quaternions?
It's also easy (after reading the article) to understand the operations that can be performed on these things.
It's not as obvious what i, j and k in the quaternions correspond to, or why they have the multiplication table that they do. It's an algebraic construction, not a geometric one and hence more difficult to visualise.
Quaternions and rotors are exactly the same in practice, but the intuitions are very different. The intuition behind rotors involves planes and lines in 3D, whereas the intuition behind quaternions typically involves a unit hypersphere; there's a 3B1B video on quaternions where you can learn more about them.
Quats are quite easy to reason about: a unit quat holds a rotation about an axis: rotation about angle theta an axis given by direction (x,y,z) is quat q = sin(t/2) + cos(t/2)(xi+yj+zk).
Composing quats q1 * q2 is the rotation you get by applying q2 then q1 to an item.
So think of the scalar as holding info about the angle rotated, and the vector part as the direction of the axis.
I don't see how with rotors or quats you can easily visualize composition or more complex actions (and I've used both extensively). "Blindly" trusting the formulas can be replaced by working through a proof enough times until you feel how they work, just like linear algebra, algebra, quadratic formula, etc.
Rotors use a.b with aXb, and quaternions use magnitude and 3D direction vector.
You can write down Maxwell’s equations using the geometric algebra easily, and it will make them better! They will be obviously coordinate independent.
Pretty much anything with a cross product will be better written using geometric algebra.
One of their main uses is to prove the generalized Stokes theorem in n dimensions.
3D rotors are isomorphic to quaternions, so go ahead and rename your variables :).
So, to be as opinionated as the g'parent comment:
The cross product is a hack which only works in certain dimensionalities, whereas the wedge product is the underlying idea, which works in all circumstances.
To be less opinionated:
The cross product is inconvenient because what it gives you aren't the "usual" vectors, they're axial vectors, which behave differently under mirror reflection than all of your other vectors do.
If you would read a few sentences on from where you quote, this becomes evident.
ij = k
is arbitrary, needs to be memorized and just happens to do what you want for reasons that require a lot of working out. (xy)(yz)=x(yy)z=xz
On the other hand requires zero memorization.It's probably my mathematical background speaking, but I find this far from arbitrary. Quaternions don't spring from nothing. It seems to me that (xy)(yz)=x(yy)z=xz needs just as much justification and memorisation ... why should y^2=1?
I guess my point is this. If people put in as much effort to understand quaternions as has been expended in this article, then quaternions would probably be just as easy to grasp and the system being described.
y^2 = 1 is because it's a unit vector. The fact that bivectors are the correct way to view rotations is evident if you look at higher dimensions. Bivectors work just the same way as described here when you want to work in R^n, you just add basis vectors beyond x, y, z. But the algebra they describe no longer forms an associative division algebra over the reals. There is no way to get to the algebra of the (generators of) rotations in higher dimensions from the quaternions.
This is why i would say the quaternions (as built up from the complex numbers) are a non-sequitur and incidental to the structure of rotations.
Then again, I would always argue that one should use complex numbers to think of rotations in R^2, so.... :)
You can do anything you do with our numbers with roman numerals. You could argue that our base-10 system is as arbitrary as roman numerals, or that knowing how to do arithmetic in one system will allow you to do arithmetic in the other one. But that does not mean that learning arithmetic with roman numerals has the same difficulty as with base-10 numbers, and the only reason we find it more difficult is because we do not put enough effort.
I have introduced a few grad students to quaternions and GA. We eventually use quaternions most of the time, but they do not understand quaternions until they see GA (the same as someone may need some base-10 theory before completely understanding roman numerals arithmetic).
You can treat complex numbers as 2D rotors (a 2D rotor is cos alpha + xy sin alpha, so xy can be replaced with i) and quaternions as 3D rotors. But if you build Cayley numbers from quaternions they don't have the same geometric meaning as 4D rotors.
Some memorisation is required, but it is in terms of things that are easily visualised.
Having to remember, out of the six possible permutations, that one of the three correct formulas is the one with the symbols in alphabetical order is much better than remembering the "right hand rule" (or was it "left hand rule"?).
The pitch in the OP is (I think) intended for people who feel pressure to understand why it works. Geometric algebra can be built up yourself by picturing actual rotations, one dimension at a time. It's physical from the start. Quaternions are a finished math system that you have to reverse-engineer to understand. Some people like one approach or the other better.
Some geometric algebra people are kind of true believers. That's probably not helping the notation get traction.
Why not change? Comfort?
There's some return on all that investment. It might pay off or it might not. I think it's a design decision.
Geometric algebra also addresses much more than just rotating stuff, it's just that when you want to do rotations it leads naturally to something very similar to quaternions.
"Even Prof. Willard Gibbs must be ranked as one of the retarders of quaternion progress, in virtue of his pamphlet on Vector Analysis, a sort of hermaphrodite monster, compounded of the notations of Hamilton and of Grassman"
See "History of Vector Analysis" by Crowe or "Hamilton, Rodrigues, and the Quaternion Scandal" by Altmann. Nice to see the author cites these!
The Geometric Algebra comes from Clifford Algebras, which where an attempt to combine Hamilton's Quaternions and Grassmann's forms, and in fact contains both as sub-algebras. In the case of 3D rotations calling them Rotors or Quaternions seems mostly like a different way of thinking about the same thing.
I think this would be more kindly put as "reimagining" quaternions and not "removing" them. The additional geometric intuition from GA does seem useful, and even as someone who has used quaternions extensively (though in a very different context), I would also choose to work with Geometric Algebra as a framework for geometry over Quaternions.
The visualizations are quite good here, it is a good way to understand bi-vectors, you can wiggle them about a bit in 3D instead of just staring at parallelograms on a page. The only criticism I have is that they say quaternions and the cross product come "out of nowhere", but then the way they present the geometric product is equally "out of nowhere".
[1], a point at the origin, is the same as [1 0] - a point at the origin in 1 dimension, or as [1 0 0], a point at the origin in 2 dimensions, or [1 0 0 0], a point at the origin in 3 dimensions.
Similarly, [0] is a zero vector. [0 0 0 0] is a zero vector in 3 dimensions.
Having to know [0 0 1] is a point at the origin in 2 dimensions (with a homogeneous coordinate), while [0 0 1] is a z vector in 3 dimensions (without the homogeneous coordinate), is just silly.
Why did we do this to ourselves?
I think going forward next gen 3D engines will have to account for the improvements in GPU hardware realized by advances in machine learning. Mixed precision matrix multiply at massively parallel scale. As well as the demands of next-gen games. Things like real time ray tracing of deformable meshes ;)
So, the actual point is that the word quaternions (and "these strange i, j, k") is confusing. Rightfully (at least for anyone without a background in maths or physics).
"Let's remove Quaternions from every 3D Engine" -> "Let's remove the word 'quaternion' from every 3D Engine"
(Nice explanations and visualization, anyway!)
No need to distinguish here between API/CLI/GUI.
Check out the demo https://observablehq.com/@enkimute/animated-orbits
Join the discord https://discord.gg/vGY6pPk
Quaternions are actually a separate 'thing' when compared to vectors (which is why their multiplication seems off and the square is a negative number).
Quaternions should be considered a versor (a rotation around great circles), that is a change in direction which is different from a vector.
See this work: https://archive.org/details/cu31924001506769/
We do 4D stuff in 3D engines because it leads to massively nicer and simpler math, like replacing extremely large trigonometric calculations with a few additions and multiplications. It is actually the right way to do things. And bonus fact: it actually makes logical/intuitive sense when you actually try to understand the math.
To be able to unify many geometric objects, like lines and spheres and point pairs and represent the duality e.g. the "meet" of two lines constructs a point (possibly a point at infinity) and the "join" of two points constructs a line (not sure what happens if the two points are identical), .... then you need 5D which is really like 2^5 = 32D in my mind.
But if all you're trying to do is stop being confused by two different things that both look like vectors, but transform differently under spatial transformations (i.e. any vector that is the result of the cross-product is really a different type of vector than the argument vectors, or e.g. normal vectors) then 3D GA is fine. Though really it's more like 2^3 = 8D (1 scalar, 3 regular basis vectors, 3 "axial" basis vectors, and one pseudo scalar).
An efficient implementation would likely need to use a type system avoid representing 8 dimensions directly. Like the cross product of two vectors will produce an element where only the "axial" components are non-zero.
> Personally, I have always found it important to actually understand the things I am using. I remember learning about Cross Products and Quaternions and being confused about why they worked this way, but nobody talked about it. Later on I learned about Geometric Algebra and suddenly I could see that the questions I had were legitimate, and everything became so much clearer.
I tend to agree with the author. I find it a lot harder to work with concepts I don't understand: I'm forced to "fly blind" and just plug in formulas and hope everything works. At the latest when you have to debug something, this can go horribly wrong and leave you without a lot of options.
Besides, your GPU shader code implements fast quaternions, and you aren't going to get NVidia to replace them with rotors. So the game is lost.
Oh, unless you don't mean "understand everything" and are going to draw your arbitrary line at the GPU.
From my personal experience, it can pay off immensely to understand the internal structure of the representation you're working with. I can look at a 4x4 matrix and immediately identify some stuff (does it include a translation component? does it scale and is this scale uniform? is it rotated and around which axis?).
Meanwhile, I can't do this with a quaternion. I know what they do and can understand how, but I have no intuition for what the four numbers mean.
Different people will be okay with different levels of understanding. You put "deep" in quotes. You should also put "heuristic" and "easier", and many more, because all of these terms are up for analysis now.
A very heuristic operation of technology is "power cycling"--"have you tried turning it off and on". Another version is "factory resetting". This is very useful, but without a slightly deeper understanding of what is does, or how computers work, it's easy to waste time doing it. Like if I get a cloudflare message saying some website is unavailable, I'm not going to log out and back in. I'm not going to turn my computer off. I'm not going to do anything. But that requires a slightly deep understanding.
I wouldn't try to argue what's easier and what's harder for people so generally. There are lots of different kinds of people. That's why both the quote and the grandparent are explaining their personal motivations and describing themselves. I mean, you kind of acknowledge this after the fact when you talk about "arbitrary lines", but it still sounds like you're dissing someone's "arbitrary" personality. I mean, yeah, even if it were arbitrary drawn at GPU---that's the sense in which we are individual people...
I doubt using the concept of rotors in place of quaternions would've made my experience any better. It's not the concepts that really frighten me - I can read about them and nod my head, pretending that the information is somehow sinking into my brain; the things that scared me were the equations which, the article implies, are pretty much the same.
In the end, the things (seem to) work as intended in my library, and I can now sleep at night knowing I'll never have to revisit quaternions (or rotors) again in my life.
Game development is not fundamentally more hard than any other field of applied engineering or mathematics. It isn't theoretical mathematics. You just use the math.
Needing to "understand" root construction before "being able to use" is just procrastination.
since I feel personally attacked by that statement (I say in jest), it's more charitably viewed as a risky investment. Understanding now might help you use it more efficiently later.
3D Rotations are traditionally very tricky to represent in a computer! It's only in "modern" times that basically everyone has settled down on quaternions as the best parameterization. I think the comparison to anything about real numbers misses the point. It's not about rotors themselves, or real numbers themselves, it's about how they model something we care about. Money isn't a real number, but we model a balance in an account using one. And an accountant definitely needs to understand operations such as "debiting", "crediting", "accruing interest". So they need to understand addition, negative numbers, and multiplication. But that's just because of the choice of the model.
funny enough, it seems like lots of accounting existed a while before negative numbers were obvious, so there are all sorts of to-me funny ways of representing negative numbers, or subtraction (I don't have any clear evidence to back this up). Everyone was doing accounting just fine before, but really it just feels more obviously elegant to use a negative number to represent a deficit.Also :
You "can" be a "good" engineer while thinking the Earth is flat. (Unless you're working on space-related projects of course.)
You "can" be a "good" scientist without knowing anything about epistemology, Popper, Kuhn...
(But can you, really, be a good one ?)
(Also IMHO most of today's economists are just charlatans akin to the astrologers of old, misusing math because math gets your more respect, and it's probably related...)
[1]: https://www.youtube.com/playlist?list=PLpzmRsG7u_gqaTo_vEseQ...
I don’t claim to have delved very deep in the topic before, but of course it is standard to start with definitions - and I found these definitions particularly clear & disambiguated.
That said, tensors are in fact more general than geometric algebra’s multivectors (in that the latter form a quotient algebra of the former). But not all tensors correspond to manifolds as we know them in physics and I argue that GA keeps track of the geometric properties we want better.
Historically it seems like 3D geometry and particularly cross products in the context of electromagnetism fomented the primary demand in mathematics education for students to be taught vectors. Unfortunately the mathematics curriculum (in Western countries) has not really been updated in decades to better prepare students for the jobs of today; we still enroll all students in a sequence that culminates in differential equations and particularly in second-order linear differential equations, which just so happen to be crucial to control problems in electrical and mechanical engineering. While many people's jobs involve some kind of mathematics somehow, only a few jobs involve the mathematics of electrical engineering, and I suspect that is part of the reason why so many students are bored in math class.
And even further :
IIRC, you don't need cross-product for electrical engineering, and IIRC it (thankfully) isn't (generally?) taught in high school.
Furthermore, later, in college, it would seem that electromagnetics get easier when taught through bivectors rather than cross products (and you avoid the traps with pseudo-vectors and, later, gimbal lock with Euler angles ?).
Maxwell's multiple equations seem to condensate to a single one under GA !
(What if we teach GA it will open the possibility of teaching EM in high school ?)
The biggest disadvantage of using quaternions over Euler axis/angle representations is that quaternions are basically impossible for humans to visualize, whereas Euler axis/angle representations are easier than transformation matrices, Euler angles, or any other representation.
So why not just use Euler axis/angle representations instead? Nobody cares any more about evaluating cosines at 1 kilohertz, and there would be none of this complicated geometric algebra stuff that nobody understands.
Composition of two rotations in axis/angle representation basically proceeds via the quaternionic formula, ie in terms of half-angles. So if you need to do that a lot, it makes sense to go fully quaternionic to avoid having to work with both full and half angles.
He's given a lot of talks on subjects like this. I imagine that what he's doing mathematically is a lot more intricate than most games need though.
He posted an update on the game recently: https://marctenbosch.com/news/2020/01/miegakure-update-end-o...
On the other hand, almost nobody mentions the nice geometric perspective that unit quaternions offer that are somehow "lost in translation" in GA: as a compact Lie group, unit quaternions come endowed with a bi-invariant Riemannian metric which means you can do interpolation, clustering, blending, statistics with them in a metric-consistent manner. And since the metric is compatible with the group structure, the geodesics are cheap to compute.
If the idea is use a higher, more pure math structure, then one can go to even more abstract math formalisms, such as coord-free calculus and bigger algebras, but these, like GA, add more computational overhead to solve problems that don't exist.
Hestenes et. al., the main popularizes of GA in the math/programming intersection, have papers on writing raytracers in both, and they too clearly demonstrate loss of performance using GA.
Now we have twenty, twenty-five years of code and resources that make use of quaternions. In some ways, game development is incredibly hide-bound and conservative, and for the most part eschews rigid correctness for performance, convenience, and a loosey-goosey good 'nuff feel.
And this only happens because the planes are defined as "xy", "xz" and "yz", rather than the more consistent "xy", "yz" and "zx"?
If you just changed the definition of the planes at the start of the derivation, it seems you would end up deriving the exact same operations as you would use with quaternions? I'm not sure if there is a good argument for not doing that.
I'd also be really interested to see some more applications. I wonder what rotor interpolation looks like for example? I know I've had problems with quaternion interpolation in the past.
What is odd about the quaternions' multiplication tables? Is it the fact that the commutative property of multiplication is violated? For the sake of argument, let me assert that it is.
What if at the highest level of abstraction x * y had no obligation to equal y * x?
I'm not sure, but the article's implication that nobody else cares why things work to be distracting and insulting.
> Personally, I have always found it important to actually understand the things I am using.
https://www.youtube.com/watch?v=PNlgMPzj-7Q&list=PLpzmRsG7u_...
This also shows that the talk of needing to visualize 4d to understand quaternions is disingenuous. The formula for using a quaternion to rotate a vector is qvq^-1, from which it is immediate that changing the length of a quaternion does not change the rotation it represents. So you can just deal with unit-length quaternions, which form a 3D space.
Much the same with argument here, sure GA would be better, and maybe that may well come about, but alas quaternions are somewhat known by the many over the few and a bit of a QWERTY situation plays out.
I work in a research field that uses rotations heavily, and trying to use things like Euler angles (with 4 or 5 competing representations) and axis angles has created nothing but confusion among people. If people used quaternions from day one, it probably would have saved, cumulatively, the time of several dozen phds.
Likewise, IMO, learning to use Rotors is easy, but learning how they work is much harder... It's just that it's easier than learning how Quaternions work.
And, also IMO, you don't need to know how either of them work to use them in gamedev. It's fine to use a library that understands them and just continue making the important parts of your game.
Oh that's indeed absolutely what a game dev should do.
A 3D engine dev however, might do well to eat the math leading to the understanding of quaternions, and by extension Clifford algebras (the underlying/original theoretical structure leading to geometric algebra). You get to understand how particular variations in n-dimensions of this structural framework are isomorphic to all numbers like R, C, H and much more. (hyperbolic! dual!)
It really paints a whole arch-picture, a meta-framework to unify all possibly kinds of numbers in one's mind (including the geometry of these numbers and ring operations, with a 1:1 equivalence between geom and algebra).
Note that this is why, I think, some strong proponents of GA (which I find myself agreeing with in that regard) would have it enshrined in K-12 education in lieu of linear algebra — because the intuition of GA is really great / second-to-none, and intuition is all that most math students in high school will ever retain afterwards (they won't do math again, ever, not really). The argument being that people who need more (from linear algebra for calculations notably) can learn that complicated and non-intuitive stuff later (university), building on top of a good base intuition nurtured in GA / Clifford.
So, the 3D engine maker, people in robotics, anyone working with spatial representations of any kind (even abstract, like research with multilinear models) would do themselves a fantastic favor for a lifetime to learn these topics. It's a no-brainer, really, from the other side.
It's delicious math!
* GA provides some nice savings when it comes to rotor/3D calculations, provided that the underlying data structures and architecture supports them. Check out the publications by Dietmar Hildenbrand and his team for several examples:
- https://www.researchgate.net/profile/Dietmar_Hildenbrand
* Quaternions start to exhibit several limitations when dealing with complex objects, even in 3D. It provides just the necessary structure to store quadrature information to avoid the "gimball lock" issue, for example. However the fact that it collapses the scalar with the pseudoscalar presents several problems again in calculations with dual quaternions and higher dimensions (projections, for once), and it's not much different from the hurdle of having to discriminate axial and polar vectors in Vector Calculus. The main issue is that its handedness doesn't scale well and has problems capturing the geometric nature and physics of the world in several dimensions (ie symplectic geometry).
* IMHO the real usefulness of GA is that, as it name implies, it's an algebra. That is what Clifford, Ball, Lie and Klein realized while extending the work of Grassmann on exterior algebras, screw theory, vector spaces and differential forms. Matrices, quaternions and some forms have awkward behaviors when they are treated symbolically as algebraic objects, being "leaky" on information or having singularities just because they are not the best representation. GA fixes that allowing you to formulate problems symbolically, and then you can almost blindly solve the equations with high confidence that the result will be sound. You can then convert the objects back to your favorite representation. For good examples, check out Terje Vold papers on:
- Rigid body dynamics: https://www.researchgate.net/publication/241273951_An_Introd..., and
- Electrodynamics: https://www.researchgate.net/publication/245345681_An_introd...)
[Note: Watch out for some typos]. For comparison, take a look at Featherstone's 6D Spatial Vector representation, which is similar to screws and I think shows the best you could do with Vector Calculus objects:
- http://bleyer.org/files/A%20Beginner's%20Guide%20to%206-D%20....
https://grassmann.crucialflow.com
The Grassmann.jl package provides tools for doing computations based on multi-linear algebra, differential geometry, and spin groups using the extended tensor algebra known as Leibniz-Grassmann-Clifford-Hestenes geometric algebra. Combinatorial products included are ∧, ∨, ⋅, *, ⋆, ', ~, d, ∂ (which are the exterior, regressive, inner, and geometric products; along with the Hodge star, adjoint, reversal, differential and boundary operators). The kernelized operations are built up from composite sparse tensor products and Hodge duality, with high dimensional support for up to 62 indices using staged caching and precompilation. Code generation enables concise yet highly extensible definitions. The DirectSum.jl multivector parametric type polymorphism is based on tangent bundle vector spaces and conformal projective geometry to make the dispatch highly extensible for many applications. Additionally, the universal interoperability between different sub-algebras is enabled by AbstractTensors.jl, on which the type system is built.
Join = ∧, Meet = ∨. Vector = point, Bivector = line, Trivector = area, etc. The figure spanned by points (a,b,c) = a ∧ b ∧ c. The boundary of the figure = ∧^(k-1) of the metric (a,b,c), equal to ∂(a,b,c) = a ∧ b + b ∧ c + c ∧ a.
I have a very amateur blog that I never publicize about this stuff and I had a long post about this, but I've taken it down for now to rework it, or I'd link it here. Suffice to say there's a lot of connections and I feel like there are even more here that haven't been discovered yet.
The book "Oriented Projective Geometry" by Stolfi has a lot of this, although it doesn't explicitly talk about geometric algebra or the wedge product -- but it uses all the same symbols. I'm on the lookout for a better reference that bridges the gap.
[I have so far not figured out what the exterior derivative means in projective geometry, besides being dual to ∂; I believe that if derivative operators are just dual to basis vectors, then d is literally just dual to ∂. Not sure. I also have no idea what the geometric product means, and tend to be skeptical of it for that meaning.]
Rotations in 3D are a whole different beast...
That really matters for defining smooth paths, quaternions simply have the right topology and rotations don't.
In particular, he’s explaining that quaternions are not vectors, they’re actually oriented planes and showing how their multiplication rules arise in a way that’s not ‘out of thin air’.