-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fixing rotation mat3 from euler bug #5202
Conversation
Thanks for the fix. Please update CHANGES.md and the unit tests. Please also run the unit tests locally to confirm in addition to the tests ran by CI. |
Specs/Core/Matrix3Spec.js
Outdated
var c3PiOver2 = Math.cos(CesiumMath.PI_OVER_TWO * 3); | ||
|
||
var headingPitchRoll = new HeadingPitchRoll(-CesiumMath.PI_OVER_TWO, -CesiumMath.PI, CesiumMath.PI_OVER_TWO * 3); | ||
var expected = new Matrix3(cPi * cPiOver2, -c3PiOver2 * sPiOver2 + s3PiOver2 * sPi * cPiOver2, s3PiOver2 * sPiOver2 + c3PiOver2 * sPi * cPiOver2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests written this way are generally not useful because it just simply copies the same math done in Matrix3.fromHeadingPitchRoll
. Most of the time there's a bug, it's because the bad math exists in both cases.
For cases like this, we prefer to use hardcoded known good values (usually created via a trusted source like STK Components, Matlab, or Wolfram Alpha. We then put a comment above the hardcoded values indicating where they are from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. Annoyingly, I couldn't find any decent euler to rot matrix conversion tools online to reference. Does a test like this, comparing to other conversion functions in the class, work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't think this approach is good either. It's still circular in that we're testing our own code against our own code. There may even be a chance that under the hood one of these are written in terms of the other (though I didn't check).
This test is also poor because it uses PI/2 and other "nice" values that can result in simple cases working fine but complicated cases being wrong. (I think some of the terms of the matrix end up being 0 for example).
Math unit tests like this should always contain hard numbers that have been validated to be correct either manually or via other trusted sources. I'll try and whip up a test case using STK Components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahwang give this a try:
it('fromHeadingPitchRoll computed correctly', function() {
// Expected generated via STK Components
var expected = new Matrix3(
0.754406506735489, 0.418940943945763, 0.505330889696038,
0.133022221559489, 0.656295369162553, -0.742685314912828,
-0.642787609686539, 0.627506871597133, 0.439385041770705);
var headingPitchRoll = new HeadingPitchRoll(-CesiumMath.toRadians(10), -CesiumMath.toRadians(40), CesiumMath.toRadians(55));
var result = new Matrix3();
var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. That makes sense. Thanks! Let me know if you don't have time to get to it for a while, I can always compute an ugly case manually. Manual matrix multiplication is painful, but will keep me strong. :)
Thanks @mramato ! This test is way better, and everything checks out. |
No problem, thanks again for fixing this. |
Fixes #5195. We noticed that using fromHeadingPitchRoll created subtle distortions.
I double, double checked @zimengyang 's fix (see here: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles)
We should probably update our tests too... I'll get on that.