# Thread: Euler Angles to Quaternions

1. ## 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. 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! )

3. 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!

4. 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. But OpenGL also points down the negative z axis...

6. 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 )

7. Originally Posted by Sipher
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.
Originally Posted by Sipher
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. Its column-major you say?! That explains the logical errors i've been getting for a long time!!!! O_o...

9. 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.

10. 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.