GarageGames / Torque3D Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Euler to Quaternion conversion is incorrect #164
Comments
|
We'd welcome anybody making a pull-request with these changes! Ideally we'd have some unit tests as well ;). |
|
Just a note, the original code makes use of mSinCos which at least on x86 uses the fsincos instruction which in theory is faster than calling mSin & mCos separately. |
|
If I'm reading it right, translating it to stock would give: QuatF& QuatF::set( const EulerF & e ) // Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ] return *this; Bit beyond my personal comfort level though for throwing that out as a PR, since it's not math I'm heavily familiar with. |
|
I'm gonna work on this, and add some unit tests in my |
|
Okay, I'm writing unit tests for this using the following approach. I create an Currently it works if I expect the angle to be less than 1e-3. Is that too large a tolerance? I mean, that's 1/1000th of a radian... |
|
This fix is apparently good. Will need to fix existing logic that relies on this conversion (looking at you, |


It seems that using the set method for the QuatF object and passing it an EulerF it incorrectly converts. Somewhere an axis ends up being negative when it was positive. This doesn't happen when passing it an angle axis.
I didn't really change the existing code to fix it, because I didn't have time to look at it real close, but instead commented it out and just wrote my own based on(http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm):
// Assuming the angles are in radians.
F32 c1 = mCos(e.y/2.0f);
F32 s1 = mSin(e.y/2.0f);
F32 c2 = mCos(e.z/2.0f);
F32 s2 = mSin(e.z/2.0f);
F32 c3 = mCos(e.x/2.0f);
F32 s3 = mSin(e.x/2.0f);
F32 c1c2 = c1_c2;
F32 s1s2 = s1_s2;
w =c1c2_c3 - s1s2_s3;
x =c1c2_s3 + s1s2_c3;
y =s1_c2_c3 + c1_s2_s3;
z =c1_s2_c3 - s1_c2_s3;
That should fix it. Also I don't don't if there was originally a QuatD class, but I made one so if there is change it respectively there as well.
Once I figure out a workflow for submitting fixes on here I will start making these changes myself, but don't really have the time at work yet.
Also if you want something to test with just use this:
EulerF eRot(0.0f, -0.0f, 1.5707963267948966f);
QuatD rot(eRot);
You will notice rot has a negative 0.7071067811... which is incorrect, then if you use this:
EulerF eRot(0.0f, -0.0f, 1.5707963267948966f);
MatrixF mat(eRot);
AngAxisF aaRot(mat);
QuatD rot(aaRot);
you will get something like this: "0.00000000000000000 0.00000000000000000 0.70710678118654746 0.70710678118654757"
I was using doubles (F64) the entire time so that is why my values are huge.
The text was updated successfully, but these errors were encountered: