[HN Gopher] Let's remove Quaternions from every 3D Engine (2018)
___________________________________________________________________
Let's remove Quaternions from every 3D Engine (2018)
Author : kilovoltaire
Score : 125 points
Date : 2021-12-10 17:06 UTC (5 hours ago)
(HTM) web link (marctenbosch.com)
(TXT) w3m dump (marctenbosch.com)
| klodolph wrote:
| I think there's a lot of fuss here to come up with something
| which has the same structure (isomorphic) and same representation
| / encoding as quaternions, while trying to avoid calling them
| quaternions. Part of math pedagogy is getting comfortable with
| terminology and when to say that two things are "the same thing".
| You understand a structures (like quaternions, like rotors) by
| using both axiomatic approaches (what are the properties of these
| things?) and from constructive approaches (how do we build these
| things?)
|
| Take the real numbers, for example. They are intuitively simple,
| but if you take an analysis class, you'll be asked to rigorously
| prove that your different approaches to understanding real
| numbers are equal to each other, and therefore interchangeable.
| You can take your axiomatic approach (real numbers are an ordered
| field, where each nonempty set bounded above has a least upper
| bound). You can construct real numbers as decimal numbers with an
| infinite number of digits past the decimal point. You can
| construct real numbers as limits of series of fractions. All of
| these approaches "are" the real numbers. No one version is
| privileged over the others. By understanding these different
| approaches, you get a better understanding of the real numbers.
|
| Same is true of quaternions, but here, it seems that we're being
| sold an idea that one version is superior and the other versions
| are inferior. This is, I believe, a bad pedagogical approach.
| There are certain advantages to thinking of quaternions in terms
| of a scalar component and 3D imaginary component. For one thing,
| the imaginary component points in the direction of the axis of
| rotation! That's pretty handy, for visualizing quaternions as
| rotations. This article takes the viewpoint that there is no
| reason to think of quaternions as anything other than rotors and
| plane reflections--again, this is bad pedagogy, because people
| should be encouraged to think of mathematical objects in
| different ways, and use whichever way that they find convenient
| for the problem, or convenient for their own mental model. No one
| approach is privileged. As a mathematician, reading this article,
| all I see at the end is "Oh, you want to use quaternions, but you
| don't want to _call_ them quaternions. "
|
| Perhaps we need a more in-depth article on the notion of
| rotations explained for non-mathematicians, something that, at
| the very least, incorporates the relationship between axis-angle
| representations and quaternions/rotors, because these two
| different representations are _not_ isomorphic, and they are
| related to each other through calculus, the exponential map, and
| Lie algebra. It 's also worthwhile to think what the tangent
| space is for unit quaternions. If you incorporate the different
| approaches to representing rotations, and don't try to sell one
| as being "the best" representation, I'd love to read _that_
| article.
| threatofrain wrote:
| I'm not sure about this pedagogical argument, since among
| various pedagogical pathways for any particular math subject,
| students are generally only aware of the path they took. I
| think it is a pedagogically motivated student who does even the
| mildest of surveys for something they _already_ understand.
| lacker wrote:
| To me a 3d rotation is a linear transformation from a 3d vector
| space to itself, so the natural way to represent it is as a 3x3
| matrix.
|
| Mathematically, this isn't an unusual way to look at it; you can
| read the Wikipedia page on this way of representing rotations.
| The nice thing is that it works basically the same as a 2d
| rotation, you just have one more row and column in your matrix.
|
| https://en.wikipedia.org/wiki/Rotation_matrix
|
| I think this is simpler than any of quaternions, rotors,
| bivectors, or exponential maps.
| edflsafoiewq wrote:
| What representation you want depends on what you want to do. A
| matrix is good for applying to vectors, but bad for
| interpolation and inefficient for storage.
| Grustaf wrote:
| Here comes the Geometric Algebra evangelists again.
| ldd wrote:
| The first sentence in the first slice opens as follows: "I have
| always found it important to actually understand the things I am
| using."
|
| I think there is a certain 'magic' in not understanding certain
| concepts fully. It's probably why I like maths and heavily
| dislike physics and chemistry. I do not want to make sense of
| this world. I want to see "the volume of a sphere is 4/3 _PI_
| r^3" and in some sense see it as an incantation that one would
| make when casting magic in an RPG. Once you take some calculus,
| it is a pretty easy formula to derive (integrate?), but there is
| an allure, an invitation to do some really interesting math just
| for itself. It fires up our inner curiosity, if you want.
|
| So anyways, I am neither addressing the title's question nor
| would I really mind if quaternions were replaced in game engines,
| but I thought it was important to voice the opinion that
| sometimes it's ok to not understand something.
| [deleted]
| jazzyjackson wrote:
| I found mathematics much more approachable after being
| convinced it was not important to understand "why" - that I
| would spend all my time trying to understand that which is not
| necessarily understandable.
|
| its like wondering how a hammer works instead of just using the
| hammer
| Jensson wrote:
| > I think there is a certain 'magic' in not understanding
| certain concepts fully. It's probably why I like maths and
| heavily dislike physics and chemistry.
|
| This doesn't make sense to me. Math are things that humans can
| understand fully, physics and chemistry are not, at least not
| yet. Things like "the volume of a sphere is 4/3PIr^3" can be
| fully understood, there are many ways to derive that formula.
| Of course you can apply it without understanding it, but the
| same goes for newtons equations or any of the many other
| formulas you have in physics and chemistry.
| undershirt wrote:
| > I have always found it important to actually understand the
| things I am using.
|
| > I think there is a certain 'magic' in not understanding
| certain concepts fully.
|
| With magic everywhere I wonder how many lifetimes it would take
| to understand the things we use. And I wonder how much of our
| knowledge is, should, or must remain tacit[1].
|
| And sometimes "surface explanations" kick off deep
| understandings that you can't surface at once, or ever. Jordan
| Peterson tried rationalizing faith in this way, and it was
| quite a show[2].
|
| [1] https://en.wikipedia.org/wiki/Tacit_knowledge
|
| [2]
| https://youtube.com/playlist?list=PL22J3VaeABQD_IZs7y60I3lUr...
| Izkata wrote:
| Funny you should choose that particular example, that's the one
| formula I could never remember in gradeschool until on a whim
| while bored at my part-time job I used what I'd just learned in
| calculus to derive it (yep, with integration). Once I
| understood where each part of the formula came from, I never
| forgot it again.
| kingcharles wrote:
| I agree. You can't know everything. When the 3D world moved to
| Quaternions I just plugged in the functions and accepted the
| fact that my maths wasn't good enough to really understand what
| was going on under the hood and I concentrated my abilities on
| building the rest of the engine, which was something I did
| understand.
|
| Most people who drive cars have no idea how a combustion engine
| works, but the world doesn't completely descend into anarchy
| because of this.
| kilovoltaire wrote:
| Since there's currently an article about quaternions on the front
| page, it felt like a good time to bring up bivectors, which in my
| opinion are a much more elegant way to do rotations.
|
| Particularly, I think this part is insightful:
|
| > In 3D, a bivector has three coordinates, one per plane: (xy,
| xz, and yz). Vectors also have three coordinates, one per axis
| (x, y and z). Each plane is perpendicular to one axis. This is a
| coincidence that only happens in three dimensions and it is why
| historically we have been confusing bivectors with vectors.
| idealmedtech wrote:
| > Each plane is perpendicular to one axis. This is a
| coincidence that only happens in three dimensions
|
| This part is confusing to me; in any number of dimensions, your
| orthonormal basis vectors (coordinate vectors) will by
| definition have tangent vector spaces (planes). There's nothing
| special about 3 in this regard, unless I'm misunderstanding
| something.
| Sukera wrote:
| I think they're saying the planes in particular are the
| tangent vector space in 3 dimensions. They're no longer the
| tangent vector space in 2,4,5.. dimensions, but they're still
| a thing there as well.
| krastanov wrote:
| In N dimensions you do indeed have N hyperplanes of dimension
| N-1. But you have N*(N-1)/2 planes of dimension 2. Then one
| needs to explain why is rotation in general related to a 2D
| plane, not to an axis. Tautologically, it is so because
| rotation is when you oscillate between two directions (the
| two vectors of the 2D plane). It is not "rotating around an
| axis", because there is no consistent way to give one single
| angle of rotation around an axis if you are in 4+ dimensions.
| zardo wrote:
| It's also nice that doing 2D physics, you can represent torque
| without invoking an extra orthogonal spatial dimension.
| dr_orpheus wrote:
| Previous discussion on this article:
| https://news.ycombinator.com/item?id=18365433
| dang wrote:
| Thanks! Macroexpanded:
|
| _Let 's remove quaternions from every 3D engine (2018)_ -
| https://news.ycombinator.com/item?id=22200260 - Jan 2020 (326
| comments)
|
| _Let 's remove Quaternions from every 3D Engine_ -
| https://news.ycombinator.com/item?id=18365433 - Nov 2018 (175
| comments)
| vazgriz wrote:
| > their API is the same
|
| > in fact, they are isomorphic
|
| > The change is simple and the code remains almost the same, but
| the understanding grows a lot.
|
| Does that mean you could rename 'class Quaternion' to 'class
| Rotor' and be done? I watched the video on rotors and some other
| videos on quaternions and I found them exactly as unintuitive as
| each other. I don't really see any advantage to using rotors and
| I'm quite happy to continue treating quaternions as black boxes.
|
| The article says that rotors are better since they can be
| generalized to any number of dimensions, unlike quaternions which
| only work in 3D. But that only seems useful to one person: Marc
| ten Bosch, the guy who writes games in 4D.
| [deleted]
| dang wrote:
| Ongoing related thread:
|
| _Quaternions_ - https://news.ycombinator.com/item?id=29510237
| ogogmad wrote:
| Off topic: Are the "dual-complex numbers"* used in 2D game
| engines? They're certainly a part of GA.
|
| The term _dual-complex numbers_ is an unfortunate name for what I
| 'm referring to, which is a 4D number system for representing
| rigid body motions of 2D space. There is an analogue of SLERP for
| them for interpolating between rigid body motions. So you would
| expect the answer to be yes.
|
| Maybe this isn't the right forum for this question.
|
| * - https://en.wikipedia.org/wiki/Dual-
| complex_number#:~:text=Th....
| ChrisLomont wrote:
| Having written professionally about quaternions and GA, and
| having implemented them multiple times in professional engines,
| GA is simply slower and worse to use (until you replace them in
| the special case and put back quaternions).
|
| I recommend every 3D engine keep quaternions - they work well for
| their task.
|
| Here's [1] one example from the godfather of GA demonstrating how
| poorly GA performs
|
| [1]
| https://webspace.science.uu.nl/~kreve101/asci/GAraytracer.pd...
| ncmncm wrote:
| It seems like leaning into support from the type system of
| modern, static-typed languages like C++ could get us the
| conceptual advantage of GA with the performance of ordinary 3D
| linear algrebra, by representing knowledge of zero elements in
| such a way that operations with them shake out.
|
| It is another trick to map this to SIMD operations with vector
| units or GPUs in modern CPUs, but that should be no harder than
| doing the same thing with quaternions.
| ChrisLomont wrote:
| >could get us the conceptual advantage of GA with the
| performance of ordinary 3D linear algrebra
|
| People have tried this for well over 20 years, and it has
| never once panned out. It's simply not possible, since the
| representation required for Clifford Algebras is simply
| larger than for a quat. C++ static typed engines with all the
| template magic, or even super optimized hand rolled GA
| engines, are simply not performant compared to the same
| effort on a traditional linear algebra one.
|
| Look over the writings of the authors in the paper I linked -
| they're gods in the GA field, and they've tried for decades
| to get it to work, as have many others (I worked on it 20ish
| years ago too..).
|
| Go ahead and reinvent it all. I suspect you'll eventually
| reach the same conclusion many have before.
| armchairhacker wrote:
| I like the author's general idea that there should be a separate,
| mostly-opaque type for 2D and 3D angles.
|
| 2D angles are represented by floats, and 3D angles are
| represented by Quaternions. Which is fine internally, but a smart
| language should provide an inline wrapper type.
|
| Typing 2D angles as floats presents issues when wrapping: x and
| 2pi * x will look and mostly function the same, but can lead to
| edge cases e.g. comparisons and loss of precision.
|
| Typing 3D angles makes them easier to understand, since you won't
| be doing high-level mathematical operations, you'll just be
| rotating to face x or rotating by y degrees perpendicular to
| vector z.
| ajkjk wrote:
| 100% agree that bivectors are an easier to way to think about
| quaternions with less magical hand-waving. However, I have an
| opinion that feels important which I like to post whenever
| geometric algebra comes up:
|
| Just because multivectors are intuitively superior doesn't mean
| GA is a solved pedagogical solution to rotations. It is itself
| very strange and unintuitive. In particular there is no
| satisfying explanation for what the geometric product means that
| I'm aware of (and I have read more-or-less everything there is on
| the subject). Certain restrictions of the product have a
| geometric interpretation but the overall operation doesn't. The
| product tends to be introduced in a just-so way: look, an
| operation! How neat! But if you're a student who's already
| wondering "wtf is a quaternion and why does this work" you're not
| going to be much better off wondering "wtf is a geometric product
| and why does it work".
|
| I happen to think that the superior pedagogical solution is to do
| away with the geometric product as well and just focus on
| rotations as an application of the exponential map
| [https://en.wikipedia.org/wiki/Exponential_map_(Lie_theory)].
| That is, quaternions emerge like this:
|
| 1. apply rotations via the exponential map acting on rotation
| operators: e^(iB) = 1 + (iB) + (iB)^2/2! + ...
|
| 2. in a flash of insight, realize that rotating vectors with two
| half-rotations is more stable than one full rotation: e^(iB) v =>
| e^(iB/2) v e^(-iB/2)
|
| I don't really understand the point of (2). I remember hearing
| that it works better in higher dimensions but couldn't tell you
| why.
|
| But the point is, the useful properties -- like avoiding gimbal
| lock -- follow from just oriented planes and the exponential map.
| Gimbal lock is avoided by expressing rotations as a single
| rotation around an arbitrary axis, instead of, say composing
| Euler angles around fixed axes. But you don't need to mention the
| geometric product anywhere for this.
|
| Anyway I think that this is a relatively 'unsolved' space,
| pedagogically. There is probably a really good explanation of why
| this all works that feels like it is still missing and doesn't
| involve any magic handwaving steps at all.
| Micoloth wrote:
| I see what you are saying.. As a counterpoint, to me, an
| oriented plane in 3d very much remembers a rotation though! The
| graphical convention of a plane with a circle arrow is great
| because it makes it very clear.
|
| To see what a plane does to a vector, you take the product: of
| course you start with basis vectors and then later show that
| everything composes linearly.
|
| The very important thing here is that the geometric product
| should Not be taught as the sum of scalar and cross product.
| Geometric product is defined by rules on the basis vectors and
| by linearity!
|
| Now, I admit that when you see that making actual rotations is
| not as straighforward as one would expect, it's confusing, and
| a bit disappointing. But, I think one can believe that
| bivectors are about rotation somehow, and then go further to
| the more complex exponential thing.
|
| Idk maybe it's just personal preferences, i studied quite a bit
| of math at college, but i never studied quaternions, and now
| I'm just very glad I didn't, since this is much better to me!
| ajkjk wrote:
| To be clear, my preferred solution still includes the idea of
| an oriented plane. It just dispenses with the 'geometric
| product'.
| whycombinater wrote:
| Regarding the "pedagogy", my favorite method of learning is
| straightforward problem solving:
| http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...
|
| If you wanted to have state with pure functions, you would,
| according to DRY, be compelled to write the bind operator. You
| wouldn't have known to call it a monad or why some basement
| theoretician likens it to a burrtiofunctor, but you
| nevertheless would have made the obvious coding solution.
|
| Is this possible for rotation without a PhD in geometry or
| algebra?
| ajkjk wrote:
| Well! I don't have a PhD at all, but I think the exponential
| map is a surprisingly intuitive operation once you get used
| to it. It works on all kinds of operators. I'd argue for
| teaching it much earlier, in intro calculus, to introduce the
| idea that e^(a d_x) f(x) = f(x + a). But it still feels like
| there is some magic in the fact that works that I don't have
| a really satisfying explanation for (although it is easy to
| see by expanding the Taylor series).
| SNosTrAnDbLe wrote:
| This is what was taught to me when I was in grad school. "The
| best way to represent rotation was the exponential of a
| matrix".
|
| I did not really grasp what it meant but I did find the idea
| itself fascinating.
___________________________________________________________________
(page generated 2021-12-10 23:02 UTC)