[ODE] properly QuaternionToEuler

Eugen Lofing lofing at gmx.net
Tue Oct 18 16:05:57 MST 2005

```Hello alltogether!

I actually use for QuaternionToEuler-converting following algorithm

---------------------------------------------------------------------
dReal w, x, y, z;
w = quaternion[0];
x = quaternion[1];
y = quaternion[2];
z = quaternion[3];
double sqw = w * w;
double sqx = x * x;
double sqy = y * y;
double sqz = z * z;
float Z = (float) (atan2(2.0 * (x*y + z*w),(sqx - sqy - sqz + sqw)) *
// bank
float X = (float) (atan2(2.0 * (y*z + x*w),(-sqx - sqy + sqz + sqw)) *
// attitude
float Y = (float) (asin(-2.0 * (x*z - y*w)) * GRAD_PI);
---------------------------------------------------------------------

but it is buggy, because I have following ranges for Y (attitude):
0..90..0..-90..0
^              |
|______________|

instead of 0..360, or -180..180 like by X and Z :(

I assume there are 3 cases to differ by checking value of (x*z - y*w)

But I don't know how, nor have some formula..

Do somebody know?

Thank u for all hints and suggestions :)

--
Highspeed-Freiheit. Bei GMX supergünstig, z.B. GMX DSL_Cityflat,
DSL-Flatrate für nur 4,99 Euro/Monat*  http://www.gmx.net/de/go/dsl
```