Skip to content

Commit

Permalink
Merge pull request #7654 from virtualcitySYSTEMS/fix-useClampedAsin
Browse files Browse the repository at this point in the history
HeadingPitchRoll.fromQuaternion clamps pitch asin
  • Loading branch information
Hannah authored Mar 15, 2019
2 parents 5cbb5e5 + 6892f16 commit fe60ac8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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

0 comments on commit fe60ac8

Please sign in to comment.