Search Unity

Quaternions explained

Discussion in 'General Discussion' started by Cataclysmix, Jan 19, 2016.

  1. Cataclysmix

    Cataclysmix

    Joined:
    Aug 2, 2015
    Posts:
    3
    James Grime has explained quaternions in a Numberphile video (for anyone interested):

     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    That isn't very good. The dude simply rehashes the information that is available all over the internet, and wastes 12 minutes doing so.

    The best explanation of quaternion I've ever seen is that:

    Quaternion is 2D plane where Y axis is 3component vector representing rotation axis.
    On that plan you rotate unit length vector that represents rotation with halved angle.
    Meaning (Y: 0, X: 1.0) is no rotation, (Y:0, X: - 1.0) is 360 degree rotation, and (Y: 1.0, X: 0.0) is 180 degree rotation, while (Y: -1.0, X: 0.0) is 180 degree rotation in opposite direction.

    Basically imagine a knob that can be rotated by 180 degrees clockwise/counter-clockwise from neutral position. The knob controls rotation of some object and sits on rotation axis. That's quaternion.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,128
    Welcome to most video tutorials.
     
  4. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    Still better than "uhh" and "umm" every 2 seconds.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,128
    Definitely. His enthusiasm did shine through. Shame I still didn't understand much of any of it. :(
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    Or

    "Before I show you where is that checkbox you're looking for, let's briefly discuss american civil war for half an hour".
     
  7. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Whomever wrote that doesn't understand them at all, or it's the earliest part of a very long explanation.

    Quaternions describe a four dimensional hypersphere, and basically there is no simple way to explain what they are in a way that will help you understand why they work the way they do. "There is no royal road to geometry," as Euclid phrased it. I have this 400 page textbook on the shelf behind me which is entirely devoted to quaternions for rotations (they have other uses), and the math is extremely dense and complicated. I understand most of the individual bits (e.g. I can translate the various mathy bits into useful code), but not being a mathematician, I still don't have an especially good Big Picture understanding of it.

    The textbook does contain probably the most concise (yet useful) description I've ever read, which is, "Quaternions represent the geometric interpretation of complex numbers."

    But that only scratches the surface, and even after you understand the math, you still can't actually visualize anything in four dimensions. Many years ago I had to write my own Euler/quaternion conversion and lerp functions in C for a D3D project. Now I'm thankful somebody else is taking care of that for me!
     
    Zagule, landon912 and Ryiah like this.
  8. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Technically, that checkbox is located posterior to the northernmost fault line of the Northwest Passage. ;)
     
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    That kind of argument doesn't fly here.

    Any idiot knows that quaternion is a technically a coordinate constrained to surface 4 unit-sized dimensional hypersphere.

    However, that doesn't help you in when trying to visualizing them or making it "click" like 4x4 matrix (which conveninetly just stores local coordinate and local axes.

    The tricks with "visualize quaternion as 2 3-dimensional filled spheres connected to each other through spherical shell" are not hhelpful, and you can memorize i^2=j^2=k^2 = ijk = -1 all you want, that's not helpful in the slighest either.

    However, when treat them the way I described before - where i/j/k are Y and w is X, it instantly clicks and becomes trivial to understand.

    As they said, "if you can't explain it simply you don't understand it well enough". If they spent 400 pages on rotations and you still didn't get the big picture, then the author should've tried harder.

    Yes you can. Even if you don't want to deal with proper 4d to 2d projection, visualize 3d component as 3d, and 4th component as color. Not to mention that any n dimensional space can be represented as several projections to spaces with less dimensions.
     
    Teravisor and AndrewGrayGames like this.
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Here is a better video, and one far more practical for game developers.



    The whole thread it came from is a relatively fascinating discussion on the topic. http://forum.unity3d.com/threads/the-_mysteries_-of-quaternions.336731/

    The identity and the 4D sphere in complex space thing are pretty useless to game devs. In fact most of quaternion mathematics is pretty useless to everyone these days. Modern vector math has pretty much replaced it.

    The reason quaternions are still used for 3D rotations is pretty fascinating. You don't need to. Rotation in 3D space only has 3 degrees of freedom. Meaning that three numbers are perfectly sufficient to describe any rotation. You can see this in the way that quaternions are used in Unity, they are all unit quaternions. So x^2 + y^2 + z^2 + w^2 = 1. That equation eliminates a degree of freedom, meaning that every quaternion we use only has three numbers. You can describe any rotation by just setting the x, y and z component of a quaternion.

    So why use quaternions? Why the fourth number? It turns out quaternions have double coverage. Every rotation is described by exactly two unique quaternions. This makes it possible to do cool things like smoothly interpolate between any two rotations. There is no sudden jumping from 360 to 0. There is no gimball lock or degenerate points.

    The fact that quaternions use complex numbers is largely irrelevant to game developers. As is the i^2 + j^2 + k^2 = ijk = -1 identity. Sure this all helps out in the engine mathematics. You need to know this stuff if you ever plan to multiply two quaternions by hand. But the libraries for this are pretty well established.
     
  11. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,563
    Mostly on the spot.

    Quaternions are used for interpolations, because interpolating it via other rotational representations is major pain.

    However, about the whole ijk thing.

    The whole point of ijk idea is that it establishes mathematical rules for quaternion operations in such way, that calculations still make sense when done in algebraic form and will result in correct outcome. It is the same thing as i^2=-1 pretty much only defines that multiplying by i rotates number by 90 degrees on complex plane. The thing is important because that kind of rule allows you to use school algebra ( like a(b+c) = ab+ac) and get rotation/2d stuff handled automatically. It is a beautiful idea, but there's no incredibly deep meaning in it.
     
  12. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,498
    Awesome!
     
    BrainSlugs83 likes this.
  13. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Quaternions is actually one of the few things where i have chosen to learn how to use them for what i need them for, and not to learn the theory behind it in any way. :D

    One day i might have to. Lets hope that never happens!
     
    AndrewGrayGames and Schneider21 like this.
  14. LarryTheBrave

    LarryTheBrave

    Joined:
    Nov 20, 2016
    Posts:
    24
    Quaternions as I understand here are merely an extension of the Pythagorean Theorem. They can have different dimensional levels. The "knob" version is a^2+b^2=c^2 where c=1. The "hypersphere" one uses a negative 1 as the "hypotenuse" of a "triangle" in 4 dimensions. Probably not needed for Unity. Spherical 3D ones (useful for games) describe any rotation by indicating where the end of a line is on the surface of a sphere that it reaches. I could be wrong but I see familiar Pythagorean math going on with this.
     
  15. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    It was in the last dot release version of Unity. It’s now over the river and through the woods, and it’s been renamed to “checkery box”.

    If only everyone specified the Unity version they use in their instructional material.
     
  16. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
    I think a lot of the confusion stems from the fact that no-one defines what a rotation actually is.

    In day to day speech, we use it interchangeably for two different concepts. The first one is to describe an orientation in space (sometimes referred to as an attitude of an object), in relation to a 3D coordinate system. For this, euler angles are fine, any orientation in space can be represented by euler angles and there are no problems.

    The other one, and where quaternions are useful, is when an object changes it orientation from one attitude to another. Now, in the hairless-ape-brain, we tend to think of this as an analog continuous motion where we turn the object first this way, then that way, until it aligns with the new attitude, but this is not what's actually happening.

    A more precise definition of this kind of rotation, is a transformation, and more specifically an affine transformation, of a point or a set of points in 3D space. A point that is "rotated" using an affine transformation does not gradually move from one angle to another, it is just at one point before the transformation, and then at a different point after the transformation.

    In two dimensions, we can use complex numbers to represent this kind of transformation. The way we do it, is we specify a line going through the origin, and we then reflect the point across this line, to obtain the new "rotated" point.

    complex-reflect.png

    We reflect the point p across the line l to obtain the point p', which equals a rotation of two times α.

    Now when we move to three dimensions, we can no longer use just a line to define the reflection, so enter the quaternion. We now have a point in 3D space, which we can envision lies on the surface of some sphere. We now construct a plane going through the origin, and we reflect this point on the sphere across this plane to "rotate" it.

    quaternion-reflect.png
     
  17. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    71
    @neginfinity well said. I know its been a few years since your post, but this is how everybody should be taught to look at quaternions. Most people overcomplicate the explanations, but this is a very simple and effective way to look at it. Cheers