News for hackers. Stuff that matters.
Re:Let's remove Quaternions from every 3D Engine by corysama on Friday November 02, 2018 @08:21PM (#18367839)
Tangential: Back in 2000 there was some debate about dropping quaternions in favor of a set of equivalent operations on plain matrices. https://www.gamedev.net/articles/programming/math-and-physic... The debate petered out when the proponents finished optimizing their implementation and found they had produced exactly the same code as the existing quaternion implementations. The only difference was the approach used to derive it.
Re:Let's remove Quaternions from every 3D Engine by lmitchell on Friday November 02, 2018 @11:46PM (#18368571)
Thank you for posting this, I found it both very enlightening and a pretty fun internet-drama read :D

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.

Re:Let's remove Quaternions from every 3D Engine by Certhas on Saturday November 03, 2018 @06:11AM (#18369482)
Matrices are linear transformations. Take a bunch of vectors, map them to another bunch of vectors. It's all inherently geometric.

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.

[1] https://en.wikipedia.org/wiki/Composition_algebra

Re:Let's remove Quaternions from every 3D Engine by wnkrshm on Saturday November 03, 2018 @07:29AM (#18369716)
There is an N-dimensional generalisation for complex numbers, quaternions and hypercomplex numbers called Clifford algebra. I'm not an expert in that field (coming from physics and optics) but apparently it's not by chance that quaternions are connected with the rotation group SO(3) and complex numbers with SO(2). You can generalize to SO(n) with Clifford algebra.
Re:Let's remove Quaternions from every 3D Engine by profquail on Saturday November 03, 2018 @02:29PM (#18371708)
There was an excellent article posted to HN a few years back about Clifford algebra you (and GP) might find interesting:

https://slehar.wordpress.com/2014/03/18/clifford-algebra-a-v...

Re:Let's remove Quaternions from every 3D Engine by Certhas on Saturday November 03, 2018 @08:30AM (#18369882)
This is closely related to the exterior algebra, which is where bivectors live. But I don't know much about Clifford algebras either. I didn't know that they are more directly connected to Quaternions. Thanks!
Re:Let's remove Quaternions from every 3D Engine by cygx on Saturday November 03, 2018 @08:37AM (#18369907)
The 'geometric product' mentioned in the article is just Clifford's product. The 'geometric algebra' is the same thing as the Clifford algebra induced by the scalar product.
Re:Let's remove Quaternions from every 3D Engine by Certhas on Sunday November 04, 2018 @04:49AM (#18375087)
Ah got it. Thanks. Feels like I should have known that.
Re:Let's remove Quaternions from every 3D Engine by marctenbosch on Saturday November 03, 2018 @02:17AM (#18368993)
I think matrices are easier for people to visualize because they can think about them as a vector frame and coordinate transformations.

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.

Re:Let's remove Quaternions from every 3D Engine by jacobolus on Saturday November 03, 2018 @05:38AM (#18369403)
To be honest the hardest part is not understanding single rotations, but understanding how rotations compose.

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.

Re:Let's remove Quaternions from every 3D Engine by z3t4 on Saturday November 03, 2018 @06:03AM (#18369468)
In high level programming, the code is for humans, the optimized compiler output is for the computer.
Re:Let's remove Quaternions from every 3D Engine by gruez on Saturday November 03, 2018 @10:24AM (#18370270)
you're greatly overestimating how much the compiler can optimize code.
Re:Let's remove Quaternions from every 3D Engine by z3t4 on Saturday November 03, 2018 @05:06PM (#18372488)
You need to be a pretty good assembler programmer in order to beat the optimizer already. Maybe in the future, with the help of "AI" the computer can do what we want, instead of what we tell it.
Re:Let's remove Quaternions from every 3D Engine by JochemK on Saturday November 03, 2018 @05:29PM (#18372577)
If you call .sort() which implements bogo-sort, any programmar will be able to write a better sorting algorithm in assembly. I doubt any "AI" will be able to restructure your high-level bogo-sort into an efficient algorithm.
Re:Let's remove Quaternions from every 3D Engine by Const-me on Saturday November 03, 2018 @05:48PM (#18372666)
I'm not especially good assembly programmer but I beat the optimizer every day, in some cases by an order of magnitude. Even best compilers suck at automatic vectorization.
Re:Let's remove Quaternions from every 3D Engine by MaxBarraclough on Saturday November 03, 2018 @11:37AM (#18370688)
But the article is about 3D graphics programming, which is often performance-sensitive.