• by dhosek on 12/10/2021, 5:43:21 PM

    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

    Sedenions (16-dimensional): We lose the alternative property, i.e., with octonions its still true that x(xy) = (xx)y but with sedenions it is not.

    We can continue this process indefinitely, although I know nothing of the characteristics of trigintaduonions or what comes later. I suspect that it might be the loss of the flexible identity next, a(ba) = (ab)a but I don't know for sure.

  • by trylfthsk on 12/10/2021, 4:44:10 PM

    W.R Hamilton's discovery of the Quaternions is semi-famous itself, with the story being that after the critical flash of insight he carved the equation describing quaternion multiplication into a bridge in Ireland with a penknife.

    A interesting read is this letter [0] written the following day, where he explains his ideas in his own words. It's a great (and accessible!) look into his thought process.

    [0] https://www.maths.tcd.ie/pub/HistMath/People/Hamilton/QLette...

  • by Const-me on 12/10/2021, 7:52:09 PM

    One interesting thing about quaternions that’s almost never mentioned anywhere on the internets, there’re two conventions for them.

    The convention in that article is known as “Hamilton's quaternions”. There’s another incompatible one usually called “JPL quaternions”, for some American Jet Propulsion Laboratory.

    Authors of 99% articles about the quaternions, and software libraries implementing quaternions, are assuming exactly one of these conventions, and almost never mention which one that is.

    More info there: https://fzheng.me/2017/11/12/quaternion_conventions_en/

  • by newpavlov on 12/10/2021, 4:46:21 PM

    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.

  • by steve_adams_86 on 12/10/2021, 4:17:38 PM

    I remember the first time I encountered quaternions, and it was in a similar context. I was using PiQT 3d to move models in a simulation.

    At first it really bothered me that quaternions were a black box to me, yet so easy to use in so many contexts. What kind of magic was happening? I had to know.

    My math is terrible. I spent actual days revisiting YouTube videos explaining quaternions but my limited brain cells were failing to properly grasp it. I had to know though, I’d go crazy writing so much code that depends on something I couldn’t understand.

    It took a long time. This would have been very helpful. Quaternions are very cool, and well worth reading about if you do anything in the digital 3d world.

    I think I can still hear my brain sizzling as I tried to absorb this stuff.

  • by Jun8 on 12/10/2021, 3:24:49 PM

    3B1B is also informative, especially in explaining why C was not extended using triplets but 4-tuples were needed: https://youtu.be/d4EgbgTm0Bg.

    Here’s a Math SE answer on why: https://math.stackexchange.com/questions/1784166/why-are-the..., here’s a more ELI5 discussion: https://www.reddit.com/r/math/comments/9urjyx/why_there_is_n.... I especially like this very intuitive comment in that thread : https://www.reddit.com/r/math/comments/9urjyx/comment/e96j4l...

    Left as an exercise to reader: prove that no such n-tuples exist for n>4.

  • by ivanstojic on 12/10/2021, 3:33:21 PM

    Interesting thing to remember: quaternions are a special application of rotors, a concept which may be easier to understand as a base:

    https://marctenbosch.com/quaternions/

  • by an1sotropy on 12/10/2021, 3:49:30 PM

    David Eberly has written a huge amount of great and free intro mathematical papers. The "Mathematics/Algebra" section of [1] has a few things on quaternions, including a nice self-contained linear algebra-based derivation of why it makes sense to represent a rotation with four numbers, which ends up being a sneaky introduction to quaternions [2]

    [1] https://www.geometrictools.com/Documentation/Documentation.h...

    [2] https://www.geometrictools.com/Documentation/LinearAlgebraic...

  • by pixelpoet on 12/10/2021, 3:38:39 PM

    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.

  • by jodrellblank on 12/10/2021, 3:40:00 PM

    > although a lecturer once eluded to them during a class in my masters

    Would be more amusing if "they eluded a lecturer" or "a lecturer once elided them".

    ("alluded to them").

  • by adamnemecek on 12/10/2021, 5:43:34 PM

    You should check out the bivector community dedicated to geometric algebra https://bivector.net/.

    Check out a demo https://observablehq.com/@enkimute/animated-orbits

    Join the discord https://discord.gg/vGY6pPk.

    Enki (the guy behind bivector) also gave a talk on GA at SIGGRAPH 2019 https://www.youtube.com/watch?v=tX4H_ctggYo

  • by dr_orpheus on 12/10/2021, 6:50:52 PM

    > I did not encounter quaternions in all my years of engineering, although a lecturer once alluded to them during a class in my masters.

    I know that I am not coming in with same perspective as a lot of the other software engineers/graphics developers, but I started learning about quaternions freshman year of college. For aerospace engineering quaternions are used almost exclusively for spacecraft attitude determination and control. For a very dynamic system they are very useful.

    There are some limitations that I have seen, and I have seen Rodrigues parameters (or modified Rodrigues parameters) used instead which are mentioned near the end of the article.

  • by akeck on 12/10/2021, 3:19:16 PM

    I've been teaching myself geometric algebra which is apparently isomorphic to quaternion algebra. Some people prefer GA for 3D modeling work.

  • by Chabsff on 12/10/2021, 3:23:21 PM

    I've been out of the games sphere for a long time, but is slerp() really the default idiomatic interpolation approach in modern games nowadays?

    There are a vanishingly small number of scenarios where lerp() + normalize() doesn't work perfectly well enough and it is drastically faster and SIMD-friendly. That used to be the case at least.

  • by analog31 on 12/10/2021, 4:29:32 PM

    Ask HN: Do quaternions have any interesting properties, akin to those of complex numbers, when calculus is applied? The only application I've ever seen is for doing rotations in computer graphics.

  • by smcameron on 12/10/2021, 4:39:22 PM

    This page is a little more information dense, but it's what I learned quaternions from (after bashing my head against it for a couple of weeks) and it's good as a refresher because it is so dense.

    http://www.tutis.ca/Rotate/7quaternions.htm

    One thing I didn't see in the OP's linked article is how to transform a quaternion into a different coordinate system defined by another quaternion. For example, suppose you have a spaceship in a game at an arbitrary orientation defined by Q1 which is a rotation away from a conventional "unrotated" orientation, and you want to input say 5 degrees of yaw to the right. Well, you just construct a quaternion Q2 that is 5 degrees yaw to the right from this conventional unrotated orientation, and you can use quaternion conjugation to transform Q2 into the orientation of Q1 where it can then be applied to the spaceship's orientation. OP's link mentioned quaternion conjugation, but didn't really mention what it was good for. It is described in section IV of the 7quaternions link.

  • by gibsonf1 on 12/10/2021, 10:29:42 PM

    The absolute best instruction on quaternions I've seen is the 3Blue1Brown series on your tube and their incredible live quaternion viewer: https://www.youtube.com/watch?v=zjMuIxRvygQ&t=24s

    I was able to learn enough from this to then use quaternion matrix transformations extensively in my startup to incredible effect.

  • by h2odragon on 12/10/2021, 3:04:53 PM

    Very nice thats a reference to keep and come back to thanks.

  • by po1nt on 12/10/2021, 11:11:54 PM

    I've seen dozen of tutorials trying to explain quaternions in multiple analogies and methods. But finally after this tutorial I can finally conclude that I'm dumb.

  • by 2143 on 12/10/2021, 6:59:35 PM

    I remember "quarternions" from my math-heavy computer graphics class.

    Today, I have zero recollection of what they were or why it was in my graphics class. Heck I barely remember anything from that class today, which is ironical considering it was a required class for me to graduate that semester.

    I wish my job had atleast a little more to do withwhat I learnt in college.

    (I'm a web developer, and I'd like to get closer to the machine.)

  • by btilly on 12/10/2021, 7:30:55 PM

    Quaternion trivia.

    There was at one point a debate in physics about whether it was better to use quaternions or linear algebra for physics. With i, j, and k being the unit vectors, and the real numbers representing time. In the end, of course, linear algebra won. But we still use i, j, and k as the unit vectors. And in electrical engineering where i wound up hijacked for current, they use j as the square root of -1.

  • by matsemann on 12/10/2021, 6:06:08 PM

    About rotation and interpolation, I once had a bug in animated CSS transforms of all things, in which IE decided to rotate the element around another axis but still end up at the correct position. That one made me raise my eyebrows. No idea if IE actually was in the wrong, though, but in my head interpolating the xyz value I'm changing feels like the correct way to do it.

  • by marcodiego on 12/10/2021, 3:35:50 PM

    tldr: Simply explained without demonstrations: Quaternions are hypercomplex numbers of the form

    w + xi + yj + zk

    Where w, x, y, and z are real and i^2 = j^2 = k^2 = -1 and ij = k, ji = -k, jk = i, kj = -i, ki = j, ik = -j.

    Being u = (x, y, z) = xi + yj + zk a unitary vector, it is possible rotate any vector q by an angle theta around u by doing:

    pqp'

    where p = cos(theta/2) + sin(theta/2)u and p' = cos(theta/2) - sin(theta/2)u .

  • by darkstarsys on 12/10/2021, 5:40:01 PM

    This is fine; there are lots of similar "intro to quaternions" pages around. One thing I haven't seen yet is someone showing how to interpolate between multiple quaternions over time, smoothly. (Hint: it's not slerp.) It's a non-trivial problem.

  • by imadr on 12/10/2021, 8:01:15 PM

    Very nice interactive visualizations! I've made a similar article some time ago https://imadr.me/rotations-with-quaternions/

  • by alanh on 12/11/2021, 8:30:13 AM

    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`

  • by dang on 12/10/2021, 6:14:54 PM

    Ongoing related thread:

    Let's remove Quaternions from every 3D Engine (2018) - https://news.ycombinator.com/item?id=29512302

  • by jcun4128 on 12/10/2021, 4:15:42 PM

    Nice I will learn these for IMU stuff, I'm still a noob currently.

  • by scythe on 12/11/2021, 6:27:25 AM

    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 >< vA = vn + vR = (v•n)n + v >< 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 >< n)

    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 >< n, viewed as vectors. But multiplication under Im() isn't associative either. But we can also define Im() another way, using the apostrophe for conjugation:

    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).