diff --git a/CHANGES.md b/CHANGES.md index 50062ce6ea4f..1786e0ae26ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ - Changes the default `RequestScheduler.maximumRequestsPerServer` from 6 to 18. This should improve performance on HTTP/2 servers and above [#11627](https://github.com/CesiumGS/cesium/issues/11627) - Corrected JSDoc and Typescript definitions that marked optional arguments as required in `ImageryProvider` constructor [#11625](https://github.com/CesiumGS/cesium/issues/11625) +- The `Quaternion.computeAxis` function created an axis that was `(0,0,0)` for the unit quaternion, and an axis that was `(NaN,NaN,NaN)` for the quaternion `(0,0,0,-1)` (which describes a rotation about 360 degrees). Now, it returns the x-axis `(1,0,0)` in both of these cases. ### 1.112 - 2023-12-01 diff --git a/packages/engine/Source/Core/Quaternion.js b/packages/engine/Source/Core/Quaternion.js index b77cb770e1de..333e353b7816 100644 --- a/packages/engine/Source/Core/Quaternion.js +++ b/packages/engine/Source/Core/Quaternion.js @@ -677,8 +677,12 @@ Quaternion.computeAxis = function (quaternion, result) { //>>includeEnd('debug'); const w = quaternion.w; - if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) { - result.x = result.y = result.z = 0; + if ( + Math.abs(w - 1.0) < CesiumMath.EPSILON6 || + Math.abs(w + 1.0) < CesiumMath.EPSILON6 + ) { + result.x = 1; + result.y = result.z = 0; return result; } diff --git a/packages/engine/Specs/Core/QuaternionSpec.js b/packages/engine/Specs/Core/QuaternionSpec.js index fdf6ed9356d4..8bfc1730513c 100644 --- a/packages/engine/Specs/Core/QuaternionSpec.js +++ b/packages/engine/Specs/Core/QuaternionSpec.js @@ -449,8 +449,8 @@ describe("Core/Quaternion", function () { expect(result).toBe(returnedResult); }); - it("axis returns Cartesian3 0 when w equals 1.0", function () { - const expected = new Cartesian3(0.0, 0.0, 0.0); + it("axis returns Cartesian3 (1,0,0) when w equals 1.0", function () { + const expected = new Cartesian3(1.0, 0.0, 0.0); const quaternion = new Quaternion(4.0, 2.0, 3.0, 1.0); const result = new Cartesian3(1, 2, 3); const returnedResult = Quaternion.computeAxis(quaternion, result); @@ -458,6 +458,15 @@ describe("Core/Quaternion", function () { expect(result).toBe(returnedResult); }); + it("axis returns Cartesian3 (1,0,0) when w equals -1.0", function () { + const expected = new Cartesian3(1.0, 0.0, 0.0); + const quaternion = new Quaternion(4.0, 2.0, 3.0, -1.0); + const result = new Cartesian3(1, 2, 3); + const returnedResult = Quaternion.computeAxis(quaternion, result); + expect(returnedResult).toEqual(expected); + expect(result).toBe(returnedResult); + }); + it("angle works", function () { // 60 degrees is used here to ensure that the sine and cosine of the half angle are not equal. const angle = Math.PI / 3.0;