Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Sep 27, 2017
1 parent 09e76ce commit bbe3c8f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 385 deletions.
4 changes: 2 additions & 2 deletions Source/Core/HeadingPitchRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ define([
var denominatorHeading = 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);
var numeratorHeading = 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);

result.heading = -Math.atan2(numeratorHeading, denominatorHeading);
result.heading = Math.atan2(numeratorHeading, denominatorHeading);
result.roll = Math.atan2(numeratorRoll, denominatorRoll);
result.pitch = -Math.asin(test);
result.pitch = Math.asin(test);

return result;
};
Expand Down
19 changes: 6 additions & 13 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,12 @@ define([

deprecationWarning('Matrix3.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.');

var cosTheta;
var cosPsi;
var cosPhi;
var sinTheta;
var sinPsi;
var sinPhi;

cosTheta = Math.cos(headingPitchRoll.pitch);
cosPsi = Math.cos(headingPitchRoll.heading);
cosPhi = Math.cos(headingPitchRoll.roll);
sinTheta = Math.sin(headingPitchRoll.pitch);
sinPsi = Math.sin(headingPitchRoll.heading);
sinPhi = Math.sin(headingPitchRoll.roll);
var cosTheta = Math.cos(headingPitchRoll.pitch);
var cosPsi = Math.cos(headingPitchRoll.heading);
var cosPhi = Math.cos(headingPitchRoll.roll);
var sinTheta = Math.sin(headingPitchRoll.pitch);
var sinPsi = Math.sin(headingPitchRoll.heading);
var sinPhi = Math.sin(headingPitchRoll.roll);

var m00 = cosTheta * cosPsi;
var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ define([
deprecationWarning('Quaternion.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.');

scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion);
scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result);
scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, headingPitchRoll.pitch, result);
result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion);
scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -headingPitchRoll.heading, scratchHPRQuaternion);
scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, headingPitchRoll.heading, scratchHPRQuaternion);

return Quaternion.multiply(scratchHeadingQuaternion, result, result);
};
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ define([

fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame);

Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion);
var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion);

var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, scratchHPRQuaternion, scratchScale, scratchHPRMatrix4);
var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4);
result = fixedFrameTransform(origin, ellipsoid, result);
return Matrix4.multiply(result, hprMatrix, result);
};
Expand Down Expand Up @@ -383,7 +383,9 @@ define([
scratchENUMatrix4 = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4);
Matrix4.getRotation(scratchENUMatrix4, scratchHPRMatrix3);

return Quaternion.fromRotationMatrix(scratchHPRMatrix3, result);
var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4);
var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3);
return Quaternion.fromRotationMatrix(rotation, result);
};

var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841;
Expand Down
26 changes: 0 additions & 26 deletions Specs/Core/HeadingPitchRollSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,6 @@ defineSuite([
}
});

it('conversion from quaternion', function() {
var testingTab = [
[0, 0, 0],
[90 * deg2rad, 0, 0],
[-90 * deg2rad, 0, 0],
[0, 89 * deg2rad, 0],
[0, -89 * deg2rad, 0],
[0, 0, 90 * deg2rad],
[0, 0, -90 * deg2rad],
[30 * deg2rad, 30 * deg2rad, 30 * deg2rad],
[-30 * deg2rad, -30 * deg2rad, 45 * deg2rad]
];
var hpr = new HeadingPitchRoll();
for (var i = 0; i < testingTab.length; i++) {
var init = testingTab[i];
hpr.heading = init[0];
hpr.pitch = init[1];
hpr.roll = init[2];

var result = HeadingPitchRoll.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true), undefined, true);
expect(init[0]).toEqualEpsilon(result.heading, CesiumMath.EPSILON11);
expect(init[1]).toEqualEpsilon(result.pitch, CesiumMath.EPSILON11);
expect(init[2]).toEqualEpsilon(result.roll, CesiumMath.EPSILON11);
}
});

it('conversion from degrees', function() {
var testingTab = [
[0, 0, 0],
Expand Down
47 changes: 1 addition & 46 deletions Specs/Core/Matrix3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,51 +147,6 @@ defineSuite([
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('fromHeadingPitchRoll computed correctly', function() {
// Expected generated via STK Components
var expected = new Matrix3(
0.754406506735489, 0.418940943945763, 0.505330889696038,
0.133022221559489, 0.656295369162553, -0.742685314912828,
-0.642787609686539, 0.627506871597133, 0.439385041770705);

var headingPitchRoll = new HeadingPitchRoll(-CesiumMath.toRadians(10), -CesiumMath.toRadians(40), CesiumMath.toRadians(55));
var result = new Matrix3();
var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('fromHeadingPitchRoll works without a result parameter', function() {
var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR);
var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR);
var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO);
var cPiOver2 = Math.cos(CesiumMath.PI_OVER_TWO);

var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3());
var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4);
var headingPitchRoll = HeadingPitchRoll.fromQuaternion(quaternion, undefined, true);
var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0);

var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, undefined, true);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('fromHeadingPitchRoll works with a result parameter', function() {
var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR);
var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR);
var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO);
var cPiOver2 = Math.cos(CesiumMath.PI_OVER_TWO);

var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3());
var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4);
var headingPitchRoll = HeadingPitchRoll.fromQuaternion(quaternion, undefined, true);
var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0);
var result = new Matrix3();
var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result, true);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});

it('fromHeadingPitchRoll computed correctly', function() {
// Expected generated via STK Components
var expected = new Matrix3(
Expand All @@ -201,7 +156,7 @@ defineSuite([

var headingPitchRoll = new HeadingPitchRoll(CesiumMath.toRadians(10), CesiumMath.toRadians(40), CesiumMath.toRadians(55));
var result = new Matrix3();
var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result, true);
var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15);
});
Expand Down
65 changes: 6 additions & 59 deletions Specs/Core/QuaternionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ defineSuite([
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(angle, 0.0, 0.0);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(-angle), CesiumMath.EPSILON11);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11);
});

it('fromHeadingPitchRoll with just pitch', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(0.0, angle, 0.0);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(-angle), CesiumMath.EPSILON11);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11);
});

it('fromHeadingPitchRoll with just roll', function() {
Expand All @@ -130,81 +130,28 @@ defineSuite([
var hpr = new HeadingPitchRoll( angle, angle, angle);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr);
var expected = Matrix3.fromRotationX(angle);
Matrix3.multiply(Matrix3.fromRotationY(-angle), expected, expected);
Matrix3.multiply(Matrix3.fromRotationZ(-angle), expected, expected);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11);
});

it('fromHeadingPitchRoll with all angles (2)', function() {
var heading = CesiumMath.toRadians(180.0);
var pitch = CesiumMath.toRadians(-45.0);
var roll = CesiumMath.toRadians(45.0);
var hpr = new HeadingPitchRoll( heading, pitch, roll);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr);
var expected = Matrix3.fromRotationX(roll);
Matrix3.multiply(Matrix3.fromRotationY(-pitch), expected, expected);
Matrix3.multiply(Matrix3.fromRotationZ(-heading), expected, expected);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11);
});

it('fromHeadingPitchRoll works with result parameter', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(0.0, 0.0, angle);
var result = new Quaternion();
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, result);
var expected = Quaternion.fromRotationMatrix(Matrix3.fromRotationX(angle));
expect(quaternion).toBe(result);
expect(quaternion).toEqualEpsilon(expected, CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll with just heading', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(angle, 0.0, 0.0);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll with just pitch', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(0.0, angle, 0.0);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll with just roll', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll( 0.0, 0.0, angle);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationX(angle), CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll with all angles (1)', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll( angle, angle, angle);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true);
var expected = Matrix3.fromRotationX(angle);
Matrix3.multiply(Matrix3.fromRotationY(angle), expected, expected);
Matrix3.multiply(Matrix3.fromRotationZ(angle), expected, expected);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll with all angles (2)', function() {
it('fromHeadingPitchRoll with all angles (2)', function() {
var heading = CesiumMath.toRadians(180.0);
var pitch = CesiumMath.toRadians(-45.0);
var roll = CesiumMath.toRadians(45.0);
var hpr = new HeadingPitchRoll( heading, pitch, roll);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr);
var expected = Matrix3.fromRotationX(roll);
Matrix3.multiply(Matrix3.fromRotationY(pitch), expected, expected);
Matrix3.multiply(Matrix3.fromRotationZ(heading), expected, expected);
expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11);
});

it('fromDirectHeadingPitchRoll works with result parameter', function() {
it('fromHeadingPitchRoll works with result parameter', function() {
var angle = CesiumMath.toRadians(20.0);
var hpr = new HeadingPitchRoll(0.0, 0.0, angle);
var result = new Quaternion();
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, result, true);
var quaternion = Quaternion.fromHeadingPitchRoll(hpr, result);
var expected = Quaternion.fromRotationMatrix(Matrix3.fromRotationX(angle));
expect(quaternion).toBe(result);
expect(quaternion).toEqualEpsilon(expected, CesiumMath.EPSILON11);
Expand Down
Loading

0 comments on commit bbe3c8f

Please sign in to comment.