Skip to content

Commit

Permalink
Merge pull request #8934 from easternmotors/master
Browse files Browse the repository at this point in the history
Exposing Transforms.rotationMatrixFromPositionVelocity
  • Loading branch information
mramato authored Jun 8, 2020
2 parents e951c03 + 9741f4b commit ac7be10
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 7 additions & 1 deletion Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions Specs/Core/TransformsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ac7be10

Please sign in to comment.