Let's remove Quaternions from every 3D Engine: Intro to Rotors from Geometric Algebra

preview_player
Показать описание


To represent 3D rotations graphics programmers use Quaternions. However, Quaternions are taught at face value. We just accept their odd multiplication tables and other arcane definitions and use them as black boxes that rotate vectors in the ways we want. Why does i^2=j^2=k^2=−1 and ij=k? Why do we take a vector and upgrade it to an "imaginary" vector in order to transform it, like q(xi+yj+zk)q∗? Who cares as long as it rotates vectors the right way, right?

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.

In Geometric Algebra there is a way to represent rotations called a Rotor that generalizes Quaternions (in 3D) and Complex Numbers (in 2D) and even works in any number of dimensions.

3D Rotors are in a sense the true form of quaternions, or in other words Quaternions are an obfuscated version of Rotors. They are equivalent in that they have the same number of components, their API is the same, they are as efficient, they are good for interpolation and avoiding gimbal lock, etc... in fact, they are isomorphic, so it is possible to do some math to turn a rotor into a quaternion, but doing so makes them less general and less intuitive (and loses extra capabilites).

But instead of defining Quaternions out of nowhere and trying to explain how they work retroactively, it is possible to explain Rotors almost entirely from scratch. This obviously takes more time, but I find it is very much worth it because it makes them much easier to understand!

For example, Quaternions are introduced as this mysterious four-dimensional object, but why introduce a fourth dimension of space to visualize a 3D concept? By contrast 3D Rotors do not require the use of a fourth dimension of space in order to be visualized.

Trying to visualize quaternions as operating in 4D just to explain 3D rotations is a bit like trying to understand planetary motion from an earth-centric perspective i.e. overly complex because you are looking at it from the wrong viewpoint.

It would be great if we could start phasing out the use and teaching of Quaternions and replace them with Rotors. The change is simple and the code remains almost the same, but the understanding grows a lot.

As a side note, Geometric Algebra contains more than just Rotors, and is a very useful tool to have in one's toolbox. This article also serves as an introduction to it.

0:00 Introduction
2:30 1.1 - Rotations happen in 2D planes
3:09 1.2 - Explicit Sense of Rotation
3:36 2.1 - The Outer Product
4:26 2.2 - Basis for Bivectors
4:41 2.3 - 2D Bivectors
6:17 2.4 - 2D Bivectors from non-unit vectors
6:54 2.5 - 3D Bivectors
8:15 2.6 - Semantics of Vectors and Bivectors
9:01 2.7 - Trivectors
9:42 3.1 - Multiplying Vectors together
11:48 3.2 - Multiplication Table
12:15 3.3 - The Reflection Formula (Traditional Version)
12:55 3.4 - The Reflection Formula (Geometric Product Version)
13:32 3.5 - Two Reflections is a Rotation: 2D case
14:26 3.6 - Two Reflections is a Rotation: 3D case
15:03 3.7 - Rotors
15:35 3.8 - 3D Rotors vs Quaternions
Рекомендации по теме
Комментарии
Автор

If you really want to make an argument for replacing quaternions, I think you should establish that the new way is computationally equally or less expensive than quaternions. Using black boxes are a non-issue in software engineering, provided they do what you intended every time and aren't inefficient. Anyway, your video is really well made and I am grateful you made it!

Toxo
Автор

Looks like the rotor isn't just a more generalized form that captures the quaternion, it captures the spinor as well. It might be worth pointing that out since spinors have been popping up in the public discussion within the last year or so.

sirnukesalot
Автор

I feel like there is an untold story of how you tried to code rotations in 4d for miagakure and discovered 4d rotors rather than a 5d solution. Then were like "well jeez if we dont need a 5th dimension for 4d rotations then why would we need a 4th dimension for 3d rotations?"

lukostello
Автор

It took a bit to digest, but after reviewing the article a few times I felt a sense of enlightenment. The stuff that seemed so out of the blue before (like the cross product) now fall into place so naturally. Thank you very much for this intro to geometric algebra.

DarkCloud
Автор

Thanks for a great explanation. I have a constructive criticism... I find it jarring when one equation cross-fades into an equivalent equation. I would prefer to have a new equation fade in below, so I can verify equivalence myself. This would make it easy to pause the video to compare the two equations. Instead, I have to rewind the video to see the previous equation. Going back and forth between the two equations is tedious. Thanks again!

schwajj
Автор

I have known geometric algebra was supposed to be more intuitive for a while. Recently I've used quaternions for the first time and I was really enthusiastic about how numerically efficient and stable they were, but I don't fully understand them. I think the next time I do a project involving 3d rotations, I will use the geometric algebra formalism. Thanks!

mudkip_btw
Автор

For me the similarities between hypercomplex basis and a bivector basis were always obvious because I always thought of ijk basis as a bivector basis to start with. But I never realised that reflection about a and then reflection about b is the same is rotating by twice the angle between a and b. This actually was very insightful.

Alexander_Sannikov
Автор

Best introduction to geometric algebra that I've ever seen. I've used quaternions for graphics and always thought geometric algebra was too complicated because of the different products and mixed type sums etc. but when it's clearly explained, it makes sense and seems simpler to work with because you can use geometric intuition to break up calculations instead of having to do a lot of algebra and hope you got it right.

AThagoras
Автор

Brilliant! I have wondered about cross products for decades, and even after working through the derivations algebraically they never really clicked. This video was a jolt of enlightenment. Thank you.

Pherecydes
Автор

Why do I feel like I’m being sold on some kind of mathematical cult?

ryanrising
Автор

1:43 if you think about matricies, and vectors. If you want 3D transformation (nost just rotation but translation and scaling) with them, you need one extra dimension, hence a 4x4 matricies and x, y, z, w homogenous vectors are needed in to order express such.

EMBD
Автор

Fantastic read/video! One thing that bugs me though if the fact that you're explaining everything in terms of XY, YZ and XZ planes, but things would get more consistent if you used YZ, ZX and XY planes instead. There are a couple of things that this fixes, let me explain.

Firstly, if you take the cross product of the basis vectors of the XY plane, you'll get Z=1. For YZ plane, you'll get X=1. But with XZ, you'll get Y=-1. Seems very wrong right? Using ZX not only fixes this, but also it's quite logical that Y comes after X, Z comes after Y and, after wrapping around, X comes after Z.

At 7:43, you explain how the outer product is almost like the cross product, but the value for Y is negative. But by using ZX, this also gets fixed and the values are identical! Also, if you fix the order so that it's [YZ, ZX, XY] and not [XY, YZ, XZ], it'd match up with the rows of the matrix you'd get from a cross product.

eeromutka
Автор

I feel you start this out with a non-argument: "I wasn't taught why quaternions work, so here's an alternative..."

NikolajKuntner
Автор

8:17 Just to clarify, the vector given by cross product is not a "confusion". It is a result of Hodge duality in the exterior algebra. Aka the hodge dual of x is exactly y^z and so on.

JohnTan
Автор

Cant wait for Randy to find this and then watch him go and refactor most of his code to get rid of the Quaternions he just learned about and implemented into his game

PSPCDJ
Автор

I feel like the name is slightly clickbait. What it seems like you're actually arguing here is a different way to teach quaternions. I don't think using this approach would actually change anything about how a 3D engine is implemented under the hood.

At best it would be some different identifiers and documentation, but once you compile and optimize everything you're left with the same end product.

r.pizzamonkey
Автор

I think the greatest confusion in understanding quaternions comes from the fact that in 3d the dimentionality of an axis of rotation is the same as dimentionality of the space itself. This is not the case for any(?) other dimensionality. Because of this, we think of rotation axes as if they were part of the same space when they are really not, which's particularly obvious in non-orthogonal bases.

Alexander_Sannikov
Автор

Quarter ions are nicely wrapped Rodriguez rotations. The only point I see in favor of quaternions is that it is possible to multiply them with a ‘C-O’ quaternion to mathematically align an observation quaternion to a body quaternion for real time applications like on seagoing vessels

arnoldn
Автор

Sorry for only watching it now, but incredible stuff, I feel dumb for just accepting quaternions in all my code as it is, till now. They would have made the like of high school me, trying to learn graphics programming so much easier, thanks a lot.

I had taken multiple courses in Maths, wasted several hours working on geometric algebra but never did I think of using it. So thanks a lot. 😊

I will try and port as much of my code to rotors as possible, and only leave a quaternion api as a secondary solution. :)

SteinCodes
Автор

Some rather interesting comments ! I'm not even going to pretend that I'm qualified to add anything useful here but, I will say that I'm grateful for those who took the time & effort to understand this stuff. & especially for those who actually came up with it in the 1st place, as well as anyone who attempts to teach it.

realcygnus