From 515851ecb82c1a66458ce938f36078670d4d7095 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Mar 2019 13:57:32 +0100 Subject: [PATCH 1/2] HeadingPitchRoll.fromQuaternion clamps pitch asin --- Source/Core/HeadingPitchRoll.js | 2 +- Specs/Core/HeadingPitchRollSpec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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], From 6892f16f5b28b44c83f6f2825bccc29affcffe8a Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Mar 2019 14:05:31 +0100 Subject: [PATCH 2/2] CHANGES.md --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) 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