Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Transforms.fixedFrameToHeadingPitchRoll #7164

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log
##### Additions :tada:
* Shrink minified and gzipped Cesium.js by 27 KB (~3.7%) by delay loading seldom-used third-party dependencies. [#7140](https://github.com/AnalyticalGraphicsInc/cesium/pull/7140)
* Added WMS-T (time) support in WebMapServiceImageryProvider [#2581](https://github.com/AnalyticalGraphicsInc/cesium/issues/2581)
* Added `Transforms.fixedFrameToHeadingPitchRoll`, a helper function for extracting a `HeadingPitchRoll` from a fixed frame transform [#7164](https://github.com/AnalyticalGraphicsInc/cesium/pull/7164)
* Added `cutoutRectangle` to `ImageryLayer`, which allows cutting out rectangular areas in imagery layers to reveal underlying imagery. [#7056](https://github.com/AnalyticalGraphicsInc/cesium/pull/7056)

##### Fixes :wrench:
Expand Down
49 changes: 49 additions & 0 deletions Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define([
'./EarthOrientationParameters',
'./EarthOrientationParametersSample',
'./Ellipsoid',
'./HeadingPitchRoll',
'./Iau2006XysData',
'./Iau2006XysSample',
'./JulianDate',
Expand All @@ -32,6 +33,7 @@ define([
EarthOrientationParameters,
EarthOrientationParametersSample,
Ellipsoid,
HeadingPitchRoll,
Iau2006XysData,
Iau2006XysSample,
JulianDate,
Expand Down Expand Up @@ -377,6 +379,53 @@ define([
return Quaternion.fromRotationMatrix(rotation, result);
};

var noScale = new Cartesian3(1.0, 1.0, 1.0);
var hprCenterScratch = new Cartesian3();
var ffScratch = new Matrix4();
var hprTransformScratch = new Matrix4();
var hprRotationScratch = new Matrix3();
var hprQuaternionScratch = new Quaternion();
/**
* Computes heading-pitch-roll angles from a transform in a particular reference frame. Heading is the rotation from the local north
* direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles
* are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
*
* @param {Matrix4} transform The transform
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation
* matrix from a reference frame to the provided ellipsoid's fixed reference frame
* @param {HeadingPitchRoll} [result] The object onto which to store the result.
* @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if none was provided.
*/
Transforms.fixedFrameToHeadingPitchRoll = function(transform, ellipsoid, fixedFrameTransform, result) {
//>>includeStart('debug', pragmas.debug);
Check.defined('transform', transform);
//>>includeEnd('debug');

ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame);
if (!defined(result)) {
result = new HeadingPitchRoll();
}

var center = Matrix4.getTranslation(transform, hprCenterScratch);
if (Cartesian3.equals(center, Cartesian3.ZERO)) {
result.heading = 0;
result.pitch = 0;
result.roll = 0;
return result;
}
var toFixedFrame = Matrix4.inverseTransformation(fixedFrameTransform(center, ellipsoid, ffScratch), ffScratch);
var transformCopy = Matrix4.setScale(transform, noScale, hprTransformScratch);
transformCopy = Matrix4.setTranslation(transformCopy, Cartesian3.ZERO, transformCopy);

toFixedFrame = Matrix4.multiply(toFixedFrame, transformCopy, toFixedFrame);
var quaternionRotation = Quaternion.fromRotationMatrix(Matrix4.getRotation(toFixedFrame, hprRotationScratch), hprQuaternionScratch);
quaternionRotation = Quaternion.normalize(quaternionRotation, quaternionRotation);

return HeadingPitchRoll.fromQuaternion(quaternionRotation, result);
};

var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841;
var gmstConstant1 = 8640184.812866;
var gmstConstant2 = 0.093104;
Expand Down
17 changes: 17 additions & 0 deletions Specs/Core/TransformsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,23 @@ defineSuite([
expect(actualTranslation).toEqualEpsilon(expectedTranslation, CesiumMath.EPSILON14);
});

it('fixedFrameToHeadingPitchRoll returns heading/pitch/roll from a transform', function () {
var expected = new HeadingPitchRoll(0.5, 0.6, 0.7);

var transform = Transforms.eastNorthUpToFixedFrame(Cartesian3.fromDegrees(0, 0));
var transform2 = Matrix4.fromTranslationQuaternionRotationScale(new Cartesian3(), Quaternion.fromHeadingPitchRoll(expected), new Cartesian3(1, 1, 1));
transform = Matrix4.multiply(transform, transform2, transform2);

var actual = Transforms.fixedFrameToHeadingPitchRoll(transform);
expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON10);
});

it('fixedFrameToHeadingPitchRoll throws with no transform', function() {
expect(function() {
return Transforms.fixedFrameToHeadingPitchRoll();
}).toThrowDeveloperError();
});

it('eastNorthUpToFixedFrame throws without an origin', function() {
expect(function() {
Transforms.eastNorthUpToFixedFrame(undefined, Ellipsoid.WGS84);
Expand Down