[ODE] properly QuaternionToEuler

Bill Sellers wis at mac.com
Tue Oct 18 15:56:10 MST 2005


There's a really good description of just this problem and some code  
to solve it at:

http://vered.rose.utoronto.ca/people/david_dir/GEMS/GEMS.html

Just decide which of the 24 different types of Euler angles you want  
(I think only 2 are actually commonly used) and watch the order of  
the quaternions (it uses X, Y, Z, W).

Cheers
Bill

On 18 Oct 2005, at 15:05, Eugen Lofing wrote:

> 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;
>     // heading
>     float Z = (float) (atan2(2.0 * (x*y + z*w),(sqx - sqy - sqz +  
> sqw)) *
> GRAD_PI);
>     // bank
>     float X = (float) (atan2(2.0 * (y*z + x*w),(-sqx - sqy + sqz +  
> sqw)) *
> GRAD_PI);
>     // 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
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
>




More information about the ODE mailing list