[HN Gopher] Quaternions
___________________________________________________________________
Quaternions
Author : the_origami_fox
Score : 273 points
Date : 2021-12-10 14:30 UTC (8 hours ago)
(HTM) web link (liorsinai.github.io)
(TXT) w3m dump (liorsinai.github.io)
| Chabsff wrote:
| 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.
| an1sotropy wrote:
| as for why lerp+normalize isn't enough: it all depends on the
| distance between things being blended, no? With far away end
| points, the apparent speed of the rotation would be fast, slow,
| fast, at the beginning, middle, end, which could be a bummer.
| Chabsff wrote:
| The two aspects that slerp() addresses over lerp() +
| normalize() are 1) it can deal with pole-to-pole
| interpolation 2) It always takes the shortest path.
|
| In practice, the former is often provably never going to
| happen, and the later doesn't actually matter from a
| qualitative standpoint: Quaternion interpolation will always
| look a bit weird over large angles, especially if there's a
| roll component to one of the orientations.
|
| As far as having a constant interpolation speed: again, this
| is rarely perceptible, and truly linear transitions from one
| orientation to another looks janky so some amount of
| filtering happens anyways (an ease-in-ease-out for example).
|
| But yeah, for very large interpolations, it can create a
| slight authoring/runtime skew. My rule of thumb used to be:
| use slerp() when the orientations can be at least 120 degrees
| apart, or when lerp() yields weird results. However, it's
| really rare to be interpolating over such a large orientation
| change, you almost always have a few keyframes or dead-
| reckoning syncs in between.
|
| Again: This might be an outdated perspective though.
| gugagore wrote:
| You can see what's wrong with that approach by considering the
| difference between traveling at constant speed along the arc of
| a circle versus traveling at constant speed along a chord, and
| projecting the point (out from the center) onto the arc.
|
| It works great if the chord is far away from the center (and
| also the angle is less than a half turn). If the chord goes
| through the center, it doesn't work at all.
| Chabsff wrote:
| 10-12 years ago, the consensus used to be that this
| singularity simply does not show up in the wild in the vast
| majority of scenarios, and the performance hit of using
| `slerp()` is just not worth it unless truly needed.
|
| It was essentially the same reasoning as for using `-ffast-
| math`. Yeah it's not "correct", but users can't tell the
| difference and it has a measurable performance benefit.
|
| To be clear, I'm not questioning using slerp() at all, it
| definitely has a role to play. I'm just wondering about using
| it by _default_ as implied by the post.
| gugagore wrote:
| Yeah, I understand. I just wanted to show that one can
| understand the exact nature of the approximation in 2D
| geometry.
|
| I think it's useful to think of it as a separate category
| of "wrong" than -ffast-math, which is "wrong" because two
| expressions that are mathematically equivalent over real
| numbers, like a + (b + c) and (a + b) + c, are not
| equivalent over floating-point numbers.
|
| Using lerp in place of slerp is like using x in place of
| sin(x). (The small-angle approximation) They're not
| equivalent over the real numbers.
| Chabsff wrote:
| My apologies. I thought you were providing an explanation
| as to why slerp() is preferred in general. The circle
| example is a really good way to frame the distinction.
| dahart wrote:
| I don't think the scenarios where uniform steps of angle is
| vanishingly small. There are plenty of cases where it matters
| to animators, on character rigs, on cameras
|
| The amount that it matters depends on the angle between keys.
| Suggesting it rarely matters means you're claiming nobody ever
| animates large angles, which I can confidently say I've seen
| plenty of counter-examples in game development.
|
| I also wouldn't be so sure that lerp+normalize is that much
| faster on today's GPUs. Normalize takes a sqrt and reciprocal
| or divide, while slerp takes a few sin evaluations and a recip
| or divide. These special functions these days execute in a
| separate pipeline from linear (FMA) type instructions, and can
| be had for "free" as long as you can mix enough independent
| linear math in between the special functions. It used to be
| that sin() was very slow, but these days you can often mix a
| couple calls in without affecting your perf at all.
| trylfthsk wrote:
| 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...
| ww520 wrote:
| The story goes that he was with his wife going to a dinner. On
| the way he got the flash of insight after years of working on
| the problem but he had no paper to write it down. When passing
| a bridge, he carved the equation on the side of the bridge to
| remind himself on the way back after the dinner.
| agumonkey wrote:
| always have a bridge nearby whenever you're trying to enter
| history
| tiborsaas wrote:
| Ah that explains my failed attempts. It was always too far.
| Agentlien wrote:
| A bridge too far?
| Jun8 wrote:
| 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.
| MayeulC wrote:
| This comment is about C the set of complex numbers, not the
| progamming language. It left me confused for a moment.
| [deleted]
| pdonis wrote:
| _> prove that no such n-tuples exist for n >4._
|
| It depends on how you define "such" n-tuples. The octonions (n
| = 8) aren't associative, but they have all the other relevant
| properties.
| Jun8 wrote:
| You're absolutely right, forgot to mention associativity: htt
| ps://en.m.wikipedia.org/wiki/Frobenius_theorem_(real_divi...
| h2odragon wrote:
| Very nice thats a reference to keep and come back to thanks.
| imadr wrote:
| Very nice interactive visualizations! I've made a similar article
| some time ago https://imadr.me/rotations-with-quaternions/
| matsemann wrote:
| 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.
| newpavlov wrote:
| 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.
| chombier wrote:
| > It's a real shame that people continue to focus so much on
| quaternions in this day and age.
|
| No really, unit quaternions are nice because it's pretty clear
| they belong to a sphere, therefore you can fairly easily extend
| geometric methods on the usual sphere to perform filtering,
| averaging, interpolation etc on rotations.
|
| With GA it's not so obvious.
| kilovoltaire wrote:
| Came here to say this!
|
| I always felt like quaternions weren't a perfect fit for 3d
| rotation, and when I finally learned about bivectors my faith
| in the elegance of mathematics was restored :D
|
| I liked this article: https://marctenbosch.com/quaternions/
| the__alchemist wrote:
| > Why does i2=j2=k2=-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?
|
| Yikes! This is the sort of thing that scares people away from
| complex numbers from a young age.
| [deleted]
| Twisol wrote:
| Aren't you doing a bit of an injustice to that article by
| cherry-picking that line? It's obviously written
| humorously; the very next words are:
|
| > 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.
|
| Clearly, "who care as long as" is not the true belief of
| the author, but rather a mocking call-out of teachers who
| do think that way.
| chadcmulligan wrote:
| GA strikes me as the monad's of physics
| jvanderbot wrote:
| 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.
| joppy wrote:
| Quaternions are the even part of the Clifford (aka Geometric)
| algebra associated to a three-dimensional space, so the
| connection is quite close. This case is also quite special
| because the quaternions form a division algebra over the real
| numbers, meaning that each nonzero quaternion has an inverse.
| Finite-dimensional real division algebras are quite rare:
| indeed the only ones up to isomorphism are the real numbers,
| complex numbers, and quaternions.
|
| Geometric algebra is great if you want to extend things to
| higher dimensions, or spaces with different metric signatures
| (the 4-dimensional spacetime for example). But quaternions
| should not be discounted just because they fit into a
| generalisation - they have many quite special properties all of
| their own.
| rovolo wrote:
| To be pedantic, "each nonzero quaternion has a
| _multiplicative_ inverse "
| wyager wrote:
| Specifically, GA allows you to invent complex numbers,
| quaternions, etc. very easily instead of it taking hundreds of
| years.
|
| I've read _linear and geometric algebra_ and it 's amazing for
| linear operations. Unfortunately it gets more complex when you
| want to use it for nonlinear operations (such as translation) -
| now you need to use CGA or PGA or something. Still, seems like
| it would be amazing for computer graphics, physical simulation,
| etc. especially if someone can figure out a good strategy for
| efficient compilation (e.g. representing a multivector with
| exactly the minimal number of non-zero entries, with non-zero
| basis elements tracked at compile time).
| ChrisLomont wrote:
| 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 performs
|
| [1]
| https://webspace.science.uu.nl/~kreve101/asci/GAraytracer.pd...
| [deleted]
| fanf2 wrote:
| 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 system can check that the resulting of an operation
| is what you expect, eg, two planes intersect in a line. So,
| similar optimizations to gaigen, but (I hoped) more automatic
| and less runtime machinery. But as I said, I didn't get it to
| work.
| ChrisLomont wrote:
| >the same size as it would be as a traditional matrix-based
| linear algebra
|
| You can get it that small, it's all been done, but that's
| far larger than a quat, which can be stored in 3 components
| when normalized, and in 4 for quick and easy computation.
|
| For large models and more importantly scarce GPU memory,
| increasing model size results in less complex models and
| slower computation.
|
| There really is no benefit for 3D engines I can tell (and I
| was early on the GA bandwagon 20ish years ago... It just
| has not and I suspect will never pan out due to the
| inefficiencies not being worth it).
| fault1 wrote:
| i've played with some libraries recently in julia that
| followed this strategy;
| https://discourse.julialang.org/t/ann-cliffordalgebras-
| jl/71...
|
| and I was surprised at how high dimensionality you could
| go. I'd like to see a c++20 version.
| an1sotropy wrote:
| 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...
| analog31 wrote:
| 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.
| Chabsff wrote:
| Still mostly relevant to their use as encoding for
| transformations, but the fact that a unit quaternion's
| conjugate is also its inverse is _extremely_ useful from a
| computational performance point of view.
| fault1 wrote:
| per wikipedia (hence the interest in twistors, spin spaces and
| clifford algebras in physics):
|
| Quaternions also capture the spinorial character of rotations
| in three dimensions. For a three-dimensional object connected
| to its (fixed) surroundings by slack strings or bands, the
| strings or bands can be untangled after two complete turns
| about some fixed axis from an initial untangled state.
| Algebraically, the quaternion describing such a rotation
| changes from a scalar +1 (initially), through (scalar +
| pseudovector) values to scalar -1 (at one full turn), through
| (scalar + pseudovector) values back to scalar +1 (at two full
| turns). This cycle repeats every 2 turns. After 2n turns
| (integer n > 0), without any intermediate untangling attempts,
| the strings/bands can be partially untangled back to the 2(n -
| 1) turns state with each application of the same procedure used
| in untangling from 2 turns to 0 turns. Applying the same
| procedure n times will take a 2n-tangled object back to the
| untangled or 0 turn state. The untangling process also removes
| any rotation-generated twisting about the strings/bands
| themselves. Simple 3D mechanical models can be used to
| demonstrate these facts.
| AnimalMuppet wrote:
| If I understand correctly, yes, calculus on quaternions is a
| useful thing. I'm not sure whether or not you have an
| equivalent of the residue theorem from the calculus of complex
| variables, but I'm pretty sure that you can do path integrals
| and stuff...
| mathgenius wrote:
| John Baez was tweeting about this recently:
|
| https://twitter.com/johncarlosbaez/status/146720413326244659.
| ..
| ivanstojic wrote:
| 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/
| dr_orpheus wrote:
| > 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.
| btilly wrote:
| 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.
| darkstarsys wrote:
| 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.
| JadeNB wrote:
| > Hint: it's not slerp.
|
| What is slerp?
| chas wrote:
| Spherical linear interpolation.
| (https://en.m.wikipedia.org/wiki/Slerp)
| chombier wrote:
| See "A General Construction Scheme for Unit Quaternion Curves
| with Simple High Order Derivatives" (Kim, 1995) for a simple
| extension of Hermite splines to Lie groups, including unit
| quaternions.
| marcodiego wrote:
| 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 .
| handrous wrote:
| > Quaternions are hypercomplex numbers of the form
|
| I'm gonna guess "hypercomplex" means "involves imaginary
| numbers" due to the rest of this.
|
| > 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.
|
| Why even use different letters for i, j, and k, if they're all
| the same thing? Which thing appears to be i, as in, the square
| root of -1, that is to say, the most well-known and basic
| imaginary number, if I'm reading this right. As for the second
| part, I can't even begin to unravel the significance. I know it
| must not be, but it just seems like arbitrary rules added
| for... some unknown reason.
|
| > 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 .
|
| Oooooh kay... 1) Where'd w go? Is this one of those things
| where there's a (situationally-defined) constant in the formula
| but we just pretend it doesn't exist most of the time (until it
| comes time to actually use the math to, like, do anything
| real)? _Would_ we need to bring it back in to apply the rest of
| this? 2) "u =" is just defining something, fine, but (x, y, z)
| doesn't seem to equal the thing after it at all--I suppose this
| is a shorthand function notation, though it seems really weird
| to me to use equality to relate that. Am I right, or is this
| something else?, 3) A quaternion is... a point, then? Since
| we're rotating around it? 4) I've got a feeling that theta
| needs a direction in this hypercomplex space but don't see
| where it's coming from. Somewhere "off screen", in this
| explanation? Or is it there but I'm not seeing it?
| cardiffspaceman wrote:
| It seems to me that i, j, and k are three things that have
| the same property, not three identical things.
| handrous wrote:
| TIL that not every imaginary number is just "i" with
| optional scaling applied. Was taught "the square root of
| negative one _is_ i ".
| fault1 wrote:
| i wish i was taught in terms of euler' formula, which is
| probably the most useful:
| https://en.wikipedia.org/wiki/Euler%27s_formula
| Twisol wrote:
| That's a heck of a great observation.
|
| In the complex numbers, every imaginary number is,
| indeed, just "i" scaled. But the quaternions are like
| three copies of the complex numbers glued together; you
| have multiple kinds of "imaginary", each with their own
| unit -- like "i", but now also copies of it, "j" and "k".
|
| To bring this somewhere more familiar, you can probably
| imagine the real number line as a physical line
| stretching off to infinity. This line has a point called
| "1". Now if we take two more copies of this line, they
| each have their own point called "1" -- a different one
| for each line. And if you stick all three of these lines
| together as a three-dimensional set of axes, you get a
| world in which you have three 1s coexisting. We just say
| "in the X direction" to be clear about which we're
| talking about, or group them together in (x, y, z)
| triples -- in which case X's 1 is called (1, 0, 0).
|
| The situation is the same for quaternions -- we glue one
| real line together with three copies of the imaginary
| line. So we get three different i's, and we give them
| different names to distinguish them.
| AnimalMuppet wrote:
| 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 not two imaginary roots, or four, or 17? Those turn
| out _not_ to have nice algebraic properties. The only other
| thing out there are the octonions, with 7 imaginary roots.
| the_only_law wrote:
| And like that I've given up hope of ever having a good
| understanding of any mathematical field.
| at_compile_time wrote:
| Sounds a lot like the first time I tried to understand
| quaternions. The explanation in geometric algebra as a scalar
| and bivector gives it an intuitive geometric sense that words
| like words like "hypercomplex" fail to. Others here have
| linked to that material.
| marcodiego wrote:
| >> Quaternions are hypercomplex numbers of the form
|
| >
|
| >I'm gonna guess "hypercomplex" means "involves imaginary
| numbers" due to the rest of this.
|
| Think it is right.
|
| >>
|
| >> 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.
|
| >
|
| >Why even use different letters for i, j, and k, if they're
| all the same thing? Which thing appears to be i, as in, the
| square root of -1, that is to say, the most well-known and
| basic imaginary number, if I'm reading this right.
|
| They are not the same thing. All of these are equal to -1
| when squared, but they are different when multiplied by any
| other of this set and multiplication between them is anti-
| commutative.
|
| >As for the second part, I can't even begin to unravel the
| significance. I know it must not be, but it just seems like
| arbitrary rules added for... some unknown reason.
|
| >
|
| These are not added for unknown reasons. They specify
| rotations of unitary vectors of a canonical base around one
| another.
|
| >> 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 .
|
| >>
|
| >Oooooh kay... 1) Where'd w go?
|
| The coordinate 'w' is the real part. For the vector 'u', such
| coordinate is 0. For 'p' and 'p'', it is cos(theta/2).
|
| >Is this one of those things where there's a (situationally-
| defined) constant in the formula but we just pretend it
| doesn't exist most of the time (until it comes time to
| actually use the math to, like, do anything real)?
|
| No.
|
| >Would we need to bring it back in to apply the rest of this?
|
| No. Just follow the rules to multiply hypercomplex numbers
| and the rotation will occur.
|
| >2) "u =" is just defining something, fine, but (x, y, z)
| doesn't seem to equal the thing after it at all--I suppose
| this is a shorthand function notation, though it seems really
| weird to me to use equality to relate that. Am I right, or is
| this something else?,
|
| The notation '(x, y, z)' is just a shorter notation for "xi +
| yj + zk". For this problem, the vector 'u' defines the axis
| of rotation.
|
| >3) A quaternion is... a point, then? Since we're rotating
| around it?
|
| You can see a quaternion as a point in R^4 since it has 4
| coordinates. Actually it describes an axis of rotation, by
| its imaginary part, and the angle of rotation.
|
| >4) I've got a feeling that theta needs a direction in this
| hypercomplex space but don't see where it's coming from.
| Somewhere "off screen", in this explanation? Or is it there
| but I'm not seeing it?
|
| >
|
| The axis of rotation is actually the vector "u".
| handrous wrote:
| Thank you, this was very helpful.
|
| > The axis of rotation is actually the vector "u".
|
| Ah, I thought the vector was what we were rotating.
| marcodiego wrote:
| I think "p" is better described as a point instead of a
| vector. So, a better writing could be: "[..]it is
| possible rotate any point q by an angle theta around the
| axis define by u [...]"
| coldacid wrote:
| I don't believe that most people will consider that "simply
| explained".
| marcodiego wrote:
| Maybe succinctly?
| coldacid wrote:
| Yes, it is certainly succinct. But only simple and
| explained for math majors. :D
| [deleted]
| OccamsRazr wrote:
| tldr tldr (Since your version is for people who already
| understand undergraduate math, this version is for people who
| already understand upper-level undergraduate/graduate math):
|
| If you try to use a product of 3 rotation matrices that
| represent rotations around fixed axes to represent rotations in
| 3D, there will inevitably be gimbal lock because there cannot
| exist a covering map from a product of 3 circles to SO(3).
| (Gimbal lock happens at the points where the map locally fails
| to be a covering map)
|
| SU(2) is the universal cover of SO(3). The unit quaternions are
| a faithful representation of SU(2). Conveniently, the double
| cover map from SU(2) to SO(3) is dead simple in this
| representation: a unit quaternion q in SU(2) act on a purely
| imaginary quaternion (thought of as a vector in R^3) by
| conjugation. This is the formula you wrote.
|
| Since it is a covering map, there is no gimbal lock.
|
| Edited to fix explanation.
| dang wrote:
| Ongoing related thread:
|
| _Let 's remove Quaternions from every 3D Engine (2018)_ -
| https://news.ycombinator.com/item?id=29512302
| jcun4128 wrote:
| Nice I will learn these for IMU stuff, I'm still a noob
| currently.
| [deleted]
| Const-me wrote:
| 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/
| billforsternz wrote:
| I remember reading some library quaternion code (sorry can't
| remember which library) that started out with a lovely quote
| from Hamilton on how the idea burst into his mind in a flash as
| he walked with his wife near the river Liffey I think it was in
| Dublin. So I guess they mentioned it, at least indirectly.
| thermistokles wrote:
| There are actually even more. You can actually have 12
| different variations depending on certain choices. Though the
| other sources of differences are minor.
|
| https://arxiv.org/abs/1711.02508
|
| This is actually a great source of frustration in the robotics
| state estimation community, as you have the influential
| University of Minnesota using JPL, and most other universities
| using Hamiltonian.
| fault1 wrote:
| you also see the variations from the group structure;
|
| https://en.wikipedia.org/wiki/Quaternion_group
| gibsonf1 wrote:
| 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.
| pixelpoet wrote:
| 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.
| the_origami_fox wrote:
| Author here: thanks for the tip. Definitely think this looks
| better
| steve_adams_86 wrote:
| 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.
| dilawar wrote:
| Try reading it up again. My experience is that with age theory
| gets easier.
| akeck wrote:
| I've been teaching myself geometric algebra which is apparently
| isomorphic to quaternion algebra. Some people prefer GA for 3D
| modeling work.
| W0lf wrote:
| Computing in higher dimensions is nice, although pretty
| difficult to implement efficiently. Hence, Quaternions are
| mostly used nowadays, I think.
| smcameron wrote:
| 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.
| jodrellblank wrote:
| > 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").
| anentropic wrote:
| also: gimbol -> gimbal
| naikrovek wrote:
| yeah that one drove me nuts for some reason.
| the_origami_fox wrote:
| Author here: these typos totally eluded me. Will fix them.
| naikrovek wrote:
| tpyos elide us all
| w0mbat wrote:
| I came here to report the same two typos. Thanks.
| dhosek wrote:
| 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.
| macrolocal wrote:
| One neat characteristic is that the derivations of these higher
| Cayley-Dickinson algebras stabilize!
|
| [1] https://projecteuclid.org/journals/pacific-journal-of-
| mathem...
| galaxyLogic wrote:
| Here's a short article that gave me some insight into the
| matter:
|
| https://nautil.us/blog/the-strange-numbers-that-birthed-mode...
|
| "Place your phone face-up on a flat surface, for example. Spin
| it 90 degrees to the left, and then flip it away from you. Note
| which way the camera points.
|
| Returning to the original position, flip it away from you first
| and then turn it to the left second. See how the camera points
| to the right instead?
|
| This initially alarming property, known as non-commutativity,
| turns out to be a feature the quaternions share with reality "
| Zamicol wrote:
| Why do you think the dimensions are in powers of two?
| Twisol wrote:
| Because the construction generating this sequence of algebras
| doubles the dimension every time.
|
| https://en.m.wikipedia.org/wiki/Cayley%E2%80%93Dickson_const.
| ..
| avz wrote:
| Interestingly, if we go in the opposite direction we also loose
| something:
|
| Real numbers (1-dimensional): No more algebraic closure [1]
|
| though as you suggest we do gain a nice ordering where "nice"
| means "compatible with operations". BTW, you can always impose
| _some_ ordering on all of these sets. It is the orderings '
| compatibility with arithmetic that we lose going from real
| numbers to complex numbers.
|
| This can be generalized a little. Real numbers fail to be
| algebraically closed because some real polynomials lack real
| solutions, e.g. xx=-2. Complex numbers "fix" this problem since
| there every n degree polynomial has exactly n roots (counting
| multiplicity). In a sense, quaternions overdo this, e.g. xx=-2
| has an infinite number of solutions (exercise for the reader).
| However, since quaternion multiplication is not commutative,
| polynomials as traditionally understood are ill-defined. For
| example, axx, xax and xxa are different degree two quaternion
| "polynomials". Ugh.
|
| [1]: https://en.wikipedia.org/wiki/Algebraically_closed_field
| nabla9 wrote:
| First 4 (reals, complex, quaternions, octonions) are normed
| division algebras.
|
| Normed means that each number has associated nonnegative real
| number that describes the "size" of the number, also |xy| <=
| |x||y|. Number having a size (a norm) is very useful concept.
|
| Sedions and the rest are less useful because they are not
| normed algebras.
| adamnemecek wrote:
| 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
| 2143 wrote:
| 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.)
___________________________________________________________________
(page generated 2021-12-10 23:00 UTC)