Thread: Euler Angles to Quaternions

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    46

    Euler Angles to Quaternions

    In 3d math primer they have two ways of converting euler angles to a quaternion, depending if we want a inertial-to-object or object-to-inertial quaternion. However in wikipedia they use a different conversion, but I don't yet understand the relation with the ones in 3d math primer. Does anyone has experience in this area that they can shed some light?

    Conversion between quaternions and Euler angles - Wikipedia, the free encyclopedia

    [3d math primer euler to quaternion equations in Google books]
    3D math primer for graphics and game ... - Google Books

    Thank you very much

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    As far as i know, a quaternion holds an axis and the amount of rotation to be made around it right?
    Then if you think about it, converting Euler angles to a quaternion is obsolette.
    Euler angles are, usually, used to represent full rotation, meaning that adding two different Euler angles, (X, Y, Z) and (x, y, z) to
    (X+x, Y+y, Z+z), makes no sense! ( Although many do this )
    Of course, from technical view, there's nothing wrong with doing that. But a quaternion, how to say this,
    isn't rotation around an axis, it's rotation speed around the axis. ( or at least i think it is! )
    Devoted my life to programming...

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Do you want a simple technique? Firstly take the angles and put them into a rotation matrix. Then use that matrix to multiply a vector that points down the negative z axis. Take the normalized cross product of the vector and the negative z axis and the enclosed angle between them ( the vector and the axis ). The cross product is the axis you want to rotate about and the enclosed angle is how much you want to rotate around it.
    Yes it may be more time consuming that others in some cases, but it's fairly simple to begin with!
    Devoted my life to programming...

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    While the 3D primer is a good book, you do have to keep in mind that they have drunk the DirectX koolaid and so all the math is done sideways and backwards. More specifically, they're using a left-handed coordinate system so the z-axis points the wrong way (and consequently there's going to be a negative sign to account for when dealing with z).

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    But OpenGL also points down the negative z axis...
    Devoted my life to programming...

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Oh, you meant the rotation direction!
    Hey i have a question. OpenGL uses row-major matrices and right-handed rotation.
    DirectX uses left-handed rotation but what kind of matrices? ( I've never used DirectX )
    Devoted my life to programming...

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Sipher View Post
    But OpenGL also points down the negative z axis...
    Um ... sure. "On screen" is negative z for OpenGL (the way it's meant to be) but positive z for DirectX.
    Quote Originally Posted by Sipher View Post
    Oh, you meant the rotation direction!
    Hey i have a question. OpenGL uses row-major matrices and right-handed rotation.
    DirectX uses left-handed rotation but what kind of matrices? ( I've never used DirectX )
    OpenGL expects column-major matrices, or at least they used to (haven't looked at the new and improved v4) -- see glMultMatrix for example. I don't remember what DirectX uses as matrix datatype. Someone will be along shortly who does, I expect. The column major matrices make a little bit of sense, since for a transformation the x-axis will transform to the first column vector, the y-axis to the second, etc.

  8. #8
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Its column-major you say?! That explains the logical errors i've been getting for a long time!!!! O_o...
    Devoted my life to programming...

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Direct3D uses LH matrices but it can be setup to use RH. OGL uses RH matrices but I suspect it can also be setup to use LH.

    You can convert a Euler angle rotation matrix to a quaternion and vice versa. I've never heard of converting a single Euler angle to a complete quaternion and it doesn't make much mathematical sense to me to try it. Quaternions represent rotations around an arbitrary axis very similar to the Euler axis-angle representation. The main difference is that quaternions can be interpoated easily. It is trivial to linearily interpolate between two quaternions as well as perform spherical quadrangle interpolation or squad. It is impossible to correctly linearily interpolate between two orientations represented by Euler angles.
    Last edited by VirtualAce; 05-21-2010 at 07:46 PM.

  10. #10
    Registered User
    Join Date
    Oct 2009
    Posts
    46
    Thanks for the replies guys. What I don't understand is the relation from the conversion in wikipedia and the ones in the book, because in the latter they make reference to object-to-inertial and inertial-to-object conversion.

    The conversion in the book and in wikipedia are different.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Project Euler Problem 14 Segfault
    By vincent01910 in forum C Programming
    Replies: 5
    Last Post: 11-04-2009, 05:56 AM
  2. Project Euler Solved but want help improving the code Newbie
    By whiterebbit in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2008, 07:00 AM
  3. OpenGL Rotation-- Part 2
    By satish.annauniv in forum Game Programming
    Replies: 9
    Last Post: 05-26-2008, 11:01 PM
  4. Quaternions
    By Lurker in forum Game Programming
    Replies: 9
    Last Post: 09-06-2003, 04:24 PM
  5. Need help with Reflecting Angles!
    By SRM in forum Game Programming
    Replies: 7
    Last Post: 05-15-2003, 04:11 PM