Live data from Hacker News

Quaternions

liorsinai.github.io

101–110 of 118 posts

Re: Quaternions

#101
post #76

Earlier quoted context omitted.

GA is much slower in practice and takes more to store. In places speed and cache are important, quaternions are much better. Game engines don't need much if anything from GA (and I've written about using GA decades ago for software, and did it for some time, before realizing that trading that elegance for worse performance was not worth it). Here's [1] one example from the godfather of GA demonstrating how poorly GA…

I have done some experiments with type-directed static optimization of geometric algebra, but I didn’t get far enough to find out if it would scale up to real applications. The idea was to represent in the type system which components are known to be zero, so that (for instance) the GA representation of a vector or a rotation is the same size as it would be as a traditional matrix-based linear algebra. And the type s…

Something like that exists in C++ and Rust:

* https://www.jeremyong.com/klein/ * https://github.com/wrnrlr/g3

Re: Quaternions

#102
post #49

I first encountered quaternions in the concept of abstract algebra. It's interesting to think of it as part of a spectrum starting with reals and continuing to octonions (and beyond). Interestingly with each extension we lose something: Complex numbers (2-dimensional): No more ordering Quaternions (4-dimensional): No more commutative multiplication Octonions (8-dimensional): No more associative multiplication Sedenio…

I don't think it makes sense to say you "lose" something. Yes, the properties of different spaces _are_ different, but these differences are intentional so that they can be used to study something useful. For instance, complex analytic functions have a number of properties that don't hold for real analytic functions, so you actually "gain" something. An example is the residue theorem. One interesting thing about the residue theorem is that you can use it to calculate the integral of a real-valued function that wouldn't be calculable using conventional calculus techniques. So not only do complex functions have a number of interesting properties on their own, they can also be used to expand what's possible in real functions.

Re: Quaternions

#103

In my opinion, Geometric Algebra and bivectors ( https://bivector.net ) in particular is a much better (both practically and pedagogically) approach compared to quaternions and significantly more elegant. It's a real shame that people continue to focus so much on quaternions in this day and age.

GA is much slower in practice and takes more to store. In places speed and cache are important, quaternions are much better. Game engines don't need much if anything from GA (and I've written about using GA decades ago for software, and did it for some time, before realizing that trading that elegance for worse performance was not worth it). Here's [1] one example from the godfather of GA demonstrating how poorly GA…

These don't look like they'd be all that different in perf

https://marctenbosch.com/quaternions/code.htm

Re: Quaternions

#104

In my opinion, Geometric Algebra and bivectors ( https://bivector.net ) in particular is a much better (both practically and pedagogically) approach compared to quaternions and significantly more elegant. It's a real shame that people continue to focus so much on quaternions in this day and age.

GA is much slower in practice and takes more to store. In places speed and cache are important, quaternions are much better. Game engines don't need much if anything from GA (and I've written about using GA decades ago for software, and did it for some time, before realizing that trading that elegance for worse performance was not worth it). Here's [1] one example from the godfather of GA demonstrating how poorly GA…

From the paper:

> The main cause for the lower performance of GA is the Gaigen’s soft typing of the geometric algebra objects at compile-time: all types of objects (scalars, vectors, bivectors, trivectors, rotors and so on) are represented by a single data type in Gaigen. When a product or operation has to be computed, Gaigen first checks the grade usage of the argument(s) and then acts accordingly. This conditional step between function call and actual computation is largely responsible for the drop in performance.

So, I blame the library. Writing out the 3-4 datatypes for 3D GA by hand as real types costs some development effort but should give equivalent performance.

Re: Quaternions

#105

Smallest of small notes: in TeX, "cos" is rendered as a product of 3 italicised variables c, o and s, whereas the escaped literal "\cos" is rendered as the cosine function.

Author here: thanks for the tip. Definitely think this looks better

Great, it certainly does look better :) Note that this also applies to log, exp and other functions. Also, some images seem to be missing in part 2.

Anyway it's a great writeup, even though I know the material it was a good read.

Re: Quaternions

#106

In my opinion, Geometric Algebra and bivectors ( https://bivector.net ) in particular is a much better (both practically and pedagogically) approach compared to quaternions and significantly more elegant. It's a real shame that people continue to focus so much on quaternions in this day and age.

Quanternions' ubiquity is relatively recent. Rotation matrices ruled supreme in games and graphics and it was only after concerted effort to abolish R's were Q's made ubiquitous. Two heartbeats later, we're bearish on Q's.

Rotation matrices are still ubiquitous even in systems which use quaternions: if you want to apply a dense linear transformation to a vector (be it a rotation or otherwise), pretty much nothing will beat (in terms of speed) a matrix-vector multiplication. For instance even if you work out the rotation matrices using quaternions, an engine will end up shipping a rotation matrix to a graphics card to actually transform the bulk of vertices in a scene.

Re: Quaternions

#107
I don't like this proof of the rotation formula. It seems like juggling formulas without providing any motivation as to how we get there. It does a great job of explaining the problems with other notations, but in demonstrating the formula for quaternion rotation we just pull conjugation out of a hat.

First, let's ask what it means to rotate around an axis. If you consider rotation of a vector v in a plane A around the unit normal n, you can decompose v as follows:

v = proj_n(v) + proj_A(v) = vn + vA

Now a 90 degree rotation of v about n is

rot_n(90,v) = vn + n >So if we consider v rotated by an angle S around n, we can infer that vn is preserved and the image rot_n(S,vA) can be projected onto vA and vR according to the usual cosine rule for projection:

rot_n(S, vA) = cos(S)vA + cos(s-90)vR = cos(S)vA + sin(S)vR

Likewise,

rot_n(S, v) = cos(S)v + sin(S)rot_n(90, v) = cos(S)v + sin(S)((v•n)n + v >Okay, now what's wrong with this formula? What if we want to combine rotations? We're stuck, because this "multiplication" isn't associative. So we can turn this into a linear transformation and use the matrix representation, which gives a nine-dimensional algebra, although with symmetry you can make it five-dimensional. (The fifth dimension comes from the requirement that both the determinant and the L2 norm of the matrix coefficients are constant, 1 and 3 respectively.)

But we have perhaps heard about the quaternions, which are associative. And we might have noticed that Im(v*n), where * denotes quaternion multiplication and Im() discards the real part, is equal to v >Im(v*n) = (v*n - (v*n)')/2 = (v*n - n*v)/2

since (v*n)' = n'*v' = (-n)*(-v) = n*v for pure imaginary v,n, where we recall that conjugation distributes over products of quaternions at the cost of reversing the order.

Now what if we try to construct the rotation again:

rot_n(S,v) = cos(S)v + sin(S)(v*n - n*v)/2 = (v*(cos(S)+ sin(S)n) - (-cos(S) + sin(S))*v)/2 = (v*q(n,S) + q(n,S)'*v)/2

Here q(n,S) = cos(S) + sin(S)n is a perfectly reasonable quaternion, and we call it a rotation quaternion. This is now almost associative but not quite. If we combine rotations q and p, we end up with terms like q'*v*p. How annoying. But it feels like we're getting closer, so let's see if we can learn anything else about these "sandwich" products.

Geometrically, if we rotate the vector forwards and backwards, we should get the same vector. But q(n,-S) = q(n,S)', so we must find (we drop the arguments since there is only one q and we are sick of parentheses):

((v*q + q'*v)*q' + q*(v*q + q'*v))/4 = (v*q*q' + q*q'*v + q'*v*q' + q*v*q)/4 = v

Now it's not so hard to verify that q*q' = q'*q = 1, so we can subtract v/2 from both sides and clear the denominator to find the curious-looking lemma:

q*v*q + q'*v*q' = 2v

Now (q'*v*q')' = q*v'*q = -q*v*q, the last equality being established because v is imaginary. Therefore:

q*v*q - (q*v*q)' = 2Im(q*v*q) = 2v

so Im(qvq) = v, for arbitrary rotation vectors q.

Evidently a multiplication by q on the right undoes a multiplication by q on the left, at least when we are talking about imaginary parts, which we were interested in already. So what happens when we take q'*v*q — the missing sandwich in the above equation? This should give us two rotations in the same direction, since switching sides inverts the rotation and conjugation inverts it again to leave us with the same rotation. But what's the use of writing

rot_n(2S, v) = Im(q'*v*q)?

Just try it:

Im(q'*v*q) = (q'*v*q - (q'*v*q)')/2 = (q'*v*q - q'*v'*q)/2 = (q'*v*q + q'*v*q)/2 = q'*v*q!

So we now have a formula where everything is in one product. It turns out that the ugly "sandwiches" (we also call this conjugation, which can be confusing) are useful after all. (Explicitly verifying that q'vq = rot_n(2S, v) is left as an exercise for the reader. See hint [1]. ) Now if we consider a rotation by a second quaternion p, we find:

p'*q'*v*q*p = (q*p)'*v*(q*p)

by inverting the distributive property for conjugation. So we only need to take one product to combine rotations. Finally, an associative structure!

There is only one sticking point left. Evidently q(n,S) corresponds to the transformation rot_n(2S,v). So in order to get rot_n(S, v) we need:

Q(n,S) = q(n,S/2)

But there is one more thing. What happens when S = 360? We all know that a rotation of 360 degrees doesn't change the geometry. So shouldn't we have Q(n,360) = 1? But in fact:

Q(n,360) = q(n,180) = cos(180) + sin(180)n = -1!

Of course (-1)'v(-1) = v.

Evidently Q has a period of 720 degrees under rotations S rather than the usual 360, i.e., Q is a spinor. This is sometimes called a "double cover".

In fact, we could also represent rotations and positions with the Pauli spin matrices and complex 2-vectors respectively, although (as in quantum mechanics) we pick up a meaningless global phase, and translation is weird.

[1]: Consider various ways of writing parentheses on the expression Im(q*q'*v*q*q), and show that q(n,S)*q(n,S) = q(n,2S).

Re: Quaternions

#108
post #49

I first encountered quaternions in the concept of abstract algebra. It's interesting to think of it as part of a spectrum starting with reals and continuing to octonions (and beyond). Interestingly with each extension we lose something: Complex numbers (2-dimensional): No more ordering Quaternions (4-dimensional): No more commutative multiplication Octonions (8-dimensional): No more associative multiplication Sedenio…

Another interesting property from which I learnt about quaternions is that all the proper subgroups of the quaternion group are normal and commutative, but the quaternion group itself is non commutative. [0]

[0] https://www.cs.cas.cz/portal/AlgoMath/AlgebraicStructures/St...

Re: Quaternions

#109
Is there a reason why, for me, this post contains `[math processing error]` numerous times instead of math symbols?

Update: It’s due to incompatibility with the Dark Reader extension, which causes MathJax to find unexpected nulls in `classList`

Re: Quaternions

#110

Earlier quoted context omitted.

No, i, j, and k are not the same thing. They are the three distinct square roots of -1. You thus wind up with a space with one real axis and three orthogonal imaginary axes. Why should -1 have three distinct imaginary roots? Well, why should it have one? Essentially, we just made up i, and we found out that the complex numbers had some really useful algebraic properties. The same is true of the quaternions. But why n…

And like that I’ve given up hope of ever having a good understanding of any mathematical field.

Try this version, which is expanded somewhat. I found it clearer:

https://news.ycombinator.com/item?id=29516191

Post reply on HN