Getting Euler out of Quaternion after fixed bug.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
skyflashde
Posts: 5
Joined: Mon Apr 28, 2014 8:29 am

Getting Euler out of Quaternion after fixed bug.

Post by skyflashde »

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:

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;
        }
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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Getting Euler out of Quaternion after fixed bug.

Post by Norbo »

I hesitate to add a to-Euler function:
1) XNA didn't have it, so there's no expectation in ported code.
2) It's not used anywhere in the engine or in any related code, and I lean towards not adding code when it does not have a core usage.
3) This is the first explicit request for it in relation to BEPUphysics that I am aware of.
4) Its existence would encourage the use of Euler/Tait-Bryan angles, and I'm on a crusade against them. :)
5) It's easy enough to find an implementation in the cases where it's truly necessary for interfacing with other code which only handles yaw/pitch/roll.

So, I would recommend just using your snippet if it does what you need for now. I may still add it in one day if some of the above conditions change.
Post Reply