diff --git a/CHANGES.md b/CHANGES.md index 30a8d0fe7659..d88ad1932e84 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ##### Additions :tada: - Add a `toString` method to the `Resource` class in case an instance gets logged as a string. [#8722](https://github.com/CesiumGS/cesium/issues/8722) +- Exposed `Transforms.rotationMatrixFromPositionVelocity` method from Cesium's private API. [#8927](https://github.com/CesiumGS/cesium/issues/8927) ##### Fixes :wrench: diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0931d07284a2..6ae54b3cef30 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -262,3 +262,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu - [Edvinas Pranka](https://github.com/epranka) - [James Bromwell](https://github.com/thw0rted) - [Brandon Nguyen](https://github.com/bn-dignitas) +- [John Remsberg](https://github.com/easternmotors) diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 26e7f715435f..be3f81aeff49 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -949,7 +949,13 @@ var rightScratch = new Cartesian3(); var upScratch = new Cartesian3(); /** - * @private + * Transform a position and velocity to a rotation matrix. + * + * @param {Cartesian3} position The position to transform. + * @param {Cartesian3} velocity The velocity vector to transform. + * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation. + * @param {Matrix3} [result] The object onto which to store the result. + * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided. */ Transforms.rotationMatrixFromPositionVelocity = function ( position, diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index fdcb883fb128..7abad2f543dd 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -1716,6 +1716,59 @@ describe("Core/Transforms", function () { expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON12); }); + it("rotationMatrixFromPositionVelocity works without a result parameter", function () { + var matrix = Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_X, + Cartesian3.UNIT_Y + ); + var expected = new Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0); + expect(matrix).toEqualEpsilon(expected, CesiumMath.EPSILON14); + + matrix = Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_X, + Cartesian3.UNIT_Z + ); + expected = new Matrix3(0, 0, 1, 0, -1, 0, 1, 0, 0); + expect(matrix).toEqualEpsilon(expected, CesiumMath.EPSILON14); + + matrix = Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_Y, + Cartesian3.UNIT_Z + ); + expected = new Matrix3(0, 1, 0, 0, 0, 1, 1, 0, 0); + expect(matrix).toEqualEpsilon(expected, CesiumMath.EPSILON14); + }); + + it("rotationMatrixFromPositionVelocity works with a result parameter", function () { + var result = new Matrix3(); + Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_X, + Cartesian3.UNIT_Y, + Ellipsoid.WGS84, + result + ); + var expected = new Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0); + expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON14); + + Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_X, + Cartesian3.UNIT_Z, + Ellipsoid.WGS84, + result + ); + expected = new Matrix3(0, 0, 1, 0, -1, 0, 1, 0, 0); + expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON14); + + Transforms.rotationMatrixFromPositionVelocity( + Cartesian3.UNIT_Y, + Cartesian3.UNIT_Z, + Ellipsoid.WGS84, + result + ); + expected = new Matrix3(0, 1, 0, 0, 0, 1, 1, 0, 0); + expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON14); + }); + it("basisTo2D projects translation", function () { var ellipsoid = Ellipsoid.WGS84; var projection = new GeographicProjection(ellipsoid);