@itwin/core-geometry 4.4.0-dev.18 → 4.4.0-dev.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -123,11 +123,13 @@ export declare class YawPitchRollAngles {
123
123
  angles: YawPitchRollAngles | undefined;
124
124
  };
125
125
  /**
126
- * Attempts to create a YawPitchRollAngles object from a Matrix3d
127
- * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
128
- * * In the failure case the method's return value is `undefined`.
129
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
130
- * a set of angles.
126
+ * Attempts to create a YawPitchRollAngles object from a Matrix3d.
127
+ * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and
128
+ * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].
129
+ * @param result optional pre-allocated object to populate and return.
130
+ * @returns computed angles, or undefined if `matrix` is not rigid.
131
+ * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:
132
+ * their usefulness decreases the further `matrix` is from being rigid.
131
133
  */
132
134
  static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined;
133
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"YawPitchRollAngles.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAY,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,gBAAgB;IAChB,GAAG,CAAC,EAAE,UAAU,CAAC;I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kBAAkB,GAAG,SAAS,CAAC;KACxC;IAMD;;;;;;;;OAQG;WACW,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS;CA0EhH"}
@@ -205,11 +205,13 @@ class YawPitchRollAngles {
205
205
  };
206
206
  }
207
207
  /**
208
- * Attempts to create a YawPitchRollAngles object from a Matrix3d
209
- * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
210
- * * In the failure case the method's return value is `undefined`.
211
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
212
- * a set of angles.
208
+ * Attempts to create a YawPitchRollAngles object from a Matrix3d.
209
+ * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and
210
+ * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].
211
+ * @param result optional pre-allocated object to populate and return.
212
+ * @returns computed angles, or undefined if `matrix` is not rigid.
213
+ * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:
214
+ * their usefulness decreases the further `matrix` is from being rigid.
213
215
  */
214
216
  static createFromMatrix3d(matrix, result) {
215
217
  /**
@@ -287,7 +289,7 @@ class YawPitchRollAngles {
287
289
  }
288
290
  // sanity check
289
291
  const matrix1 = angles.toMatrix3d();
290
- return matrix.maxDiff(matrix1) < Geometry_1.Geometry.smallAngleRadians ? angles : undefined;
292
+ return matrix.isAlmostEqual(matrix1) ? angles : undefined;
291
293
  }
292
294
  }
293
295
  exports.YawPitchRollAngles = YawPitchRollAngles;
@@ -1 +1 @@
1
- {"version":3,"file":"YawPitchRollAngles.js","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,0CAAmD;AACnD,mCAAgC;AAChC,yCAAsC;AACtC,uDAA4C;AAkB5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,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W,EAAE;gBAChD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;iBAAM;gBACL,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACtC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACtC,IAAI,IAAI,IAAI,IAAI,EAAE;oBAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;iBACtB;qBAAM;oBACL,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;iBACtB;aACF;SACF;QACD,eAAe;QACf,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,mBAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,CAAC;CACF;AAjSD,gDAiSC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { AngleProps, Geometry } from \"../Geometry\";\r\nimport { Angle } from \"./Angle\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d } from \"./Point3dVector3d\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n// cspell:word Tait\r\n\r\n/**\r\n * Angle properties of a `YawPitchRoll` orientation\r\n * @public\r\n */\r\nexport interface YawPitchRollProps {\r\n /** yaw field */\r\n yaw?: AngleProps;\r\n /** pitch field */\r\n pitch?: AngleProps;\r\n /** roll field */\r\n roll?: AngleProps;\r\n}\r\n\r\n/**\r\n * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]\r\n * (https://en.wikipedia.org/wiki/Euler_angles).\r\n * * The matrix construction can be replicated by this logic:\r\n * * xyz coordinates have\r\n * * x forward\r\n * * y to left\r\n * * z up\r\n * * Note that this is a right handed coordinate system.\r\n * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):\r\n * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`\r\n * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):\r\n * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`\r\n * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):\r\n * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`\r\n * * The YPR matrix is the product\r\n * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`\r\n * * Note that this is for \"column based\" matrix with vectors multiplying on the right of the matrix.\r\n * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in\r\n * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.\r\n * @public\r\n */\r\nexport class YawPitchRollAngles {\r\n /** The yaw angle: counterclockwise rotation angle around z */\r\n public yaw: Angle;\r\n /** The pitch angle: **clockwise** rotation angle around y */\r\n public pitch: Angle;\r\n /** The roll angle: counterclockwise rotation angle around x */\r\n public roll: Angle;\r\n /**\r\n * Constructor\r\n * @param yaw counterclockwise rotation angle around z\r\n * @param pitch **clockwise** rotation angle around y\r\n * @param roll counterclockwise rotation angle around x\r\n */\r\n constructor(yaw: Angle = Angle.zero(), pitch: Angle = Angle.zero(), roll: Angle = Angle.zero()) {\r\n this.yaw = yaw;\r\n this.pitch = pitch;\r\n this.roll = roll;\r\n }\r\n /** Freeze this YawPitchRollAngles */\r\n public freeze(): Readonly<this> {\r\n this.yaw.freeze();\r\n this.pitch.freeze();\r\n this.roll.freeze();\r\n return Object.freeze(this);\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in degrees.\r\n * @param yawDegrees counterclockwise rotation angle (in degrees) around z\r\n * @param pitchDegrees **clockwise** rotation angle (in degrees) around y\r\n * @param rollDegrees counterclockwise rotation angle (in degrees) around x\r\n */\r\n public static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createDegrees(yawDegrees),\r\n Angle.createDegrees(pitchDegrees),\r\n Angle.createDegrees(rollDegrees),\r\n );\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in radians.\r\n * @param yawRadians counterclockwise rotation angle (in radians) around z\r\n * @param pitchRadians **clockwise** rotation angle (in radians) around y\r\n * @param rollRadians counterclockwise rotation angle (in radians) around x\r\n */\r\n public static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createRadians(yawRadians),\r\n Angle.createRadians(pitchRadians),\r\n Angle.createRadians(rollRadians),\r\n );\r\n }\r\n /** Construct a `YawPitchRoll` object from an object with 3 named angles */\r\n public static fromJSON(json?: YawPitchRollProps): YawPitchRollAngles {\r\n json = json ? json : {};\r\n return new YawPitchRollAngles(\r\n Angle.fromJSON(json.yaw),\r\n Angle.fromJSON(json.pitch),\r\n Angle.fromJSON(json.roll),\r\n );\r\n }\r\n /** Populate yaw, pitch and roll fields using `Angle.fromJSON` */\r\n public setFromJSON(json?: YawPitchRollProps): void {\r\n json = json ? json : {};\r\n this.yaw = Angle.fromJSON(json.yaw);\r\n this.pitch = Angle.fromJSON(json.pitch);\r\n this.roll = Angle.fromJSON(json.roll);\r\n }\r\n /**\r\n * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.\r\n * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.\r\n */\r\n public toJSON(): YawPitchRollProps {\r\n const val: YawPitchRollProps = {};\r\n if (!this.pitch.isAlmostZero)\r\n val.pitch = this.pitch.toJSON();\r\n if (!this.roll.isAlmostZero)\r\n val.roll = this.roll.toJSON();\r\n if (!this.yaw.isAlmostZero)\r\n val.yaw = this.yaw.toJSON();\r\n return val;\r\n }\r\n /**\r\n * Install all rotations from `other` into `this`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public setFrom(other: YawPitchRollAngles) {\r\n this.yaw.setFrom(other.yaw);\r\n this.pitch.setFrom(other.pitch);\r\n this.roll.setFrom(other.roll);\r\n }\r\n /**\r\n * Compare angles between `this` and `other`.\r\n * * Comparisons are via `isAlmostEqualAllowPeriodShift`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public isAlmostEqual(other: YawPitchRollAngles) {\r\n return this.yaw.isAlmostEqualAllowPeriodShift(other.yaw)\r\n && this.pitch.isAlmostEqualAllowPeriodShift(other.pitch)\r\n && this.roll.isAlmostEqualAllowPeriodShift(other.roll);\r\n }\r\n /** Make a copy of this YawPitchRollAngles */\r\n public clone() {\r\n return new YawPitchRollAngles(\r\n this.yaw.clone(),\r\n this.pitch.clone(),\r\n this.roll.clone(),\r\n );\r\n }\r\n /**\r\n * Expand the angles into a (rigid rotation) matrix.\r\n * * The returned matrix is \"rigid\" (i.e., it has unit length rows and columns, and its transpose is its inverse).\r\n * * The rigid matrix is always a right handed coordinate system.\r\n * @param result optional pre-allocated `Matrix3d`\r\n */\r\n public toMatrix3d(result?: Matrix3d) {\r\n const cz = Math.cos(this.yaw.radians);\r\n const sz = Math.sin(this.yaw.radians);\r\n const cy = Math.cos(this.pitch.radians);\r\n const sy = Math.sin(this.pitch.radians);\r\n const cx = Math.cos(this.roll.radians);\r\n const sx = Math.sin(this.roll.radians);\r\n /**\r\n * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where\r\n * rX, rY, and rZ are base rotation matrixes:\r\n *\r\n * const rX = Matrix3d.createRowValues(\r\n * 1, 0, 0,\r\n * 0, Math.cos(x), -Math.sin(x),\r\n * 0, Math.sin(x), Math.cos(x),\r\n * );\r\n * const rY = Matrix3d.createRowValues(\r\n * Math.cos(y), 0, Math.sin(y),\r\n * 0, 1, 0,\r\n * -Math.sin(y), 0, Math.cos(y),\r\n * );\r\n * const rZ = Matrix3d.createRowValues(\r\n * Math.cos(z), -Math.sin(z), 0,\r\n * Math.sin(z), Math.cos(z), 0,\r\n * 0, 0, 1,\r\n * );\r\n *\r\n * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you\r\n * can use transpose of rY in the matrix multiplication to get the same result)\r\n */\r\n return Matrix3d.createRowValues(\r\n cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n sy, cy * sx, cy * cx,\r\n result,\r\n );\r\n }\r\n /**\r\n * Returns true if this rotation does nothing.\r\n * * If allowPeriodShift is false, any nonzero angle is considered a non-identity\r\n * * If allowPeriodShift is true, all angles are individually allowed to be any multiple of 360 degrees.\r\n */\r\n public isIdentity(allowPeriodShift: boolean = true): boolean {\r\n if (allowPeriodShift)\r\n return Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.roll.radians);\r\n else\r\n return Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);\r\n }\r\n /** Return the largest angle in radians */\r\n public maxAbsRadians(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the sum of the angles in squared radians */\r\n public sumSquaredRadians(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the largest difference of angles (in radians) between this and other */\r\n public maxDiffRadians(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.radians - other.yaw.radians,\r\n this.pitch.radians - other.pitch.radians,\r\n this.roll.radians - other.roll.radians,\r\n );\r\n }\r\n /** Return the largest angle in degrees. */\r\n public maxAbsDegrees(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the sum of squared angles in degrees. */\r\n public sumSquaredDegrees(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the largest difference of angles (in degrees) between this and other */\r\n public maxDiffDegrees(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.degrees - other.yaw.degrees,\r\n this.pitch.degrees - other.pitch.degrees,\r\n this.roll.degrees - other.roll.degrees,\r\n );\r\n }\r\n /** Return an object from a Transform as an origin and YawPitchRollAngles. */\r\n public static tryFromTransform(transform: Transform): {\r\n origin: Point3d;\r\n angles: YawPitchRollAngles | undefined;\r\n } {\r\n return {\r\n origin: Point3d.createFrom(transform.origin),\r\n angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),\r\n };\r\n }\r\n /**\r\n * Attempts to create a YawPitchRollAngles object from a Matrix3d\r\n * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)\r\n * * In the failure case the method's return value is `undefined`.\r\n * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with\r\n * a set of angles.\r\n */\r\n public static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined {\r\n /**\r\n * The rotation matrix form is\r\n *\r\n * Matrix3d.createRowValues(\r\n * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n * sy, cy * sx, cy * cx\r\n * );\r\n *\r\n * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)\r\n */\r\n const sy = matrix.at(2, 0); // sin(y)\r\n const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|\r\n const pitchA = Angle.createAtan2(sy, cy); // with positive cosine\r\n const pitchB = Angle.createAtan2(sy, -cy); // with negative cosine\r\n const angles = result ? result : new YawPitchRollAngles();\r\n /**\r\n * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.\r\n * This means x and z can be anything as long as their sum x + z is constant.\r\n * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).\r\n * Math details can be found\r\n * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles\r\n *\r\n * The rotation matrix for y = +-90 degrees and x = 0 becomes\r\n *\r\n * Matrix3d.createRowValues(\r\n * 0, -sz, -+cz,\r\n * 0, cz, -+sz,\r\n * +-1, 0, 0\r\n * );\r\n *\r\n * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))\r\n */\r\n if (cy < Geometry.smallAngleRadians) {\r\n angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));\r\n angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.\r\n angles.roll = Angle.createRadians(0.0);\r\n } else {\r\n /**\r\n * positive cosine\r\n * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))\r\n * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))\r\n */\r\n const yawA = Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));\r\n const rollA = Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));\r\n // similar with negative cosine\r\n const yawB = Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));\r\n const rollB = Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));\r\n // create YPR\r\n const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);\r\n const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);\r\n // decide to pick yprA or yprB with smallest magnitude angles\r\n const absFactor = 0.95;\r\n const maxRadiansA = yprA.maxAbsRadians();\r\n const maxRadiansB = yprB.maxAbsRadians();\r\n if (maxRadiansA < absFactor * maxRadiansB) {\r\n angles.setFrom(yprA);\r\n } else if (maxRadiansB < absFactor * maxRadiansA) {\r\n angles.setFrom(yprB);\r\n } else {\r\n const sumA = yprA.sumSquaredRadians();\r\n const sumB = yprB.sumSquaredRadians();\r\n if (sumA <= sumB) {\r\n angles.setFrom(yprA);\r\n } else {\r\n angles.setFrom(yprB);\r\n }\r\n }\r\n }\r\n // sanity check\r\n const matrix1 = angles.toMatrix3d();\r\n return matrix.maxDiff(matrix1) < Geometry.smallAngleRadians ? angles : undefined;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"YawPitchRollAngles.js","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,0CAAmD;AACnD,mCAAgC;AAChC,yCAAsC;AACtC,uDAA4C;AAkB5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,MAAa,aAAK,CAAC,IAAI,EAAE,EAAE,QAAe,aAAK,CAAC,IAAI,EAAE,EAAE,OAAc,aAAK,CAAC,IAAI,EAAE;QAC5F,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,qCAAqC;IAC9B,MAAM;QACX,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IACD;;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AC5D,CAAC;CACF;AAnSD,gDAmSC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { AngleProps, Geometry } from \"../Geometry\";\r\nimport { Angle } from \"./Angle\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d } from \"./Point3dVector3d\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n// cspell:word Tait\r\n\r\n/**\r\n * Angle properties of a `YawPitchRoll` orientation\r\n * @public\r\n */\r\nexport interface YawPitchRollProps {\r\n /** yaw field */\r\n yaw?: AngleProps;\r\n /** pitch field */\r\n pitch?: AngleProps;\r\n /** roll field */\r\n roll?: AngleProps;\r\n}\r\n\r\n/**\r\n * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]\r\n * (https://en.wikipedia.org/wiki/Euler_angles).\r\n * * The matrix construction can be replicated by this logic:\r\n * * xyz coordinates have\r\n * * x forward\r\n * * y to left\r\n * * z up\r\n * * Note that this is a right handed coordinate system.\r\n * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):\r\n * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`\r\n * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):\r\n * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`\r\n * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):\r\n * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`\r\n * * The YPR matrix is the product\r\n * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`\r\n * * Note that this is for \"column based\" matrix with vectors multiplying on the right of the matrix.\r\n * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in\r\n * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.\r\n * @public\r\n */\r\nexport class YawPitchRollAngles {\r\n /** The yaw angle: counterclockwise rotation angle around z */\r\n public yaw: Angle;\r\n /** The pitch angle: **clockwise** rotation angle around y */\r\n public pitch: Angle;\r\n /** The roll angle: counterclockwise rotation angle around x */\r\n public roll: Angle;\r\n /**\r\n * Constructor\r\n * @param yaw counterclockwise rotation angle around z\r\n * @param pitch **clockwise** rotation angle around y\r\n * @param roll counterclockwise rotation angle around x\r\n */\r\n constructor(yaw: Angle = Angle.zero(), pitch: Angle = Angle.zero(), roll: Angle = Angle.zero()) {\r\n this.yaw = yaw;\r\n this.pitch = pitch;\r\n this.roll = roll;\r\n }\r\n /** Freeze this YawPitchRollAngles */\r\n public freeze(): Readonly<this> {\r\n this.yaw.freeze();\r\n this.pitch.freeze();\r\n this.roll.freeze();\r\n return Object.freeze(this);\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in degrees.\r\n * @param yawDegrees counterclockwise rotation angle (in degrees) around z\r\n * @param pitchDegrees **clockwise** rotation angle (in degrees) around y\r\n * @param rollDegrees counterclockwise rotation angle (in degrees) around x\r\n */\r\n public static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createDegrees(yawDegrees),\r\n Angle.createDegrees(pitchDegrees),\r\n Angle.createDegrees(rollDegrees),\r\n );\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in radians.\r\n * @param yawRadians counterclockwise rotation angle (in radians) around z\r\n * @param pitchRadians **clockwise** rotation angle (in radians) around y\r\n * @param rollRadians counterclockwise rotation angle (in radians) around x\r\n */\r\n public static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createRadians(yawRadians),\r\n Angle.createRadians(pitchRadians),\r\n Angle.createRadians(rollRadians),\r\n );\r\n }\r\n /** Construct a `YawPitchRoll` object from an object with 3 named angles */\r\n public static fromJSON(json?: YawPitchRollProps): YawPitchRollAngles {\r\n json = json ? json : {};\r\n return new YawPitchRollAngles(\r\n Angle.fromJSON(json.yaw),\r\n Angle.fromJSON(json.pitch),\r\n Angle.fromJSON(json.roll),\r\n );\r\n }\r\n /** Populate yaw, pitch and roll fields using `Angle.fromJSON` */\r\n public setFromJSON(json?: YawPitchRollProps): void {\r\n json = json ? json : {};\r\n this.yaw = Angle.fromJSON(json.yaw);\r\n this.pitch = Angle.fromJSON(json.pitch);\r\n this.roll = Angle.fromJSON(json.roll);\r\n }\r\n /**\r\n * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.\r\n * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.\r\n */\r\n public toJSON(): YawPitchRollProps {\r\n const val: YawPitchRollProps = {};\r\n if (!this.pitch.isAlmostZero)\r\n val.pitch = this.pitch.toJSON();\r\n if (!this.roll.isAlmostZero)\r\n val.roll = this.roll.toJSON();\r\n if (!this.yaw.isAlmostZero)\r\n val.yaw = this.yaw.toJSON();\r\n return val;\r\n }\r\n /**\r\n * Install all rotations from `other` into `this`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public setFrom(other: YawPitchRollAngles) {\r\n this.yaw.setFrom(other.yaw);\r\n this.pitch.setFrom(other.pitch);\r\n this.roll.setFrom(other.roll);\r\n }\r\n /**\r\n * Compare angles between `this` and `other`.\r\n * * Comparisons are via `isAlmostEqualAllowPeriodShift`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public isAlmostEqual(other: YawPitchRollAngles) {\r\n return this.yaw.isAlmostEqualAllowPeriodShift(other.yaw)\r\n && this.pitch.isAlmostEqualAllowPeriodShift(other.pitch)\r\n && this.roll.isAlmostEqualAllowPeriodShift(other.roll);\r\n }\r\n /** Make a copy of this YawPitchRollAngles */\r\n public clone() {\r\n return new YawPitchRollAngles(\r\n this.yaw.clone(),\r\n this.pitch.clone(),\r\n this.roll.clone(),\r\n );\r\n }\r\n /**\r\n * Expand the angles into a (rigid rotation) matrix.\r\n * * The returned matrix is \"rigid\" (i.e., it has unit length rows and columns, and its transpose is its inverse).\r\n * * The rigid matrix is always a right handed coordinate system.\r\n * @param result optional pre-allocated `Matrix3d`\r\n */\r\n public toMatrix3d(result?: Matrix3d) {\r\n const cz = Math.cos(this.yaw.radians);\r\n const sz = Math.sin(this.yaw.radians);\r\n const cy = Math.cos(this.pitch.radians);\r\n const sy = Math.sin(this.pitch.radians);\r\n const cx = Math.cos(this.roll.radians);\r\n const sx = Math.sin(this.roll.radians);\r\n /**\r\n * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where\r\n * rX, rY, and rZ are base rotation matrixes:\r\n *\r\n * const rX = Matrix3d.createRowValues(\r\n * 1, 0, 0,\r\n * 0, Math.cos(x), -Math.sin(x),\r\n * 0, Math.sin(x), Math.cos(x),\r\n * );\r\n * const rY = Matrix3d.createRowValues(\r\n * Math.cos(y), 0, Math.sin(y),\r\n * 0, 1, 0,\r\n * -Math.sin(y), 0, Math.cos(y),\r\n * );\r\n * const rZ = Matrix3d.createRowValues(\r\n * Math.cos(z), -Math.sin(z), 0,\r\n * Math.sin(z), Math.cos(z), 0,\r\n * 0, 0, 1,\r\n * );\r\n *\r\n * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you\r\n * can use transpose of rY in the matrix multiplication to get the same result)\r\n */\r\n return Matrix3d.createRowValues(\r\n cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n sy, cy * sx, cy * cx,\r\n result,\r\n );\r\n }\r\n /**\r\n * Returns true if this rotation does nothing.\r\n * * If allowPeriodShift is false, any nonzero angle is considered a non-identity\r\n * * If allowPeriodShift is true, all angles are individually allowed to be any multiple of 360 degrees.\r\n */\r\n public isIdentity(allowPeriodShift: boolean = true): boolean {\r\n if (allowPeriodShift)\r\n return Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.roll.radians);\r\n else\r\n return Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);\r\n }\r\n /** Return the largest angle in radians */\r\n public maxAbsRadians(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the sum of the angles in squared radians */\r\n public sumSquaredRadians(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the largest difference of angles (in radians) between this and other */\r\n public maxDiffRadians(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.radians - other.yaw.radians,\r\n this.pitch.radians - other.pitch.radians,\r\n this.roll.radians - other.roll.radians,\r\n );\r\n }\r\n /** Return the largest angle in degrees. */\r\n public maxAbsDegrees(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the sum of squared angles in degrees. */\r\n public sumSquaredDegrees(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the largest difference of angles (in degrees) between this and other */\r\n public maxDiffDegrees(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.degrees - other.yaw.degrees,\r\n this.pitch.degrees - other.pitch.degrees,\r\n this.roll.degrees - other.roll.degrees,\r\n );\r\n }\r\n /** Return an object from a Transform as an origin and YawPitchRollAngles. */\r\n public static tryFromTransform(transform: Transform): {\r\n origin: Point3d;\r\n angles: YawPitchRollAngles | undefined;\r\n } {\r\n return {\r\n origin: Point3d.createFrom(transform.origin),\r\n angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),\r\n };\r\n }\r\n /**\r\n * Attempts to create a YawPitchRollAngles object from a Matrix3d.\r\n * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and\r\n * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].\r\n * @param result optional pre-allocated object to populate and return.\r\n * @returns computed angles, or undefined if `matrix` is not rigid.\r\n * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:\r\n * their usefulness decreases the further `matrix` is from being rigid.\r\n */\r\n public static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined {\r\n /**\r\n * The rotation matrix form is\r\n *\r\n * Matrix3d.createRowValues(\r\n * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n * sy, cy * sx, cy * cx\r\n * );\r\n *\r\n * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)\r\n */\r\n const sy = matrix.at(2, 0); // sin(y)\r\n const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|\r\n const pitchA = Angle.createAtan2(sy, cy); // with positive cosine\r\n const pitchB = Angle.createAtan2(sy, -cy); // with negative cosine\r\n const angles = result ? result : new YawPitchRollAngles();\r\n /**\r\n * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.\r\n * This means x and z can be anything as long as their sum x + z is constant.\r\n * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).\r\n * Math details can be found\r\n * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles\r\n *\r\n * The rotation matrix for y = +-90 degrees and x = 0 becomes\r\n *\r\n * Matrix3d.createRowValues(\r\n * 0, -sz, -+cz,\r\n * 0, cz, -+sz,\r\n * +-1, 0, 0\r\n * );\r\n *\r\n * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))\r\n */\r\n if (cy < Geometry.smallAngleRadians) {\r\n angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));\r\n angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.\r\n angles.roll = Angle.createRadians(0.0);\r\n } else {\r\n /**\r\n * positive cosine\r\n * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))\r\n * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))\r\n */\r\n const yawA = Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));\r\n const rollA = Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));\r\n // similar with negative cosine\r\n const yawB = Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));\r\n const rollB = Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));\r\n // create YPR\r\n const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);\r\n const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);\r\n // decide to pick yprA or yprB with smallest magnitude angles\r\n const absFactor = 0.95;\r\n const maxRadiansA = yprA.maxAbsRadians();\r\n const maxRadiansB = yprB.maxAbsRadians();\r\n if (maxRadiansA < absFactor * maxRadiansB) {\r\n angles.setFrom(yprA);\r\n } else if (maxRadiansB < absFactor * maxRadiansA) {\r\n angles.setFrom(yprB);\r\n } else {\r\n const sumA = yprA.sumSquaredRadians();\r\n const sumB = yprB.sumSquaredRadians();\r\n if (sumA <= sumB) {\r\n angles.setFrom(yprA);\r\n } else {\r\n angles.setFrom(yprB);\r\n }\r\n }\r\n }\r\n // sanity check\r\n const matrix1 = angles.toMatrix3d();\r\n return matrix.isAlmostEqual(matrix1) ? angles : undefined;\r\n }\r\n}\r\n"]}
@@ -123,11 +123,13 @@ export declare class YawPitchRollAngles {
123
123
  angles: YawPitchRollAngles | undefined;
124
124
  };
125
125
  /**
126
- * Attempts to create a YawPitchRollAngles object from a Matrix3d
127
- * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
128
- * * In the failure case the method's return value is `undefined`.
129
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
130
- * a set of angles.
126
+ * Attempts to create a YawPitchRollAngles object from a Matrix3d.
127
+ * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and
128
+ * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].
129
+ * @param result optional pre-allocated object to populate and return.
130
+ * @returns computed angles, or undefined if `matrix` is not rigid.
131
+ * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:
132
+ * their usefulness decreases the further `matrix` is from being rigid.
131
133
  */
132
134
  static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined;
133
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"YawPitchRollAngles.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAY,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,gBAAgB;IAChB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,kBAAkB;IAClB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,iBAAiB;IACjB,IAAI,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M,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS;CA0EhH"}
@@ -202,11 +202,13 @@ export class YawPitchRollAngles {
202
202
  };
203
203
  }
204
204
  /**
205
- * Attempts to create a YawPitchRollAngles object from a Matrix3d
206
- * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
207
- * * In the failure case the method's return value is `undefined`.
208
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
209
- * a set of angles.
205
+ * Attempts to create a YawPitchRollAngles object from a Matrix3d.
206
+ * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and
207
+ * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].
208
+ * @param result optional pre-allocated object to populate and return.
209
+ * @returns computed angles, or undefined if `matrix` is not rigid.
210
+ * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:
211
+ * their usefulness decreases the further `matrix` is from being rigid.
210
212
  */
211
213
  static createFromMatrix3d(matrix, result) {
212
214
  /**
@@ -284,7 +286,7 @@ export class YawPitchRollAngles {
284
286
  }
285
287
  // sanity check
286
288
  const matrix1 = angles.toMatrix3d();
287
- return matrix.maxDiff(matrix1) < Geometry.smallAngleRadians ? angles : undefined;
289
+ return matrix.isAlmostEqual(matrix1) ? angles : undefined;
288
290
  }
289
291
  }
290
292
  //# sourceMappingURL=YawPitchRollAngles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"YawPitchRollAngles.js","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAc,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,C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CAAC;aACtB;iBAAM,IAAI,WAAW,GAAG,SAAS,GAAG,WAAW,EAAE;gBAChD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;iBAAM;gBACL,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACtC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACtC,IAAI,IAAI,IAAI,IAAI,EAAE;oBAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;iBACtB;qBAAM;oBACL,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;iBACtB;aACF;SACF;QACD,eAAe;QACf,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { AngleProps, Geometry } from \"../Geometry\";\r\nimport { Angle } from \"./Angle\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d } from \"./Point3dVector3d\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n// cspell:word Tait\r\n\r\n/**\r\n * Angle properties of a `YawPitchRoll` orientation\r\n * @public\r\n */\r\nexport interface YawPitchRollProps {\r\n /** yaw field */\r\n yaw?: AngleProps;\r\n /** pitch field */\r\n pitch?: AngleProps;\r\n /** roll field */\r\n roll?: AngleProps;\r\n}\r\n\r\n/**\r\n * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]\r\n * (https://en.wikipedia.org/wiki/Euler_angles).\r\n * * The matrix construction can be replicated by this logic:\r\n * * xyz coordinates have\r\n * * x forward\r\n * * y to left\r\n * * z up\r\n * * Note that this is a right handed coordinate system.\r\n * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):\r\n * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`\r\n * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):\r\n * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`\r\n * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):\r\n * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`\r\n * * The YPR matrix is the product\r\n * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`\r\n * * Note that this is for \"column based\" matrix with vectors multiplying on the right of the matrix.\r\n * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in\r\n * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.\r\n * @public\r\n */\r\nexport class YawPitchRollAngles {\r\n /** The yaw angle: counterclockwise rotation angle around z */\r\n public yaw: Angle;\r\n /** The pitch angle: **clockwise** rotation angle around y */\r\n public pitch: Angle;\r\n /** The roll angle: counterclockwise rotation angle around x */\r\n public roll: Angle;\r\n /**\r\n * Constructor\r\n * @param yaw counterclockwise rotation angle around z\r\n * @param pitch **clockwise** rotation angle around y\r\n * @param roll counterclockwise rotation angle around x\r\n */\r\n constructor(yaw: Angle = Angle.zero(), pitch: Angle = Angle.zero(), roll: Angle = Angle.zero()) {\r\n this.yaw = yaw;\r\n this.pitch = pitch;\r\n this.roll = roll;\r\n }\r\n /** Freeze this YawPitchRollAngles */\r\n public freeze(): Readonly<this> {\r\n this.yaw.freeze();\r\n this.pitch.freeze();\r\n this.roll.freeze();\r\n return Object.freeze(this);\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in degrees.\r\n * @param yawDegrees counterclockwise rotation angle (in degrees) around z\r\n * @param pitchDegrees **clockwise** rotation angle (in degrees) around y\r\n * @param rollDegrees counterclockwise rotation angle (in degrees) around x\r\n */\r\n public static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createDegrees(yawDegrees),\r\n Angle.createDegrees(pitchDegrees),\r\n Angle.createDegrees(rollDegrees),\r\n );\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in radians.\r\n * @param yawRadians counterclockwise rotation angle (in radians) around z\r\n * @param pitchRadians **clockwise** rotation angle (in radians) around y\r\n * @param rollRadians counterclockwise rotation angle (in radians) around x\r\n */\r\n public static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createRadians(yawRadians),\r\n Angle.createRadians(pitchRadians),\r\n Angle.createRadians(rollRadians),\r\n );\r\n }\r\n /** Construct a `YawPitchRoll` object from an object with 3 named angles */\r\n public static fromJSON(json?: YawPitchRollProps): YawPitchRollAngles {\r\n json = json ? json : {};\r\n return new YawPitchRollAngles(\r\n Angle.fromJSON(json.yaw),\r\n Angle.fromJSON(json.pitch),\r\n Angle.fromJSON(json.roll),\r\n );\r\n }\r\n /** Populate yaw, pitch and roll fields using `Angle.fromJSON` */\r\n public setFromJSON(json?: YawPitchRollProps): void {\r\n json = json ? json : {};\r\n this.yaw = Angle.fromJSON(json.yaw);\r\n this.pitch = Angle.fromJSON(json.pitch);\r\n this.roll = Angle.fromJSON(json.roll);\r\n }\r\n /**\r\n * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.\r\n * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.\r\n */\r\n public toJSON(): YawPitchRollProps {\r\n const val: YawPitchRollProps = {};\r\n if (!this.pitch.isAlmostZero)\r\n val.pitch = this.pitch.toJSON();\r\n if (!this.roll.isAlmostZero)\r\n val.roll = this.roll.toJSON();\r\n if (!this.yaw.isAlmostZero)\r\n val.yaw = this.yaw.toJSON();\r\n return val;\r\n }\r\n /**\r\n * Install all rotations from `other` into `this`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public setFrom(other: YawPitchRollAngles) {\r\n this.yaw.setFrom(other.yaw);\r\n this.pitch.setFrom(other.pitch);\r\n this.roll.setFrom(other.roll);\r\n }\r\n /**\r\n * Compare angles between `this` and `other`.\r\n * * Comparisons are via `isAlmostEqualAllowPeriodShift`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public isAlmostEqual(other: YawPitchRollAngles) {\r\n return this.yaw.isAlmostEqualAllowPeriodShift(other.yaw)\r\n && this.pitch.isAlmostEqualAllowPeriodShift(other.pitch)\r\n && this.roll.isAlmostEqualAllowPeriodShift(other.roll);\r\n }\r\n /** Make a copy of this YawPitchRollAngles */\r\n public clone() {\r\n return new YawPitchRollAngles(\r\n this.yaw.clone(),\r\n this.pitch.clone(),\r\n this.roll.clone(),\r\n );\r\n }\r\n /**\r\n * Expand the angles into a (rigid rotation) matrix.\r\n * * The returned matrix is \"rigid\" (i.e., it has unit length rows and columns, and its transpose is its inverse).\r\n * * The rigid matrix is always a right handed coordinate system.\r\n * @param result optional pre-allocated `Matrix3d`\r\n */\r\n public toMatrix3d(result?: Matrix3d) {\r\n const cz = Math.cos(this.yaw.radians);\r\n const sz = Math.sin(this.yaw.radians);\r\n const cy = Math.cos(this.pitch.radians);\r\n const sy = Math.sin(this.pitch.radians);\r\n const cx = Math.cos(this.roll.radians);\r\n const sx = Math.sin(this.roll.radians);\r\n /**\r\n * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where\r\n * rX, rY, and rZ are base rotation matrixes:\r\n *\r\n * const rX = Matrix3d.createRowValues(\r\n * 1, 0, 0,\r\n * 0, Math.cos(x), -Math.sin(x),\r\n * 0, Math.sin(x), Math.cos(x),\r\n * );\r\n * const rY = Matrix3d.createRowValues(\r\n * Math.cos(y), 0, Math.sin(y),\r\n * 0, 1, 0,\r\n * -Math.sin(y), 0, Math.cos(y),\r\n * );\r\n * const rZ = Matrix3d.createRowValues(\r\n * Math.cos(z), -Math.sin(z), 0,\r\n * Math.sin(z), Math.cos(z), 0,\r\n * 0, 0, 1,\r\n * );\r\n *\r\n * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you\r\n * can use transpose of rY in the matrix multiplication to get the same result)\r\n */\r\n return Matrix3d.createRowValues(\r\n cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n sy, cy * sx, cy * cx,\r\n result,\r\n );\r\n }\r\n /**\r\n * Returns true if this rotation does nothing.\r\n * * If allowPeriodShift is false, any nonzero angle is considered a non-identity\r\n * * If allowPeriodShift is true, all angles are individually allowed to be any multiple of 360 degrees.\r\n */\r\n public isIdentity(allowPeriodShift: boolean = true): boolean {\r\n if (allowPeriodShift)\r\n return Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.roll.radians);\r\n else\r\n return Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);\r\n }\r\n /** Return the largest angle in radians */\r\n public maxAbsRadians(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the sum of the angles in squared radians */\r\n public sumSquaredRadians(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the largest difference of angles (in radians) between this and other */\r\n public maxDiffRadians(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.radians - other.yaw.radians,\r\n this.pitch.radians - other.pitch.radians,\r\n this.roll.radians - other.roll.radians,\r\n );\r\n }\r\n /** Return the largest angle in degrees. */\r\n public maxAbsDegrees(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the sum of squared angles in degrees. */\r\n public sumSquaredDegrees(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the largest difference of angles (in degrees) between this and other */\r\n public maxDiffDegrees(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.degrees - other.yaw.degrees,\r\n this.pitch.degrees - other.pitch.degrees,\r\n this.roll.degrees - other.roll.degrees,\r\n );\r\n }\r\n /** Return an object from a Transform as an origin and YawPitchRollAngles. */\r\n public static tryFromTransform(transform: Transform): {\r\n origin: Point3d;\r\n angles: YawPitchRollAngles | undefined;\r\n } {\r\n return {\r\n origin: Point3d.createFrom(transform.origin),\r\n angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),\r\n };\r\n }\r\n /**\r\n * Attempts to create a YawPitchRollAngles object from a Matrix3d\r\n * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)\r\n * * In the failure case the method's return value is `undefined`.\r\n * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with\r\n * a set of angles.\r\n */\r\n public static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined {\r\n /**\r\n * The rotation matrix form is\r\n *\r\n * Matrix3d.createRowValues(\r\n * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n * sy, cy * sx, cy * cx\r\n * );\r\n *\r\n * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)\r\n */\r\n const sy = matrix.at(2, 0); // sin(y)\r\n const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|\r\n const pitchA = Angle.createAtan2(sy, cy); // with positive cosine\r\n const pitchB = Angle.createAtan2(sy, -cy); // with negative cosine\r\n const angles = result ? result : new YawPitchRollAngles();\r\n /**\r\n * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.\r\n * This means x and z can be anything as long as their sum x + z is constant.\r\n * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).\r\n * Math details can be found\r\n * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles\r\n *\r\n * The rotation matrix for y = +-90 degrees and x = 0 becomes\r\n *\r\n * Matrix3d.createRowValues(\r\n * 0, -sz, -+cz,\r\n * 0, cz, -+sz,\r\n * +-1, 0, 0\r\n * );\r\n *\r\n * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))\r\n */\r\n if (cy < Geometry.smallAngleRadians) {\r\n angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));\r\n angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.\r\n angles.roll = Angle.createRadians(0.0);\r\n } else {\r\n /**\r\n * positive cosine\r\n * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))\r\n * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))\r\n */\r\n const yawA = Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));\r\n const rollA = Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));\r\n // similar with negative cosine\r\n const yawB = Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));\r\n const rollB = Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));\r\n // create YPR\r\n const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);\r\n const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);\r\n // decide to pick yprA or yprB with smallest magnitude angles\r\n const absFactor = 0.95;\r\n const maxRadiansA = yprA.maxAbsRadians();\r\n const maxRadiansB = yprB.maxAbsRadians();\r\n if (maxRadiansA < absFactor * maxRadiansB) {\r\n angles.setFrom(yprA);\r\n } else if (maxRadiansB < absFactor * maxRadiansA) {\r\n angles.setFrom(yprB);\r\n } else {\r\n const sumA = yprA.sumSquaredRadians();\r\n const sumB = yprB.sumSquaredRadians();\r\n if (sumA <= sumB) {\r\n angles.setFrom(yprA);\r\n } else {\r\n angles.setFrom(yprB);\r\n }\r\n }\r\n }\r\n // sanity check\r\n const matrix1 = angles.toMatrix3d();\r\n return matrix.maxDiff(matrix1) < Geometry.smallAngleRadians ? angles : undefined;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"YawPitchRollAngles.js","sourceRoot":"","sources":["../../../src/geometry3d/YawPitchRollAngles.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAc,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAkB5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,MAAa,KAAK,CAAC,IAAI,EAAE,EAAE,QAAe,KAAK,CAAC,IAAI,EAAE,EAAE,OAAc,KAAK,CAAC,IAAI,EAAE;QAC5F,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,qCAAqC;IAC9B,MAAM;QACX,IAAI,CAAC,GAAG,CAAC,MAAM,EA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ACF;QACD,eAAe;QACf,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module CartesianGeometry\r\n */\r\n\r\nimport { AngleProps, Geometry } from \"../Geometry\";\r\nimport { Angle } from \"./Angle\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Point3d } from \"./Point3dVector3d\";\r\nimport { Transform } from \"./Transform\";\r\n\r\n// cspell:word Tait\r\n\r\n/**\r\n * Angle properties of a `YawPitchRoll` orientation\r\n * @public\r\n */\r\nexport interface YawPitchRollProps {\r\n /** yaw field */\r\n yaw?: AngleProps;\r\n /** pitch field */\r\n pitch?: AngleProps;\r\n /** roll field */\r\n roll?: AngleProps;\r\n}\r\n\r\n/**\r\n * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]\r\n * (https://en.wikipedia.org/wiki/Euler_angles).\r\n * * The matrix construction can be replicated by this logic:\r\n * * xyz coordinates have\r\n * * x forward\r\n * * y to left\r\n * * z up\r\n * * Note that this is a right handed coordinate system.\r\n * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):\r\n * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`\r\n * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):\r\n * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`\r\n * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):\r\n * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`\r\n * * The YPR matrix is the product\r\n * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`\r\n * * Note that this is for \"column based\" matrix with vectors multiplying on the right of the matrix.\r\n * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in\r\n * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.\r\n * @public\r\n */\r\nexport class YawPitchRollAngles {\r\n /** The yaw angle: counterclockwise rotation angle around z */\r\n public yaw: Angle;\r\n /** The pitch angle: **clockwise** rotation angle around y */\r\n public pitch: Angle;\r\n /** The roll angle: counterclockwise rotation angle around x */\r\n public roll: Angle;\r\n /**\r\n * Constructor\r\n * @param yaw counterclockwise rotation angle around z\r\n * @param pitch **clockwise** rotation angle around y\r\n * @param roll counterclockwise rotation angle around x\r\n */\r\n constructor(yaw: Angle = Angle.zero(), pitch: Angle = Angle.zero(), roll: Angle = Angle.zero()) {\r\n this.yaw = yaw;\r\n this.pitch = pitch;\r\n this.roll = roll;\r\n }\r\n /** Freeze this YawPitchRollAngles */\r\n public freeze(): Readonly<this> {\r\n this.yaw.freeze();\r\n this.pitch.freeze();\r\n this.roll.freeze();\r\n return Object.freeze(this);\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in degrees.\r\n * @param yawDegrees counterclockwise rotation angle (in degrees) around z\r\n * @param pitchDegrees **clockwise** rotation angle (in degrees) around y\r\n * @param rollDegrees counterclockwise rotation angle (in degrees) around x\r\n */\r\n public static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createDegrees(yawDegrees),\r\n Angle.createDegrees(pitchDegrees),\r\n Angle.createDegrees(rollDegrees),\r\n );\r\n }\r\n /**\r\n * Constructor for YawPitchRollAngles with angles in radians.\r\n * @param yawRadians counterclockwise rotation angle (in radians) around z\r\n * @param pitchRadians **clockwise** rotation angle (in radians) around y\r\n * @param rollRadians counterclockwise rotation angle (in radians) around x\r\n */\r\n public static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(\r\n Angle.createRadians(yawRadians),\r\n Angle.createRadians(pitchRadians),\r\n Angle.createRadians(rollRadians),\r\n );\r\n }\r\n /** Construct a `YawPitchRoll` object from an object with 3 named angles */\r\n public static fromJSON(json?: YawPitchRollProps): YawPitchRollAngles {\r\n json = json ? json : {};\r\n return new YawPitchRollAngles(\r\n Angle.fromJSON(json.yaw),\r\n Angle.fromJSON(json.pitch),\r\n Angle.fromJSON(json.roll),\r\n );\r\n }\r\n /** Populate yaw, pitch and roll fields using `Angle.fromJSON` */\r\n public setFromJSON(json?: YawPitchRollProps): void {\r\n json = json ? json : {};\r\n this.yaw = Angle.fromJSON(json.yaw);\r\n this.pitch = Angle.fromJSON(json.pitch);\r\n this.roll = Angle.fromJSON(json.roll);\r\n }\r\n /**\r\n * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.\r\n * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.\r\n */\r\n public toJSON(): YawPitchRollProps {\r\n const val: YawPitchRollProps = {};\r\n if (!this.pitch.isAlmostZero)\r\n val.pitch = this.pitch.toJSON();\r\n if (!this.roll.isAlmostZero)\r\n val.roll = this.roll.toJSON();\r\n if (!this.yaw.isAlmostZero)\r\n val.yaw = this.yaw.toJSON();\r\n return val;\r\n }\r\n /**\r\n * Install all rotations from `other` into `this`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public setFrom(other: YawPitchRollAngles) {\r\n this.yaw.setFrom(other.yaw);\r\n this.pitch.setFrom(other.pitch);\r\n this.roll.setFrom(other.roll);\r\n }\r\n /**\r\n * Compare angles between `this` and `other`.\r\n * * Comparisons are via `isAlmostEqualAllowPeriodShift`.\r\n * @param other YawPitchRollAngles source\r\n */\r\n public isAlmostEqual(other: YawPitchRollAngles) {\r\n return this.yaw.isAlmostEqualAllowPeriodShift(other.yaw)\r\n && this.pitch.isAlmostEqualAllowPeriodShift(other.pitch)\r\n && this.roll.isAlmostEqualAllowPeriodShift(other.roll);\r\n }\r\n /** Make a copy of this YawPitchRollAngles */\r\n public clone() {\r\n return new YawPitchRollAngles(\r\n this.yaw.clone(),\r\n this.pitch.clone(),\r\n this.roll.clone(),\r\n );\r\n }\r\n /**\r\n * Expand the angles into a (rigid rotation) matrix.\r\n * * The returned matrix is \"rigid\" (i.e., it has unit length rows and columns, and its transpose is its inverse).\r\n * * The rigid matrix is always a right handed coordinate system.\r\n * @param result optional pre-allocated `Matrix3d`\r\n */\r\n public toMatrix3d(result?: Matrix3d) {\r\n const cz = Math.cos(this.yaw.radians);\r\n const sz = Math.sin(this.yaw.radians);\r\n const cy = Math.cos(this.pitch.radians);\r\n const sy = Math.sin(this.pitch.radians);\r\n const cx = Math.cos(this.roll.radians);\r\n const sx = Math.sin(this.roll.radians);\r\n /**\r\n * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where\r\n * rX, rY, and rZ are base rotation matrixes:\r\n *\r\n * const rX = Matrix3d.createRowValues(\r\n * 1, 0, 0,\r\n * 0, Math.cos(x), -Math.sin(x),\r\n * 0, Math.sin(x), Math.cos(x),\r\n * );\r\n * const rY = Matrix3d.createRowValues(\r\n * Math.cos(y), 0, Math.sin(y),\r\n * 0, 1, 0,\r\n * -Math.sin(y), 0, Math.cos(y),\r\n * );\r\n * const rZ = Matrix3d.createRowValues(\r\n * Math.cos(z), -Math.sin(z), 0,\r\n * Math.sin(z), Math.cos(z), 0,\r\n * 0, 0, 1,\r\n * );\r\n *\r\n * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you\r\n * can use transpose of rY in the matrix multiplication to get the same result)\r\n */\r\n return Matrix3d.createRowValues(\r\n cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n sy, cy * sx, cy * cx,\r\n result,\r\n );\r\n }\r\n /**\r\n * Returns true if this rotation does nothing.\r\n * * If allowPeriodShift is false, any nonzero angle is considered a non-identity\r\n * * If allowPeriodShift is true, all angles are individually allowed to be any multiple of 360 degrees.\r\n */\r\n public isIdentity(allowPeriodShift: boolean = true): boolean {\r\n if (allowPeriodShift)\r\n return Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansAllowPeriodShift(0.0, this.roll.radians);\r\n else\r\n return Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.yaw.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)\r\n && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);\r\n }\r\n /** Return the largest angle in radians */\r\n public maxAbsRadians(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the sum of the angles in squared radians */\r\n public sumSquaredRadians(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);\r\n }\r\n /** Return the largest difference of angles (in radians) between this and other */\r\n public maxDiffRadians(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.radians - other.yaw.radians,\r\n this.pitch.radians - other.pitch.radians,\r\n this.roll.radians - other.roll.radians,\r\n );\r\n }\r\n /** Return the largest angle in degrees. */\r\n public maxAbsDegrees(): number {\r\n return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the sum of squared angles in degrees. */\r\n public sumSquaredDegrees(): number {\r\n return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);\r\n }\r\n /** Return the largest difference of angles (in degrees) between this and other */\r\n public maxDiffDegrees(other: YawPitchRollAngles): number {\r\n return Math.max(\r\n this.yaw.degrees - other.yaw.degrees,\r\n this.pitch.degrees - other.pitch.degrees,\r\n this.roll.degrees - other.roll.degrees,\r\n );\r\n }\r\n /** Return an object from a Transform as an origin and YawPitchRollAngles. */\r\n public static tryFromTransform(transform: Transform): {\r\n origin: Point3d;\r\n angles: YawPitchRollAngles | undefined;\r\n } {\r\n return {\r\n origin: Point3d.createFrom(transform.origin),\r\n angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),\r\n };\r\n }\r\n /**\r\n * Attempts to create a YawPitchRollAngles object from a Matrix3d.\r\n * @param matrix rigid matrix to process. Caller can test for rigidity with [[Matrix3d.isRigid]] and\r\n * ensure rigid input with [[Matrix3d.createRigidFromMatrix3d]] or [[Matrix3d.makeRigid]].\r\n * @param result optional pre-allocated object to populate and return.\r\n * @returns computed angles, or undefined if `matrix` is not rigid.\r\n * * Even when undefined is returned, `result` (if supplied) is populated with angles that may be used with caution:\r\n * their usefulness decreases the further `matrix` is from being rigid.\r\n */\r\n public static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined {\r\n /**\r\n * The rotation matrix form is\r\n *\r\n * Matrix3d.createRowValues(\r\n * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),\r\n * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),\r\n * sy, cy * sx, cy * cx\r\n * );\r\n *\r\n * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)\r\n */\r\n const sy = matrix.at(2, 0); // sin(y)\r\n const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|\r\n const pitchA = Angle.createAtan2(sy, cy); // with positive cosine\r\n const pitchB = Angle.createAtan2(sy, -cy); // with negative cosine\r\n const angles = result ? result : new YawPitchRollAngles();\r\n /**\r\n * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.\r\n * This means x and z can be anything as long as their sum x + z is constant.\r\n * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).\r\n * Math details can be found\r\n * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles\r\n *\r\n * The rotation matrix for y = +-90 degrees and x = 0 becomes\r\n *\r\n * Matrix3d.createRowValues(\r\n * 0, -sz, -+cz,\r\n * 0, cz, -+sz,\r\n * +-1, 0, 0\r\n * );\r\n *\r\n * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))\r\n */\r\n if (cy < Geometry.smallAngleRadians) {\r\n angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));\r\n angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.\r\n angles.roll = Angle.createRadians(0.0);\r\n } else {\r\n /**\r\n * positive cosine\r\n * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))\r\n * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))\r\n */\r\n const yawA = Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));\r\n const rollA = Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));\r\n // similar with negative cosine\r\n const yawB = Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));\r\n const rollB = Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));\r\n // create YPR\r\n const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);\r\n const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);\r\n // decide to pick yprA or yprB with smallest magnitude angles\r\n const absFactor = 0.95;\r\n const maxRadiansA = yprA.maxAbsRadians();\r\n const maxRadiansB = yprB.maxAbsRadians();\r\n if (maxRadiansA < absFactor * maxRadiansB) {\r\n angles.setFrom(yprA);\r\n } else if (maxRadiansB < absFactor * maxRadiansA) {\r\n angles.setFrom(yprB);\r\n } else {\r\n const sumA = yprA.sumSquaredRadians();\r\n const sumB = yprB.sumSquaredRadians();\r\n if (sumA <= sumB) {\r\n angles.setFrom(yprA);\r\n } else {\r\n angles.setFrom(yprB);\r\n }\r\n }\r\n }\r\n // sanity check\r\n const matrix1 = angles.toMatrix3d();\r\n return matrix.isAlmostEqual(matrix1) ? angles : undefined;\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-geometry",
3
- "version": "4.4.0-dev.18",
3
+ "version": "4.4.0-dev.19",
4
4
  "description": "iTwin.js Core Geometry library",
5
5
  "main": "lib/cjs/core-geometry.js",
6
6
  "module": "lib/esm/core-geometry.js",
@@ -34,11 +34,11 @@
34
34
  "nyc": "^15.1.0",
35
35
  "rimraf": "^3.0.2",
36
36
  "typescript": "~5.0.2",
37
- "@itwin/build-tools": "4.4.0-dev.18"
37
+ "@itwin/build-tools": "4.4.0-dev.19"
38
38
  },
39
39
  "dependencies": {
40
40
  "flatbuffers": "~1.12.0",
41
- "@itwin/core-bentley": "4.4.0-dev.18"
41
+ "@itwin/core-bentley": "4.4.0-dev.19"
42
42
  },
43
43
  "nyc": {
44
44
  "extends": "./node_modules/@itwin/build-tools/.nycrc",