17 ms·
Rotations with quaternions
- imadr 5y agoI made this guide on how to implement quaternions yourself and use them to rotate objects in a 3D engine. The implementation is probably not the most efficient, but I tried to make it simple enough to understand how quaternions work.
- KboPAacDA3 5y agoThank you for making this and getting straight to the useful code. Too often, guides on quaternions stray into proofs and waste time for a programmer who just wants to apply the quaternion concept.
- deleted 5y ago[deleted]
- gspr 5y agoThe reason this works is often skipped in computationally oriented writeups: Rotations of 3-dimensional real space form the topological group SO(3). Naive parameterizations of that group do not form a cover [1], but the group of norm-1 quaterinons, Spin(3), does. The failure of naive parameterizations, like the Euler angles, to be a cover manifests itself as gimbal lock. [1] https://en.wikipedia.org/wiki/Covering_space https://en.wikipedia.org/wiki/Covering_space
- quietbritishjim 5y agoYou're definitely right to bring up Gimbal lock [1] One of the benefits of knowing about it is to know when it doesn't matter to you. In that case, you can just use Euler angles, as you say. If you just need to express a rotation in terms of three angles, or convert back from three angles (e.g. yaw/pitch/roll [2]) to a rotation matrix, then you don't need to know about quartertonians at all. [1] https://en.wikipedia.org/wiki/Gimbal_lock https://en.wikipedia.org/wiki/Gimbal_lock [2] https://en.wikipedia.org/wiki/Aircraft_principal_axes https://en.wikipedia.org/wiki/Aircraft_principal_axes
- gspr 5y agoEven in this case you need to take care of the action of rotations on points near the poles, don't you? (I don't remember, it's been a long time since I did such calculations). But yes, otherwise I agree with you.
- gilbetron 5y agoIf you are going to apply 3 angles directly, then you run into problems (specifically, if you pitch +/- 90 degrees, then roll and yaw become the same thing, aka gimbal lock). If you take those 3 angles and convert them to a matrix, and use that matrix to apply the angles, you're all good. You can then even take the new matrix and pull 3 angles out of that.
- toxik 5y ago… and those three angles will be discontinuous at the poles.
- GolDDranks 5y agoHere's a similar argument from my naive, intuition-based perspective: It's important to remember that the the group of rotations in 3d space is represented by _unit_ quaternions. This is a subset of the full 4d quaternion space: a spherical shell around the origin, like the skin of a 3d ball but in 4d. A 3d ball has a 2d, "flat" skin that is "spherically" symmetric. A 4d ball has a 3d, "volumetric" skin that is, similarly, "spherically" symmetric. If we are stuck to that 3d skin, it makes perfect sense that it manages to represent rotations in 3d, which have 3 degrees of freedom and spherical symmetry. The space of rotations that is formed by this "skin" has two special points: the point where all the imaginary coordinates are zero and the real coordinate is one, and it's dual, the negative one, precisely because we are talking about _unit_ quaternions. (Similarly as there is only two "purely x" points in a unit circle: (1, 0) and (-1, 0)). These points represent the identity rotation, i.e. "don't rotate at all". This makes sense, if you think how complex numbers work: the effect of multiplying "one" is that it keeps everything as-is, whereas every other "unit" complex number has a rotating effect. Then as you think the three imaginary dimensions as degrees of freedoms you can start traveling into, from this neutral point, you get all kinds of rotations. The geometry of the "round", "skin-shaped" space ensures that the rotations wrap around the correct way, "spherically". Especially that after you have travelled "tau" (2 times pi) units, you are again in purely "real", "not rotated" state. And the spherical symmetry means that this works similarly in _any_ direction you can travel to. The only gotcha is that the unit quaternion space contains doubly the space of minimal 3d rotations, because of the negative number symmetry. There's some good arguments why this is especially beautiful and true, but they are a bit beyond me.
- hanche 5y agoThere is a nice experiment you can do, illustrating this: Hold a glass of water in the palm of your hand. Not too full, especially not until you get the hang of the following move: Assuming you use your right hand, rotate your hand counterclockwise. At first, your hand goes under your arm, until it has rotated about 270 degrees or so. You can now continue that rotation, but you have to lift your hand up, so it is now above the arm. Keep going, and you end up where you started, but the glass has done two full revolutions. Hopefully without spilling an water (takes practice). The fun thing is, after just one revolution, your arm is twisted into a really uncomfortable configuration. The mathematical explanation is that SO(3) is doubly connected, whereas the unit quaternions, like any sphere, is simply connected. At any time, each part of your arm has undergone some rotation from the orientation at rest. Halfway through the move, as you travel from the shoulder down to the hand, this rotation starts at the identity, and changes continuously through one rotation, back to the identity once more. But in the unit quaternions, that path takes you from one pole to the opposite pole. This explains why you can’t untwist your arm. Sorry if that made no sense. Edit: Have a look at “Your palm is a spinor” [1], and then at this Phillipine* tradtional dance [2] about 40 seconds in. I knew I had written about this before [3]. [1] https://www.youtube.com/watch?v=fTlbVLGBm3Q https://www.youtube.com/watch?v=fTlbVLGBm3Q [2] https://www.youtube.com/watch?v=mOO_IQznZCQ https://www.youtube.com/watch?v=mOO_IQznZCQ [3] https://math.stackexchange.com/a/383549 https://math.stackexchange.com/a/383549 * I wrote Thai originally.
- imadr 5y agoHow far into algebra do you need to get to understand "Rotations of 3-dimensional real space form the topological group SO(3)"? I kinda understand that norm-1 quaternions map to rotations in 3D space somehow but I can't prove it myself. What kind of curriculum do I need to follow to really grasp this?
- gspr 5y agoTo understand the definitions and apply them in practice, a first course in group theory + a basic understanding of vector calculus suffices. To add the adjective "topology", the first parts of a general topology course is enough. To truly appreciate groups like SO(3), a course in differential geometry and differential topology is useful. Edit: This is all assuming you have no background in mathematics (or, alternatively, physics) at all. If you do, a targeted text can teach you these concepts in a few pages.
- billfruit 5y agoThe thing is group theory is taught in an incredibly abstract manner, its hard to find any motivating application for it, or any problems it helps us solve. Also terminology/definitions are vague too, whether a vector has an endpoint or it something unachored in space is itself not clear from many treatments.
- gspr 5y ago> The thing is group theory is taught in an incredibly abstract manner, its hard to find any motivating application for it, or any problems it helps us solve. Mathematics is abstractly defined. But for basic group theory there's a plentitude of very concrete examples to rely on. > Also terminology/definitions are vague too, Absolutely not. There is no vagueness at all! Everything is completely well-defined in most introductory textbooks/courses (or you can even read the precise definitions on Wikipedia, which is often not the case). > whether a vector has an endpoint or it something unachored in space is itself not clear from many treatments. Vectors do not have endpoints. Vectors are not anchored. Vectors are elements of vector spaces. Vector spaces are completely clearly defined.
- rnhmjoj 5y agoTechnically the unit quaterions are not Spin(3), but only isomorphic to it, they are properly Sp(1) = GL(1, H). It's all fuzzy because the low dimensional classical groups are all isomorphic to each other: SU(2) ~ Sp(1) ~ Spin(3).
- gspr 5y agoIndeed.
- jacobolus 5y agoThis seems extraordinarily nitpicky. Like saying that unit complex numbers are technically not the group of plane rotations about a fixed point, but only isomorphic to it. Or for that matter like saying that the "real number line" is technically not a line, but only isomorphic to one.
- rnhmjoj 5y agoWell yeah, it is. The point I wanted to make is that these isomorphism are "exceptional"[1] and only hold for the lower dimensional groups. The general Spin group and quaterions are very different objects. [1]: https://en.wikipedia.org/wiki/Exceptional_isomorphism https://en.wikipedia.org/wiki/Exceptional_isomorphism
- joppy 5y agoThat really depends on how you define Spin(3), for example some would define it as the compact simply-connected Lie group of a certain type, at which point the unit quaternions model of Spin(3) is as good as any other.
- tobinfricke 5y ago> Technically X is not Y, but only isomorphic to it Not sure this is a useful argument. If two structures are isomorphic, there is no way to tell them apart. If you can't tell them apart - maybe they are the same thing.
- nick__m 5y ago
- hanche 5y agoI know what you mean, but I would hesitate to call Euler angles naïve. ;-)
- an1sotropy 5y agoSpeaking of gimbal lock - it was a real (as opposed to only theoretical/mathematical) concern for navigation during the Apollo 11 moon landing [1]. Euler angles are fugly and annoying. Quarternions are clean and refreshing. [1] https://apollo11space.com/apollo-and-gimbal-lock/ https://apollo11space.com/apollo-and-gimbal-lock/
- blovescoffee 5y agoThis is really interesting. Why does the failure of naive parameterizations to form a cover imply a group with gimbal lock? I'm unclear on how a cover is linked to gimbal lock. I've taken undergrad topology and algebra if you could explain in those terms (I understand what a covering is).
- bollu 5y agoDo correct me if I'm wrong: I thought Spin(3) was a double cover, with the quaternions being one sheet of the covering, that of the connected component of the identity?!
- aardvark179 5y agoSince this will get posted here anyway I’ll just get it done now. https://marctenbosch.com/quaternions/ https://marctenbosch.com/quaternions/ I don’t entirely agree with the article’s viewpoint that people do not perfectly understand quaternions and therefore they should not be used, as I get the feeling there are many parts of 3D graphics that are not perfectly understood by developers, and that’s okay.
- marosgrego 5y agoThe Geometric Algebra viewpoint is much nicer, more natural and encompasses more.
- frankus 5y agoSort of unrelated but I wonder if this could make certain kinds of latitude/longitude calculations easier.
- jacobolus 5y agoIf you are dealing with a sphere, is much easier to work with pure vector methods than with classical spherical trigonometry. If you are dealing with an ellipsoid of revolution, then vector methods can also get tricky.
- FabHK 5y agoA few remarks: 0) Very nice practical introduction to quaternions and their application to rotation. 1) Neat didactic "textbook" implementation, but note that it is not production quality (eg potential overflow in the norm function unnecessarily). That was not the aim, either, but just something to bear in mind. 2) As a supplement, a useful practical reference for rotations in 3D (with good clarifications and basically all formulae you'll ever need, but no implementation) is Representing Attitude: Euler Angles, Unit Quaternions, and Rotation Vectors by James Diebel https://www.astro.rug.nl/software/kapteyn-beta/_downloads/attitude.pdf https://www.astro.rug.nl/software/kapteyn-beta/_downloads/at...
- tbabb 5y agoWhat would you do differently with the norm function?
- hanche 5y agoTo compute a norm without overflow (unless it is totally unavoidable), let m be the maximum of the absolute values of the components. Divide each component by m, compute the square root of the sum of squares, and multiply by m. Only the last step might overflow, and if it does, it could not be avoided in any case. Incidentally, this normalization procedure also avoids underflow problems.
- tbabb 5y agoI see. I'd say it depends what the application is, then, because in graphics correctly handling (unlikely) extreme values would be quite secondary to performance, especially for an inner loop function like norm. See fastinvsqrt, e.g., which is extremely imprecise!
- hanche 5y agoIn many applications there is definitely no reason to worry about overflow when computing norms. That is more of an issue if you are writing library code for general use, which should be as robust as you can make it.
- rthomas6 5y agoAs a non-math person, I've thought a lot about quaternions and why they need 4 dimensions, and why there aren't 3d complex numbers. It's because if you think about it, on the complex plane, the imaginary number i just represents a rotation of 90 degrees. Now if you think about a 3d space, i represents a rotation across one dimension, and j represents a rotation across another dimension. But how do you rotate from i to j? You can't without another number k.
- hanche 5y agoHamilton famously had the same problem before he came up with the quaternions.
- darkstarsys 5y agoThis is good, thanks. But a much more interesting problem I haven't seen a good writeup for is how to interpolate smoothly between quaternions at different times. Quaternion slerp has jerks (C_0 but not C_1 or C_2) at the keyframes.
- gilbetron 5y agoIt's been a while for me, but iirc, there's two ways you can slerp between two quaternions, and by using the shortest path, you can avoid the jerk.
- dahart 5y agoKen Shoemake’s 1985 Siggraph paper “Animation Rotation with Quaternion Curves”, that brought quaternions to computer graphics, covered this. The idea is to use quaternions as control points in a spline the same way you would use 3d points in a spline. You could have a series of quaternion orientations, and connect them with C_2 continuity by using a connected series of piecewise cubic Bezier splines. The abstract mentions it: “This paper gives one answer by presenting a new kind of spline curve, created on a sphere, suitable for smoothly in-hetweening (i.e. interpolating) sequences of arbitrary rotations.” And the final punch line is section 4.3, then you can work through the details in the earlier sections. https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf
- chombier 5y agoI've used "A General Construction Scheme for Unit Quaternion Curveswith Simple High Order Derivatives" in the past, and while not perfect it was generally good enough and fairly easy to implement. Basically it extends Hermite splines to Quaternion splines using the Lie group operations.
- xaedes 5y agoYou can use bezier splines (https://ibiblio.org/e-notes/Splines/bezier.html https://ibiblio.org/e-notes/Splines/bezier.html). These just use linear interpolation, multiple times. In the case of quaternions replace the linear interpolations with quaternion slerps and you get quadratic bezier splines over orientations.
- marcodiego 5y agotldr: 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 parallel to a rotation axis, it is possible rotate any vector q with a theta arc around u by doing: pqp' where p = cos(theta/2) + sin(theta/2)u and p' = cos(theta/2) - sin(theta/2)u .
- Jyaif 5y agoMost of the time you don't want to use his SLERP function. You can even see what is wrong in his illustration video: the cube does 3/4s of a full rotation, while only 1/4 of a full rotation would have been sufficient. In other words, it's not always taking the shortest path between 2 rotations. If you are not careful, this is what you may end up with: https://www.reddit.com/r/FIFA/comments/9gms3n/most_realistic_graphics_ever_in_fifa_history/ https://www.reddit.com/r/FIFA/comments/9gms3n/most_realistic...
- imadr 5y agoWhat would be the alternative to slerp that takes the shortest path?
- edflsafoiewq 5y agoJust replace q2 with -q2 if q1 and q2 are in opposite hemispheres, then slerp.
- imadr 5y agoIf I'm not wrong you check if q1 and q2 are in opposite hemispheres with the sign of their dot product?
- edflsafoiewq 5y agoYes.
- OmarShehata 5y agoThis article incorrectly states that gimbal lock is a property of Euler angles, and that using quaternions prevents it. This is a common misconception. Euler angles can be used to rotate an object exactly the same way as quaternions do with no gimbal lock. Similarly, you can apply quaternions in such a way that gimbal lock will happen (if you wanted to represent a physical system of gimbals with quaternions, where that is a physical property). I wrote a short article demonstrating and clarifying this, hope it helps: https://omar-shehata.medium.com/how-to-fix-gimbal-lock-in-n-dimensions-f2f7baec2b5e https://omar-shehata.medium.com/how-to-fix-gimbal-lock-in-n-...
- DecoPerson 5y agoI was hoping your article would example how gimbal lock can occur with quaternions, but from a quick skim I can’t see any such paragraph. Would you mind elaborating?
- OmarShehata 5y agoIt's at the bottom of the "What causes gimbal lock?" section, the final code snippet: ``` rotationAroundX = Quaternion.fromAxisAngle(angle1, Xaxis); rotationAroundY = Quaternion.fromAxisAngle(angle2, Yaxis); rotationAroundZ = Quaternion.fromAxisAngle(angle3, Zaxis); cubeRotation = rotationAroundX * rotationAroundY * rotationAroundZ; ``` Basically, you store 3 quaternions, representing 3 angles, and combine them to get the final rotation. You might say "This is just quaternions emulating Euler angles!" and my answer is, sure. You can say the same about rotation matrices. There's nothing inherent about rotation matrices that makes them susceptible to gimbal lock. You can implement them as representing 3 fixed angles, thus gimbal lock, or you can implement them as accumulating rotations, thus no gimbal lock. Same is true of quaternions. The fact that you can get gimbal lock with quaternions is a feature, not a bug. Quaternions are just one way to describe rotations. Gimbal lock is a natural phenomenon of certain physical rotation systems, and can be described whether you use quaternions, or matrices etc.
- imadr 5y agoThanks for the heads up, I'm going to rephrase the statement about gimbal lock and link you article. And just to be 100% sure, is the approach I'm using the right one: storing a quaternion instead of 3 angles, multiplying, overwriting the rotation value?
- dnautics 5y agoam I wrong that this use of a union is UB in C?
- imadr 5y agoI'm absolutely not a pro in C, so if it is undefined behaviour I'd be glad to know and fix it, I just found out about the notation and it looks handy
- dnautics 5y agochecked myself. My cursory, poor search suggests it's UB in C++, but not in C?
- steerablesafe 5y agoIt is definitely UB in C++ and probably implementation defined in C (and this use is fine all implementations, AFAIK). Some C++ implementations allow this as a conforming language extension.
- dnautics 5y agothanks for clarifying!
- Scene_Cast2 5y agoAs a much more intuitive version of quaternions, there's Geometric Algebra (aka Clifford Algebra). In 4D, the calculations end up being the same, but there's much more intuition and generalizability behind the Geometric version.
- sojuz151 5y agoSmall trivia: Existence of two unit quaternions corresponding to the same rotation is the same thing as the fact that an electron must be fully rotated twice before it has the same configuration as when it started.
- marosgrego 5y agoHow?
- a1369209993 5y agoWhich is also the same as the fact that (very, very roughly) the virtual photons that make up a electron's electromagnetic field have continuous (in the calculus sense) polarization over time and space.
- deleted 5y ago[deleted]
- ww520 5y agoQuaternion is great for dealing with 3D rotation. Another great approach is using the rotor in geometric algebra. It's pretty simple and it works on rotation in dimensions higher than 3D as well.
- vladTheInhaler 5y agoFor anyone who is interested in an accessible introduction to representing rotations, I highly recommend this site: https://rotations.berkeley.edu https://rotations.berkeley.edu. One of my professors provided it for one of his courses, and it's been a really helpful reference several times since then.
- neonological 5y agoGuys I work at a company that uses Quaternions for rotations of physical objects. PTUs we call them (Pan Tilt Units). I am telling you Quaternions have HUGE issues. These issues become much more apparent when you deal with physical objects. Here's the thing Quaternions don't exist in reality. It represents an orientation of rotation but it completely masks the path took to achieve that orientation. For every gimbal in reality there is an actual YawPitchRoll (YPR) that was executed to achieve that orientation. AS soon as you convert that real YPR into a Quaternion you lose the YPR that was needed to achieve that orienation. So let's say I need to have one gimbal imitate the position of another gimbal. I take the YPR given to me by gimbal "A" convert the YPR to a Quat, send that Quat over the wire to Gimbal "B" and convert that Quat back to YPR to feed to the gimbal so it can rotate itself to imitate the orientation of gimbal A. The quat is a higher entropy form of information. Now when converting back to YPR there are MULTIPLE YPRs that yield the same orientation. You can derive a YPR that is out of bounds of the physical gimbal. Literally you can get a YPR that tells your gimbal to Yaw 190 and pitch all the way back past 90 to 170 degrees and roll 180 degrees until it's right side up. This YPR is identical to a yaw of 10, a pitch of 20 and 0 roll. Quaternions hide the original YPR, you lose information so when you receive a Quaternion it's hard to translate it into a physical realization of the orientation. The company I work for doesn't realize this. They used Quaternions from day one and we have all kinds of headaches like this when we try to extract the YPR and use these orientations in the real world. Actually I should say only I have these headaches. A lot of people haven't figured out this problem yet. The only time you should use Quats are if you need to transform an orientation or you're dealing with virtual objects that have no rotational limits. Everybody thinks quats are magic and better. They are not. They have huge downsides. Huge.
- dakr 5y agoThis real hardware handles quaternions just fine: https://en.wikipedia.org/wiki/Stratospheric_Observatory_for_Infrared_Astronomy https://en.wikipedia.org/wiki/Stratospheric_Observatory_for_...
- neonological 5y agoI'm sure it does, I'll give you the benefit of the doubt even though the article makes no mention of Quaternions. My point is, using Quaternions for physical devices is using a hammer on a screw. Huge mistake, but it can be done by people who don't know any better. I'm guessing you worked on this and bought in to the whole Quaternion BS? I'm in the defense industry as well and guess what? Basically most people don't know any better.
- greggman3 5y agoBe aware, quaternions are not always the right solution. There's a reason Unity, Unreal, 3DSMax, Maya, Blender, etc all support Euler interpolation in animation. A simple example is an artist might want to show a clock hand spinning fast to show the progress of time. To do that they set a start angle of 0 and an end angle of say 20000. Sure, there may be ways to represent that with specialized quaternions but in general the 3D tools all seems to default to using Eulers. This is an issue with the GLTF format. They chose quaternions to represent rotations in animation and as such can't easily represent what the artist's intent was. You might claim you can sample the Euler animation and split it into multiple quaternion slerps but that brings up another issue which is you need support for discontinuous animations in order to handle other situations (another thing the GLTF format apparently didn't consider).
- sillysaurusx 5y ago“Why not both?”
- mottosso 5y agoYes, exactly. The article even points this out: > However writing a rotation directly in quaternion form isn't really intuitive, what we do instead is convert an Euler angle to a quaternion then use it for rotating.
- jonas21 5y agoYeah, I think any time you need to interface with a human, Euler angles are better because they're more intuitive. There's a good reason aircraft instruments display things in Euler angles, for example.
- klodolph 5y agoQuaternions usually match artist's intent, and Euler angles usually don't. glTF isn't alone in using quaternions. I did a bunch of FBX imports a while back all the orientation channels are just quaternions. It makes sense, because it's one natural way to interpolate rotation data, just based on the orientations of bones during the keyframes. The kind of stuff that you interpolate using Euler angles is going to be stuff that is naturally on gimbals, like cameras, tanks, robots, turrets, and stuff like that. You can do that easily enough by adding another node to your transform hierarchy with quaternions, but if you started off with Euler angles, you don't really have a way to back out. Quaternions are not always right, but they are the right default. If you want Euler angles, you can always translate to-from quaternions. Quaternions are independent of the way you set up the coordinate system and each axis is equal. Unity, for example, uses quaternions internally. It exposes getters and setters for Euler angles that do the conversion to/from quaternions as a convenience. The editor edits Euler angles but they disappear as soon as you are in-game, and if you open up your scene file in a text editor, you'll see m_LocalRotation with the x/y/z/w of a quaternion. I believe Unreal is the same way. Honestly, that just makes too much sense. Trying to do a physics simulation with Euler angles is just adding extra steps, because Euler angles are not easily composable. If you want to compose two Euler angles to get a third, the easy way to do it is to convert to quaternions, multiply, and then convert back to euler angles. You can see Euler angles in the editor when you are animating a model, but most of the time you are just dragging stuff around on screen or matching mocap data and quaternions make 100x more sense than Euler angles for representing that stuff. My sense is that any code which does a lot of trig, when there's an obvious way to write the code that does no trig, should probably be rewritten to eliminate the trig. A little bit of sin/cos/tan is fine but as soon as you are doing round trips with acos/asin/atan, you have to start considering where the branch cuts are.
- rdevsrex 5y agoThere was a post about Geometric Algebra, a while back. Is that more in use these days?
- Jenz 5y agoWas hoping to see some discussion on this too.
- Syzygies 5y agoIn "Further Reading" the article links to [Let's remove Quaternions from every 3D Engine](https://marctenbosch.com/quaternions/ https://marctenbosch.com/quaternions/) which is about Geometric Algebra. Many chefs are brilliant, but only Jeremiah Tower's book covers will tell you he's brilliant. Many branches of mathematics are of great utility. Geometric Algebra will breathlessly tell you this. I know few fields quite so evangelical. If you don't know better, you should use quaternions rather than matrices. If you don't know better, stick with quaternions and avoid the generalization presented by Geometric Algebra until the benefit is clear. This tension is probably why the field is so evangelical. Quaternions are inevitable. In ten thousand runs of the simulation, sentient beings would come up with quaternions every time. Geometric Algebra is not so inevitable. An aesthetic awareness of the centrality of ideas guides some but not all mathematicians. Like that famous quote about taking an instant dislike to Ted Cruz, it saves time.
- marosgrego 5y agoWhat makes you think quaternions are inevitable, but geometric algebra is not?
- captainmuon 5y ago> A quaternion is basically a 4 dimensional vector, so it has a magnitude (or norm, or length) Is it really a vector in the physical sense? People often say vector when they mean N-tuple -- for example we learned in high school that vectors are just N numbers taken together. For physicists, a vector must satisfy certain transformation laws - it must transform in the correct way if a rotation is applied, and the scalar product must be invariant of the coordinate system, IIRC. I don't have enough intuition of quaternions to say how they behave under transformations, though. I would be surprized if you could have "proper" vectors with four components in three-dimensional space.
- marosgrego 5y agoIt's a vector in the mathematical sense.
- foo92691 5y agoWell, quaternions form a vector space over quaternion addition. This part is not very interesting. Vector spaces do not describe multiplication of vectors by each other. So, quaternions are not (only) vectors "in the mathematical sense" when it comes to their more interesting properties.
- marosgrego 5y agoWhat do you mean? They also form an algebra (a vector space where a "multiplication" is defined).
- littlestymaar 5y agoA vector is a member of a vector space. A vector space is a set V + a Field F, where for all x,y in V and a in F, x + ay is also in V. That's it.
- Animats 5y agoFor a simpler discussion, see [1]. [1] http://wiki.secondlife.com/wiki/Rotation http://wiki.secondlife.com/wiki/Rotation
- unholiness 5y agoIf you want to intuitively understand why this particular 4D construction is the right representation of a 3D rotation, then I highly recommend 3blue1brown's explorable interactive video series on the topic: https://eater.net/quaternions https://eater.net/quaternions The interactive videos alone are quite the technical feat, but after going through it, it's honestly hard to imagine fully understanding this topic with less technology (or with a less incredible teacher!)
- nighthawk454 5y agoIn particular, that toggle switch to show it in terms of an angle makes it super clear. The 4 components can be re-written in terms of 3 variables for an orientation vector and 1 variable for rotation about that axis. Basically "point this way and rotate this much". The 4 variables are expressed as two complex numbers. That helped me understand what the quaternions are actually describing. Incidentally, it also kind of explains why 3 variables isn't enough, and so the regular rotation thing must not be sufficient.
- mwkaufma 5y agoThese implementations of difference and slerp aren't accounting for geometric double-cover. You want to do a dot-product check first to make sure you're in the same "hemisphere"
- gabereiser 5y agoI love this. Quaternions were my nemesis while learning 3D math. I think it was the way I was taught it but quaternions always confused me as I mixed them up with euler angles. Having resources like this that explain them in detail really helps grok what quaternions are, can do, and how to incorporate them in your project. Great job! I’m over the hump now. I use dual quaternions for skinning and single q’s for rotation storage (why store 3x3m when a 4f quaternion will do?).