Getting Euler out of Quaternion after fixed bug.
Posted: Tue Apr 29, 2014 10:09 am
Ok, I am doing a little bit better now. I have taken your new code, and it broke my function that gets the Euler Angles back from the Quaternion. Your engine does not have a reverse function I think, but it is really needed for people that have to work with Euler. I experimented some, and here is what I got now:
This seems to be working mostly for me, however it does not have the special cases (that dont exist in my case). Maybe you can finish it up and put it into BEPU?
Code: Select all
public static Vector GetYPRFromQuaternion_OutRadians(Quaternion rotation)
{
Vector res = new Vector();
double q0 = rotation.W;
double q1 = rotation.Y;
double q2 = rotation.X;
double q3 = rotation.Z;
res.X = Math.Atan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1*q1 + q2*q2));
res.Y = Math.Asin(2 * (q0 * q2 - q3 * q1));
res.Z = Math.Atan2(2 * (q0 * q3 + q1 * q2), 1 - 2 * (q2 * q2 + q3*q3));
return res;
}