Search Unity

Where to learn quaternion math?

Discussion in 'Scripting' started by GarthSmith, Jul 24, 2014.

  1. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    So I'm kinda bugged by the fact that I don't know what a quaternion is or how it represents a rotation. Wtf is that w component supposed to mean anyway?

    Can anyone point me to a tutorial on the math of a quaternion? The closest thing I can find is this Wikipedia article "Quaternions and Spatial Rotation". Does anyone else have books, pdfs, example problems, etc. to suggest?
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    I remember someone saying something like the w of a Quaternion corresponds with the z part of the axis of rotation
     
  3. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    I think they are supposed to be taught in calc 4. Naturally, I never got that far so I wouldn't know. I wouldn't recommend text books either since they are typically written by idiots who really don't know how to explain something.

    tl;dr: have looked, never found anything.
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    And that individual is sadly wrong.
    If you look at identity quaternion - no rotation, it is 0, 0, 0, 1.
    90 degrees in X; 0.7, 0, 0, 0.7
    90 degrees in Y; 0, 0.7, 0, 0.7
    90 degrees in Z; 0, 0, 0.7, 0.7

    From that... assume W is never 0? Wrong!
    180 degrees in X: 1, 0, 0, 0
    180 degrees in Y: 0, 1, 0, 0
    180 degrees in Z: 0, 0, 1, 0

    Well... sound easy, no?
    Let's try 45 degrees in all axis; 0.46, 0.19, 0.19, 0.84... wut?

    I gave up trying to understand what the inner value of a quaternion would be for a given rotation a long time ago.



    The problem with quaternion, is if you look at the values inside it, you won't get a freaking clue what it does. It's also why you will never have a quaternion constructor taking x/y/z/w as argument, it would be pointless. They represent a rotation, NOT an orientation, and while that distinction appear minor, it is a huge different.

    However, without knowing how those values comes up to be, quaternion still remains fairly easy to use! Their biggest use is to apply rotation on vectors or on other quaternion.
     
    Last edited: Jul 24, 2014
  5. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Yeah Quaternions are crazy and mysterious. Yet, looking at that Wikipedia article, there is obviously some reason why they perform the calculations they do to get something that represents "rotation".

    I'll go through the Wikipedia article and recalculate all the equations line-by-line if I have to, there's no other way I can absorb all that. I just feel like there's a math book out there somewhere that goes into more detail and might have a couple more diagrams and example problems.
     
    Last edited: Jul 24, 2014
  6. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Calc 4? Like Intro to Analysis or something? I've been trying to figure out what book would have this. Abstract algebra? Geometry? Some P.D.E. class I never took? I'll still take a text book over nothing. (There are even a couple text books that are quite good!)
     
  7. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    A quaternion uses complex numbers to represent rotation.

    The x,y,z parts are the complex numbers. By complex I mean they're imaginary. Because we know they're complex, we only store the scalar part of the complex number (i is imaginary, a complex number is ix + b, we store the x). The w component is the 'real' part of the complex number (the b in ix + b).

    In algebraic form we get:

    ix + iy + iz + w = 0

    Dude man who discovered them realized the proof that:

    i2 = j2 = k2 = ijk = −1
    (i,j,k are your complex parts ix, iy, iz)

    From here on out you need to be really well versed in some linear algebra and the sort to really grasp it. Quaternions in and of themselves are just a 4-dimensional number system. But they can be USED to represent 3-dimensional rotation.

    You don't really NEED to understand it to use it though. Getting into them is really a more academic process then a useful process.

    As long as you understand the rules of them, and allow the computer to do the actual arithmetic, they work.

    The main principal you got is that the quaternion stores as a complex number an axis and the rotation around that axis. The number system that the quaternion is though allows for simple appending of quaternions onto one another by multiplying one onto the other. Just remember that the multiplication is NOT commutative (the order of the operands is important). Because they're not commutative, division is slightly tricky, and must default to the definition of division (division is the product of the inverse).

    If you want to get into the actual meat of it and learn the math. Well, like a lot of linear algebra, it's all about building on the basic structure of the line. Remember in Algebra 1 you learn about slope-intercept form, y = mx + b. And that polynomials in their root for are really just that with degrees added onto them which really just append curvature to them.

    OK.

    Well note the root complex number is f(x) = ix + b. It's just slope-intercept with i as the slope.

    A quaternion is just a polynomial of a complex number.

    Just keep this in mind when learning complex numbers. The actual maths is based in simple algebra, just the numbers that result remain in complex space.
     
    Last edited: Jul 24, 2014
    Alverik likes this.
  8. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Don't really know. May want to make a trip to a used book store near a college/university and look for chapters in the ToC named quaternions. It's probably worth a shot.