diff --git a/CHANGES.md b/CHANGES.md index a328b9eabd67..684205004fc8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index b934f6d04f3e..1fd9f692aaa6 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -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; }; diff --git a/Specs/Core/HeadingPitchRollSpec.js b/Specs/Core/HeadingPitchRollSpec.js index 81d2aefb856b..4569f75ac38c 100644 --- a/Specs/Core/HeadingPitchRollSpec.js +++ b/Specs/Core/HeadingPitchRollSpec.js @@ -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],