Skip to content
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

HeadingPitchRoll.fromQuaternion clamps pitch asin #7654

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Change Log

##### Fixes :wrench:
* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624)
* Fixed `HeadingPitchRoll.pitch` being `NaN` when using `.fromQuaternion` do to a rounding error
for pitches close to +/- 90°. [#7654](https://github.com/AnalyticalGraphicsInc/cesium/pull/7654)

### 1.55 - 2019-03-01

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/HeadingPitchRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define([
var numeratorHeading = 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);
result.heading = -Math.atan2(numeratorHeading, denominatorHeading);
result.roll = Math.atan2(numeratorRoll, denominatorRoll);
result.pitch = -Math.asin(test);
result.pitch = -CesiumMath.asinClamped(test);
return result;
};

Expand Down
6 changes: 6 additions & 0 deletions Specs/Core/HeadingPitchRollSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ defineSuite([
}
});

it('it should return the correct pitch, even with a quaternion rounding error', function() {
var q = new Quaternion(8.801218199179452e-17, -0.7071067801637715, -8.801218315071006e-17, -0.7071067822093238);
var result = HeadingPitchRoll.fromQuaternion(q);
expect(result.pitch).toEqual(-(Math.PI / 2));
});

it('conversion from degrees', function() {
var testingTab = [
[0, 0, 0],
Expand Down