1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Rotations in 3D space

  1. Sep 24, 2013 #1
    Hey there,
    I have a question regarding quaternions and rotations. It's related to 3D graphics programming, but nevertheless I'm sure the physics forum is the right place for my question.

    As far as I've understood there are 3 primary ways we can store rotation: euler angles, quaternions and matrices. In 3D graphics programming, quaternions are often the preferred way because they need less memory than matrices but avoid gimbal lock.

    To represent a 3D object with euler angles I just need 3 components: x, y and z, which each represent the angle around an axis.

    Now, how many quaternions are needed to store a rotation? To my knowledge a quaternion stores an axis and the amount of rotation - so I'd need 3 quaternions to store a rotation - is that right? That would be 3 (quaternions) x 4 (values) = 12 values to be stored. To store a rotation in a matrix I would need 3 x 3 = 9 values, which is even less. So why not just use matrices? Why do quaternions need less values/memory than matrices? Do I really need 3 quaternions to represent a rotation?

    Greetings!
     
  2. jcsd
  3. Sep 24, 2013 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    For some reason, you're getting things mixed up.

    Matrices ARE used to do coordinate rotations, even in 3D graphics programming. They are an efficient way not only of storing data, but computer hardware is specially designed to process them faster than regular data streams.

    Quaternions have representations in matrix form, just like complex numbers.

    To accommodate rotations and translations in 3D, 4x4 matrices are used, as illustrated in this article:
    http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/ [Broken]
     
    Last edited by a moderator: May 6, 2017
  4. Sep 24, 2013 #3
    Thanks for your answer!

    How do you mean that? A quaternion can be represented by a matrix?

    I know that OpenGL and other graphics APIs work with 4x4 matrices internally, however, frameworks built around these APIs often implement Quaternions for rotation and transform them to rotation matrices when needed. (At least this is the way I understood it, feel free to correct me if I'm wrong).

    I'm really curious about how many quaternions I need to store for a rotation. I mean, i have 3 axes, but this doesn't mean that I need 3 quaternions, does it?
     
  5. Sep 24, 2013 #4

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    A 2x2 matrix. Computer implementations? Probably not. Almost definitely not. Much more likely is as a 4 vector, or as a scalar (the real part) plus a three vector (the imaginary, or quaternionic part).

    Those 4x4 matrices -- here are some appropriate adjectives. Ugly. Inefficient. Kludge. Don't go there.

    Only one is needed. No matter how many times you turn an object, you can always find a single axis and rotation angle that completely describes the orientation of that object in three dimensional space. Always. It's the Euler rotation theorem. Note: This theorem does not apply to four dimensional space and higher. It's special to two and three dimensional space.

    There are a lot of ways to represent rotations in three dimensional space. One approach is via 3x3 orthogonal matrices. This approach generalizes to any dimension. Rotations in four dimensional space are described by a 4x4 orthogonal matrix, in five dimensional space, a 5x5 orthogonal matrix, and so on. There's one big drawback to the matrix approach: There are a lot more numbers in the matrix than there are degrees of freedom. A 3x3 matrix contains nine numbers, but there are only three degrees of freedom in rotations in three dimensional space. Only three numbers are needed. A quaternion has four elements, so there's a slight bit of over-specification here. A 3x3 matrix has nine elements. That's not just over-specification. It's overkill.

    One way to represent rotations in three dimensional space is via that single axis orientation. You need a unit vector and an angle. Multiply each element of the unit vector by the angle and you have just what is needed, three parameters that fully describe the orientation of an object. Unfortunately, this single axis rotation vector is hard to use and even harder to manipulate. (What happens if an object rotates about this axis by this number of radians, then about that axis by that number of radians? Good luck describing this with that three element single axis rotation representation. It can be done, but it is a mathematical nightmare.)

    Unit quaternions are very closely allied with this single axis rotation, only now the mathematics are much better behaved. That problem of rotating about this axis, then that axis? This becomes a product of two quaternions. Any sequence of rotations is a product of unit quaternions.
     
  6. Sep 25, 2013 #5
    Obviously quaternions can be represented by a 4 vector (not a matrix).

    When SteamKing mentioned “Quaternions have representations in matrix form”, I believe he meant that a rotation matrix can be constructed using the elements of a quaternion.
     
  7. Sep 25, 2013 #6

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    One somewhat common representation of quaternions is as 2x2 complex matrices. Physicists use this scheme a lot; the Pauli spin matrices are isomorphic to the quaternions.
     
  8. Sep 25, 2013 #7
    Thank you so much for this excellent explanation!

    This was the point I was unsure about - being able to represent every rotation with ONE quaternion is a reason to not use matrices. I'm already trying to implement a quaternion functionality and hope that I won't encounter any problems.
     
  9. Sep 25, 2013 #8

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    This is not an advantage of quaternions over matrices. The exact same thing applies to matrices. Every rotation can be represented by a single matrix.
     
  10. Sep 25, 2013 #9
    There is no reason to implement that. Use an existing library. For that matter, do not sweat over matrices/quaternions - use whatever 3D rotation library works for you. As long as it works, leave it alone. Premature optimization is the root of all evil.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Rotations in 3D space
Loading...