@itwin/core-geometry 3.6.0-dev.8 → 4.0.0-dev.2

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Geometry.d.ts +25 -14
  4. package/lib/cjs/Geometry.d.ts.map +1 -1
  5. package/lib/cjs/Geometry.js +25 -14
  6. package/lib/cjs/Geometry.js.map +1 -1
  7. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +10 -6
  8. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  9. package/lib/cjs/curve/CurveChainWithDistanceIndex.js +10 -19
  10. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  11. package/lib/cjs/geometry3d/Angle.d.ts +1 -0
  12. package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
  13. package/lib/cjs/geometry3d/Angle.js +1 -0
  14. package/lib/cjs/geometry3d/Angle.js.map +1 -1
  15. package/lib/cjs/geometry3d/AngleSweep.d.ts +1 -0
  16. package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
  17. package/lib/cjs/geometry3d/AngleSweep.js +1 -0
  18. package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
  19. package/lib/cjs/geometry3d/GrowableXYArray.d.ts +1 -1
  20. package/lib/cjs/geometry3d/GrowableXYArray.js +1 -1
  21. package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
  22. package/lib/cjs/geometry3d/Matrix3d.d.ts +221 -159
  23. package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
  24. package/lib/cjs/geometry3d/Matrix3d.js +365 -249
  25. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  26. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts +71 -14
  27. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  28. package/lib/cjs/geometry3d/OrderedRotationAngles.js +204 -114
  29. package/lib/cjs/geometry3d/OrderedRotationAngles.js.map +1 -1
  30. package/lib/cjs/geometry3d/Point2dVector2d.d.ts +1 -0
  31. package/lib/cjs/geometry3d/Point2dVector2d.d.ts.map +1 -1
  32. package/lib/cjs/geometry3d/Point2dVector2d.js +1 -0
  33. package/lib/cjs/geometry3d/Point2dVector2d.js.map +1 -1
  34. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +4 -3
  35. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  36. package/lib/cjs/geometry3d/Point3dVector3d.js +6 -5
  37. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  38. package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts +49 -25
  39. package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
  40. package/lib/cjs/geometry3d/YawPitchRollAngles.js +146 -50
  41. package/lib/cjs/geometry3d/YawPitchRollAngles.js.map +1 -1
  42. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +4 -4
  43. package/lib/cjs/polyface/PolyfaceBuilder.js +4 -4
  44. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  45. package/lib/cjs/polyface/PolyfaceQuery.d.ts +28 -0
  46. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  47. package/lib/cjs/polyface/PolyfaceQuery.js +79 -0
  48. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  49. package/lib/cjs/serialization/IModelJsonSchema.d.ts +1 -1
  50. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  51. package/lib/esm/Geometry.d.ts +25 -14
  52. package/lib/esm/Geometry.d.ts.map +1 -1
  53. package/lib/esm/Geometry.js +25 -14
  54. package/lib/esm/Geometry.js.map +1 -1
  55. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +10 -6
  56. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  57. package/lib/esm/curve/CurveChainWithDistanceIndex.js +10 -19
  58. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  59. package/lib/esm/geometry3d/Angle.d.ts +1 -0
  60. package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
  61. package/lib/esm/geometry3d/Angle.js +1 -0
  62. package/lib/esm/geometry3d/Angle.js.map +1 -1
  63. package/lib/esm/geometry3d/AngleSweep.d.ts +1 -0
  64. package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
  65. package/lib/esm/geometry3d/AngleSweep.js +1 -0
  66. package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
  67. package/lib/esm/geometry3d/GrowableXYArray.d.ts +1 -1
  68. package/lib/esm/geometry3d/GrowableXYArray.js +1 -1
  69. package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
  70. package/lib/esm/geometry3d/Matrix3d.d.ts +221 -159
  71. package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
  72. package/lib/esm/geometry3d/Matrix3d.js +365 -249
  73. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  74. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts +71 -14
  75. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  76. package/lib/esm/geometry3d/OrderedRotationAngles.js +205 -115
  77. package/lib/esm/geometry3d/OrderedRotationAngles.js.map +1 -1
  78. package/lib/esm/geometry3d/Point2dVector2d.d.ts +1 -0
  79. package/lib/esm/geometry3d/Point2dVector2d.d.ts.map +1 -1
  80. package/lib/esm/geometry3d/Point2dVector2d.js +1 -0
  81. package/lib/esm/geometry3d/Point2dVector2d.js.map +1 -1
  82. package/lib/esm/geometry3d/Point3dVector3d.d.ts +4 -3
  83. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  84. package/lib/esm/geometry3d/Point3dVector3d.js +6 -5
  85. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  86. package/lib/esm/geometry3d/YawPitchRollAngles.d.ts +49 -25
  87. package/lib/esm/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
  88. package/lib/esm/geometry3d/YawPitchRollAngles.js +146 -50
  89. package/lib/esm/geometry3d/YawPitchRollAngles.js.map +1 -1
  90. package/lib/esm/polyface/PolyfaceBuilder.d.ts +4 -4
  91. package/lib/esm/polyface/PolyfaceBuilder.js +4 -4
  92. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  93. package/lib/esm/polyface/PolyfaceQuery.d.ts +28 -0
  94. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  95. package/lib/esm/polyface/PolyfaceQuery.js +79 -0
  96. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  97. package/lib/esm/serialization/IModelJsonSchema.d.ts +1 -1
  98. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  99. package/package.json +4 -4
@@ -6,7 +6,6 @@ import { Angle } from "./Angle";
6
6
  import { Matrix3d } from "./Matrix3d";
7
7
  import { Point3d } from "./Point3dVector3d";
8
8
  import { Transform } from "./Transform";
9
- /** The properties that define [[YawPitchRollAngles]]. */
10
9
  /**
11
10
  * angle properties of a `YawPitchRoll` orientation
12
11
  * @public
@@ -19,44 +18,66 @@ export interface YawPitchRollProps {
19
18
  /** roll field */
20
19
  roll?: AngleProps;
21
20
  }
22
- /** Three angles that determine the orientation of an object in space. Sometimes referred to as [Tait–Bryan angles](https://en.wikipedia.org/wiki/Euler_angles).
21
+ /**
22
+ * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]
23
+ * (https://en.wikipedia.org/wiki/Euler_angles).
23
24
  * * The matrix construction can be replicated by this logic:
24
25
  * * xyz coordinates have
25
26
  * * x forward
26
27
  * * y to left
27
28
  * * z up
28
- * * Note that this is a right handed coordinate system.
29
- * * yaw is a rotation of x towards y, i.e. around positive z:
29
+ * * Note that this is a right handed coordinate system.
30
+ * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):
30
31
  * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`
31
- * * pitch is a rotation that raises x towards z, i.e. rotation around negative y:
32
+ * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):
32
33
  * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`
33
- * * roll is rotation of y towards z, i.e. rotation around positive x:
34
+ * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):
34
35
  * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`
35
- * * The YPR matrix is the product
36
+ * * The YPR matrix is the product
36
37
  * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`
37
- * * Note that this is for "column based" matrix, with vectors appearing to the right
38
- * * Hence a vector is first rotated by roll, then the pitch, finally yaw.
38
+ * * Note that this is for "column based" matrix with vectors multiplying on the right of the matrix.
39
+ * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in
40
+ * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.
39
41
  * @public
40
42
  */
41
43
  export declare class YawPitchRollAngles {
42
- /** The yaw angle. */
44
+ /** The yaw angle: counterclockwise rotation angle around z */
43
45
  yaw: Angle;
44
- /** The pitch angle. */
46
+ /** The pitch angle: **clockwise** rotation angle around y */
45
47
  pitch: Angle;
46
- /** The roll angle. */
48
+ /** The roll angle: counterclockwise rotation angle around x */
47
49
  roll: Angle;
50
+ /**
51
+ * constructor
52
+ * @param yaw counterclockwise rotation angle around z
53
+ * @param pitch **clockwise** rotation angle around y
54
+ * @param roll counterclockwise rotation angle around x
55
+ * */
48
56
  constructor(yaw?: Angle, pitch?: Angle, roll?: Angle);
49
57
  /** Freeze this YawPitchRollAngles */
50
58
  freeze(): Readonly<this>;
51
- /** constructor for YawPitchRollAngles with angles in degrees. */
59
+ /**
60
+ * constructor for YawPitchRollAngles with angles in degrees.
61
+ * @param yawDegrees counterclockwise rotation angle (in degrees) around z
62
+ * @param pitchDegrees **clockwise** rotation angle (in degrees) around y
63
+ * @param rollDegrees counterclockwise rotation angle (in degrees) around x
64
+ * */
52
65
  static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles;
53
- /** constructor for YawPitchRollAngles with angles in radians. */
66
+ /**
67
+ * constructor for YawPitchRollAngles with angles in radians.
68
+ * @param yawRadians counterclockwise rotation angle (in radians) around z
69
+ * @param pitchRadians **clockwise** rotation angle (in radians) around y
70
+ * @param rollRadians counterclockwise rotation angle (in radians) around x
71
+ * */
54
72
  static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles;
55
73
  /** construct a `YawPitchRoll` object from an object with 3 named angles */
56
74
  static fromJSON(json?: YawPitchRollProps): YawPitchRollAngles;
57
75
  /** populate yaw, pitch and roll fields using `Angle.fromJSON` */
58
76
  setFromJSON(json?: YawPitchRollProps): void;
59
- /** Convert to a JSON object of form { pitch: 20 , roll: 29.999999999999996 , yaw: 10 }. Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted. */
77
+ /**
78
+ * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.
79
+ * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.
80
+ **/
60
81
  toJSON(): YawPitchRollProps;
61
82
  /**
62
83
  * Install all rotations from `other` into `this`.
@@ -64,7 +85,7 @@ export declare class YawPitchRollAngles {
64
85
  */
65
86
  setFrom(other: YawPitchRollAngles): void;
66
87
  /**
67
- * * Compare angles between `this` and `other`.
88
+ * Compare angles between `this` and `other`.
68
89
  * * Comparisons are via `isAlmostEqualAllowPeriodShift`.
69
90
  * @param other YawPitchRollAngles source
70
91
  */
@@ -76,35 +97,38 @@ export declare class YawPitchRollAngles {
76
97
  /**
77
98
  * Expand the angles into a (rigid rotation) matrix.
78
99
  *
79
- * * The returned matrix is "rigid" -- unit length rows and columns, and its transpose is its inverse.
80
- * * The "rigid" matrix is always a right handed coordinate system.
100
+ * * The returned matrix is "rigid" (i.e., it has unit length rows and columns, and its transpose is its inverse).
101
+ * * The rigid matrix is always a right handed coordinate system.
81
102
  * @param result optional pre-allocated `Matrix3d`
82
103
  */
83
104
  toMatrix3d(result?: Matrix3d): Matrix3d;
84
- /** Return the largest angle in radians */
85
- maxAbsRadians(): number;
86
- /** Return the sum of the angles in squared radians */
87
- sumSquaredRadians(): number;
88
105
  /** Returns true if this rotation does nothing.
89
106
  * * If allowPeriodShift is false, any nonzero angle is considered a non-identity
90
107
  * * If allowPeriodShift is true, all angles are individually allowed to be any multiple of 360 degrees.
91
108
  */
92
109
  isIdentity(allowPeriodShift?: boolean): boolean;
110
+ /** Return the largest angle in radians */
111
+ maxAbsRadians(): number;
112
+ /** Return the sum of the angles in squared radians */
113
+ sumSquaredRadians(): number;
93
114
  /** Return the largest difference of angles (in radians) between this and other */
94
115
  maxDiffRadians(other: YawPitchRollAngles): number;
95
116
  /** Return the largest angle in degrees. */
96
117
  maxAbsDegrees(): number;
97
118
  /** Return the sum of squared angles in degrees. */
98
119
  sumSquaredDegrees(): number;
120
+ /** Return the largest difference of angles (in degrees) between this and other */
121
+ maxDiffDegrees(other: YawPitchRollAngles): number;
99
122
  /** Return an object from a Transform as an origin and YawPitchRollAngles. */
100
123
  static tryFromTransform(transform: Transform): {
101
124
  origin: Point3d;
102
125
  angles: YawPitchRollAngles | undefined;
103
126
  };
104
- /** Attempts to create a YawPitchRollAngles object from an Matrix3d
105
- * * This conversion fails if the matrix is not rigid (unit rows and columns, transpose is inverse)
127
+ /** Attempts to create a YawPitchRollAngles object from a Matrix3d
128
+ * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
106
129
  * * In the failure case the method's return value is `undefined`.
107
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with a set of angles.
130
+ * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
131
+ * a set of angles.
108
132
  */
109
133
  static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined;
110
134
  }
@@ -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;AAExC,yDAAyD;AACzD;;;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,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAkB;IAC7B,qBAAqB;IACd,GAAG,EAAE,KAAK,CAAC;IAClB,uBAAuB;IAChB,KAAK,EAAE,KAAK,CAAC;IACpB,sBAAsB;IACf,IAAI,EAAE,KAAK,CAAC;gBAEP,GAAG,GAAE,KAAoB,EAAE,KAAK,GAAE,KAAoB,EAAE,IAAI,GAAE,KAAoB;IAK9F,qCAAqC;IAC9B,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC;IAC/B,iEAAiE;WACnD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB;IAG9G,iEAAiE;WACnD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB;IAG9G,2EAA2E;WAC7D,QAAQ,CAAC,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,GAAE,OAAc,GAAG,OAAO;IAU5D,0CAA0C;IACnC,aAAa,IAAI,MAAM;IAG9B,sDAAsD;IAC/C,iBAAiB,IAAI,MAAM;IAGlC,kFAAkF;IAC3E,cAAc,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;IAOxD,2CAA2C;IACpC,aAAa,IAAI,MAAM;IAG9B,mDAAmD;IAC5C,iBAAiB,IAAI,MAAM;IAGlC,kFAAkF;IAC3E,cAAc,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;IAOxD,6EAA6E;WAC/D,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG;QACpD,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;KACxC;IAMD;;;;;OAKG;WACW,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS;CA0EhH"}
@@ -12,39 +12,62 @@ const Geometry_1 = require("../Geometry");
12
12
  const Angle_1 = require("./Angle");
13
13
  const Matrix3d_1 = require("./Matrix3d");
14
14
  const Point3dVector3d_1 = require("./Point3dVector3d");
15
- // cspell:word Tait
16
- /** Three angles that determine the orientation of an object in space. Sometimes referred to as [Tait–Bryan angles](https://en.wikipedia.org/wiki/Euler_angles).
15
+ /**
16
+ * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]
17
+ * (https://en.wikipedia.org/wiki/Euler_angles).
17
18
  * * The matrix construction can be replicated by this logic:
18
19
  * * xyz coordinates have
19
20
  * * x forward
20
21
  * * y to left
21
22
  * * z up
22
- * * Note that this is a right handed coordinate system.
23
- * * yaw is a rotation of x towards y, i.e. around positive z:
23
+ * * Note that this is a right handed coordinate system.
24
+ * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):
24
25
  * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`
25
- * * pitch is a rotation that raises x towards z, i.e. rotation around negative y:
26
+ * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):
26
27
  * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`
27
- * * roll is rotation of y towards z, i.e. rotation around positive x:
28
+ * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):
28
29
  * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`
29
- * * The YPR matrix is the product
30
+ * * The YPR matrix is the product
30
31
  * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`
31
- * * Note that this is for "column based" matrix, with vectors appearing to the right
32
- * * Hence a vector is first rotated by roll, then the pitch, finally yaw.
32
+ * * Note that this is for "column based" matrix with vectors multiplying on the right of the matrix.
33
+ * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in
34
+ * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.
33
35
  * @public
34
36
  */
35
37
  class YawPitchRollAngles {
38
+ /**
39
+ * constructor
40
+ * @param yaw counterclockwise rotation angle around z
41
+ * @param pitch **clockwise** rotation angle around y
42
+ * @param roll counterclockwise rotation angle around x
43
+ * */
36
44
  constructor(yaw = Angle_1.Angle.zero(), pitch = Angle_1.Angle.zero(), roll = Angle_1.Angle.zero()) {
37
45
  this.yaw = yaw;
38
46
  this.pitch = pitch;
39
47
  this.roll = roll;
40
48
  }
41
49
  /** Freeze this YawPitchRollAngles */
42
- freeze() { this.yaw.freeze(); this.pitch.freeze(); this.roll.freeze(); return Object.freeze(this); }
43
- /** constructor for YawPitchRollAngles with angles in degrees. */
50
+ freeze() {
51
+ this.yaw.freeze();
52
+ this.pitch.freeze();
53
+ this.roll.freeze();
54
+ return Object.freeze(this);
55
+ }
56
+ /**
57
+ * constructor for YawPitchRollAngles with angles in degrees.
58
+ * @param yawDegrees counterclockwise rotation angle (in degrees) around z
59
+ * @param pitchDegrees **clockwise** rotation angle (in degrees) around y
60
+ * @param rollDegrees counterclockwise rotation angle (in degrees) around x
61
+ * */
44
62
  static createDegrees(yawDegrees, pitchDegrees, rollDegrees) {
45
63
  return new YawPitchRollAngles(Angle_1.Angle.createDegrees(yawDegrees), Angle_1.Angle.createDegrees(pitchDegrees), Angle_1.Angle.createDegrees(rollDegrees));
46
64
  }
47
- /** constructor for YawPitchRollAngles with angles in radians. */
65
+ /**
66
+ * constructor for YawPitchRollAngles with angles in radians.
67
+ * @param yawRadians counterclockwise rotation angle (in radians) around z
68
+ * @param pitchRadians **clockwise** rotation angle (in radians) around y
69
+ * @param rollRadians counterclockwise rotation angle (in radians) around x
70
+ * */
48
71
  static createRadians(yawRadians, pitchRadians, rollRadians) {
49
72
  return new YawPitchRollAngles(Angle_1.Angle.createRadians(yawRadians), Angle_1.Angle.createRadians(pitchRadians), Angle_1.Angle.createRadians(rollRadians));
50
73
  }
@@ -60,7 +83,10 @@ class YawPitchRollAngles {
60
83
  this.pitch = Angle_1.Angle.fromJSON(json.pitch);
61
84
  this.roll = Angle_1.Angle.fromJSON(json.roll);
62
85
  }
63
- /** Convert to a JSON object of form { pitch: 20 , roll: 29.999999999999996 , yaw: 10 }. Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted. */
86
+ /**
87
+ * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.
88
+ * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.
89
+ **/
64
90
  toJSON() {
65
91
  const val = {};
66
92
  if (!this.pitch.isAlmostZero)
@@ -81,7 +107,7 @@ class YawPitchRollAngles {
81
107
  this.roll.setFrom(other.roll);
82
108
  }
83
109
  /**
84
- * * Compare angles between `this` and `other`.
110
+ * Compare angles between `this` and `other`.
85
111
  * * Comparisons are via `isAlmostEqualAllowPeriodShift`.
86
112
  * @param other YawPitchRollAngles source
87
113
  */
@@ -93,30 +119,47 @@ class YawPitchRollAngles {
93
119
  /**
94
120
  * Make a copy of this YawPitchRollAngles.
95
121
  */
96
- clone() { return new YawPitchRollAngles(this.yaw.clone(), this.pitch.clone(), this.roll.clone()); }
122
+ clone() {
123
+ return new YawPitchRollAngles(this.yaw.clone(), this.pitch.clone(), this.roll.clone());
124
+ }
97
125
  /**
98
126
  * Expand the angles into a (rigid rotation) matrix.
99
127
  *
100
- * * The returned matrix is "rigid" -- unit length rows and columns, and its transpose is its inverse.
101
- * * The "rigid" matrix is always a right handed coordinate system.
128
+ * * The returned matrix is "rigid" (i.e., it has unit length rows and columns, and its transpose is its inverse).
129
+ * * The rigid matrix is always a right handed coordinate system.
102
130
  * @param result optional pre-allocated `Matrix3d`
103
131
  */
104
132
  toMatrix3d(result) {
105
- const c0 = Math.cos(this.yaw.radians);
106
- const s0 = Math.sin(this.yaw.radians);
107
- const c1 = Math.cos(this.pitch.radians);
108
- const s1 = Math.sin(this.pitch.radians);
109
- const c2 = Math.cos(this.roll.radians);
110
- const s2 = Math.sin(this.roll.radians);
111
- return Matrix3d_1.Matrix3d.createRowValues(c0 * c1, -(s0 * c2 + c0 * s1 * s2), (s0 * s2 - c0 * s1 * c2), s0 * c1, (c0 * c2 - s0 * s1 * s2), -(c0 * s2 + s0 * s1 * c2), s1, c1 * s2, c1 * c2, result);
112
- }
113
- /** Return the largest angle in radians */
114
- maxAbsRadians() {
115
- return Geometry_1.Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
116
- }
117
- /** Return the sum of the angles in squared radians */
118
- sumSquaredRadians() {
119
- return Geometry_1.Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
133
+ const cz = Math.cos(this.yaw.radians);
134
+ const sz = Math.sin(this.yaw.radians);
135
+ const cy = Math.cos(this.pitch.radians);
136
+ const sy = Math.sin(this.pitch.radians);
137
+ const cx = Math.cos(this.roll.radians);
138
+ const sx = Math.sin(this.roll.radians);
139
+ /**
140
+ * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where
141
+ * rX, rY, and rZ are base rotation matrixes:
142
+ *
143
+ * const rX = Matrix3d.createRowValues(
144
+ * 1, 0, 0,
145
+ * 0, Math.cos(x), -Math.sin(x),
146
+ * 0, Math.sin(x), Math.cos(x),
147
+ * );
148
+ * const rY = Matrix3d.createRowValues(
149
+ * Math.cos(y), 0, Math.sin(y),
150
+ * 0, 1, 0,
151
+ * -Math.sin(y), 0, Math.cos(y),
152
+ * );
153
+ * const rZ = Matrix3d.createRowValues(
154
+ * Math.cos(z), -Math.sin(z), 0,
155
+ * Math.sin(z), Math.cos(z), 0,
156
+ * 0, 0, 1,
157
+ * );
158
+ *
159
+ * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you
160
+ * can use transpose of rY in the matrix multiplication to get the same result)
161
+ */
162
+ return Matrix3d_1.Matrix3d.createRowValues(cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx), sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx), sy, cy * sx, cy * cx, result);
120
163
  }
121
164
  /** Returns true if this rotation does nothing.
122
165
  * * If allowPeriodShift is false, any nonzero angle is considered a non-identity
@@ -132,52 +175,104 @@ class YawPitchRollAngles {
132
175
  && Angle_1.Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)
133
176
  && Angle_1.Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);
134
177
  }
178
+ /** Return the largest angle in radians */
179
+ maxAbsRadians() {
180
+ return Geometry_1.Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
181
+ }
182
+ /** Return the sum of the angles in squared radians */
183
+ sumSquaredRadians() {
184
+ return Geometry_1.Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
185
+ }
135
186
  /** Return the largest difference of angles (in radians) between this and other */
136
187
  maxDiffRadians(other) {
137
188
  return Math.max(this.yaw.radians - other.yaw.radians, this.pitch.radians - other.pitch.radians, this.roll.radians - other.roll.radians);
138
189
  }
139
190
  /** Return the largest angle in degrees. */
140
- maxAbsDegrees() { return Geometry_1.Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }
191
+ maxAbsDegrees() {
192
+ return Geometry_1.Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);
193
+ }
141
194
  /** Return the sum of squared angles in degrees. */
142
- sumSquaredDegrees() { return Geometry_1.Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }
195
+ sumSquaredDegrees() {
196
+ return Geometry_1.Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);
197
+ }
198
+ /** Return the largest difference of angles (in degrees) between this and other */
199
+ maxDiffDegrees(other) {
200
+ return Math.max(this.yaw.degrees - other.yaw.degrees, this.pitch.degrees - other.pitch.degrees, this.roll.degrees - other.roll.degrees);
201
+ }
143
202
  /** Return an object from a Transform as an origin and YawPitchRollAngles. */
144
203
  static tryFromTransform(transform) {
145
- // bundle up the transform's origin with the angle data extracted from the transform
146
204
  return {
147
- angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),
148
205
  origin: Point3dVector3d_1.Point3d.createFrom(transform.origin),
206
+ angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),
149
207
  };
150
208
  }
151
- /** Attempts to create a YawPitchRollAngles object from an Matrix3d
152
- * * This conversion fails if the matrix is not rigid (unit rows and columns, transpose is inverse)
209
+ /** Attempts to create a YawPitchRollAngles object from a Matrix3d
210
+ * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
153
211
  * * In the failure case the method's return value is `undefined`.
154
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with a set of angles.
212
+ * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
213
+ * a set of angles.
155
214
  */
156
215
  static createFromMatrix3d(matrix, result) {
157
- const s1 = matrix.at(2, 0);
158
- const c1 = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2));
159
- const pitchA = Angle_1.Angle.createAtan2(s1, c1); // with positive cosine
160
- const pitchB = Angle_1.Angle.createAtan2(s1, -c1); // with negative cosine
161
- const angles = result ? result : new YawPitchRollAngles(); // default undefined . . .
162
- if (c1 < Geometry_1.Geometry.smallAngleRadians) { // This is a radians test !!!
216
+ /**
217
+ * The rotation matrix for is
218
+ *
219
+ * Matrix3d.createRowValues(
220
+ * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),
221
+ * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),
222
+ * sy, cy * sx, cy * cx
223
+ * );
224
+ *
225
+ * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)
226
+ */
227
+ const sy = matrix.at(2, 0); // sin(y)
228
+ const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|
229
+ const pitchA = Angle_1.Angle.createAtan2(sy, cy); // with positive cosine
230
+ const pitchB = Angle_1.Angle.createAtan2(sy, -cy); // with negative cosine
231
+ const angles = result ? result : new YawPitchRollAngles();
232
+ /**
233
+ * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.
234
+ * This means x and z can be anything as long as their sum x + z is constant.
235
+ * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).
236
+ * Math details can be found
237
+ * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles
238
+ *
239
+ * The rotation matrix for y = +-90 degrees and x = 0 becomes
240
+ *
241
+ * Matrix3d.createRowValues(
242
+ * 0, -sz, -+cz,
243
+ * 0, cz, -+sz,
244
+ * +-1, 0, 0
245
+ * );
246
+ *
247
+ * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))
248
+ */
249
+ if (cy < Geometry_1.Geometry.smallAngleRadians) {
163
250
  angles.yaw = Angle_1.Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));
164
- angles.pitch = pitchA;
251
+ angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.
165
252
  angles.roll = Angle_1.Angle.createRadians(0.0);
166
253
  }
167
254
  else {
255
+ /**
256
+ * positive cosine
257
+ * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))
258
+ * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))
259
+ */
168
260
  const yawA = Angle_1.Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));
169
261
  const rollA = Angle_1.Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));
262
+ // similar with negative cosine
170
263
  const yawB = Angle_1.Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));
171
264
  const rollB = Angle_1.Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));
265
+ // create YPR
172
266
  const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);
173
267
  const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);
268
+ // decide to pick yprA or yprB with smallest magnitude angles
174
269
  const absFactor = 0.95;
175
- const radiansA = yprA.maxAbsRadians();
176
- const radiansB = yprB.maxAbsRadians();
177
- if (radiansA < absFactor * radiansB) {
270
+ const maxRadiansA = yprA.maxAbsRadians();
271
+ const maxRadiansB = yprB.maxAbsRadians();
272
+ if (maxRadiansA < absFactor * maxRadiansB) {
178
273
  angles.setFrom(yprA);
179
274
  }
180
- else if (radiansB < absFactor * radiansA) {
275
+ else if (maxRadiansB < absFactor * maxRadiansA) {
181
276
  angles.setFrom(yprB);
182
277
  }
183
278
  else {
@@ -191,6 +286,7 @@ class YawPitchRollAngles {
191
286
  }
192
287
  }
193
288
  }
289
+ // sanity check
194
290
  const matrix1 = angles.toMatrix3d();
195
291
  return matrix.maxDiff(matrix1) < Geometry_1.Geometry.smallAngleRadians ? angles : undefined;
196
292
  }
@@ -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;AAgB5C,mBAAmB;AACnB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,kBAAkB;IAQ7B,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,KAAqB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3H,iEAAiE;IAC1D,MAAM,CAAC,aAAa,CAAC,UAAkB,EAAE,YAAoB,EAAE,WAAmB;QACvF,OAAO,IAAI,kBAAkB,CAAC,aAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,aAAK,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,aAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;IACtI,CAAC;IACD,iEAAiE;IAC1D,MAAM,CAAC,aAAa,CAAC,UAAkB,EAAE,YAAoB,EAAE,WAAmB;QACvF,OAAO,IAAI,kBAAkB,CAAC,aAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,aAAK,CAAC,aAAa,CAAC,YAAY,CAAC,EAA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,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,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;AAxKD,gDAwKC","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/** The properties that define [[YawPitchRollAngles]]. */\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// cspell:word Tait\r\n/** Three angles that determine the orientation of an object in space. Sometimes referred to as [Tait–Bryan angles](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:\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:\r\n * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`\r\n * * roll is rotation of y towards z, i.e. rotation around positive x:\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 appearing to the right\r\n * * Hence a vector is first rotated by roll, then the pitch, finally yaw.\r\n * @public\r\n */\r\nexport class YawPitchRollAngles {\r\n /** The yaw angle. */\r\n public yaw: Angle;\r\n /** The pitch angle. */\r\n public pitch: Angle;\r\n /** The roll angle. */\r\n public roll: Angle;\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> { this.yaw.freeze(); this.pitch.freeze(); this.roll.freeze(); return Object.freeze(this); }\r\n /** constructor for YawPitchRollAngles with angles in degrees. */\r\n public static createDegrees(yawDegrees: number, pitchDegrees: number, rollDegrees: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(Angle.createDegrees(yawDegrees), Angle.createDegrees(pitchDegrees), Angle.createDegrees(rollDegrees));\r\n }\r\n /** constructor for YawPitchRollAngles with angles in radians. */\r\n public static createRadians(yawRadians: number, pitchRadians: number, rollRadians: number): YawPitchRollAngles {\r\n return new YawPitchRollAngles(Angle.createRadians(yawRadians), Angle.createRadians(pitchRadians), Angle.createRadians(rollRadians));\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(Angle.fromJSON(json.yaw), Angle.fromJSON(json.pitch), Angle.fromJSON(json.roll));\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 /** Convert to a JSON object of form { pitch: 20 , roll: 29.999999999999996 , yaw: 10 }. Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted. */\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 /**\r\n * Make a copy of this YawPitchRollAngles.\r\n */\r\n public clone() { return new YawPitchRollAngles(this.yaw.clone(), this.pitch.clone(), this.roll.clone()); }\r\n /**\r\n * Expand the angles into a (rigid rotation) matrix.\r\n *\r\n * * The returned matrix is \"rigid\" -- 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 c0 = Math.cos(this.yaw.radians);\r\n const s0 = Math.sin(this.yaw.radians);\r\n const c1 = Math.cos(this.pitch.radians);\r\n const s1 = Math.sin(this.pitch.radians);\r\n const c2 = Math.cos(this.roll.radians);\r\n const s2 = Math.sin(this.roll.radians);\r\n return Matrix3d.createRowValues(c0 * c1, -(s0 * c2 + c0 * s1 * s2), (s0 * s2 - c0 * s1 * c2), s0 * c1, (c0 * c2 - s0 * s1 * s2), -(c0 * s2 + s0 * s1 * c2), s1, c1 * s2, c1 * c2, result);\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 /** 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 difference of angles (in radians) between this and other */\r\n public maxDiffRadians(other: YawPitchRollAngles): number {\r\n return Math.max(this.yaw.radians - other.yaw.radians, this.pitch.radians - other.pitch.radians, this.roll.radians - other.roll.radians);\r\n }\r\n /** Return the largest angle in degrees. */\r\n public maxAbsDegrees(): number { return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }\r\n /** Return the sum of squared angles in degrees. */\r\n public sumSquaredDegrees(): number { return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }\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 // bundle up the transform's origin with the angle data extracted from the transform\r\n return {\r\n angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),\r\n origin: Point3d.createFrom(transform.origin),\r\n };\r\n }\r\n /** Attempts to create a YawPitchRollAngles object from an Matrix3d\r\n * * This conversion fails if the matrix is not rigid (unit rows and columns, 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 a set of angles.\r\n */\r\n public static createFromMatrix3d(matrix: Matrix3d, result?: YawPitchRollAngles): YawPitchRollAngles | undefined {\r\n const s1 = matrix.at(2, 0);\r\n const c1 = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2));\r\n const pitchA = Angle.createAtan2(s1, c1); // with positive cosine\r\n const pitchB = Angle.createAtan2(s1, -c1); // with negative cosine\r\n const angles = result ? result : new YawPitchRollAngles(); // default undefined . . .\r\n if (c1 < Geometry.smallAngleRadians) { // This is a radians test !!!\r\n angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));\r\n angles.pitch = pitchA;\r\n angles.roll = Angle.createRadians(0.0);\r\n } else {\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 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 const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);\r\n const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);\r\n const absFactor = 0.95;\r\n const radiansA = yprA.maxAbsRadians();\r\n const radiansB = yprB.maxAbsRadians();\r\n if (radiansA < absFactor * radiansB) {\r\n angles.setFrom(yprA);\r\n } else if (radiansB < absFactor * radiansA) {\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 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;;;;;SAKK;IACL,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,I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iB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,CAAC;CACF;AAlSD,gDAkSC","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 /**\r\n * Make a copy of this YawPitchRollAngles.\r\n */\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 *\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 /** 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 /** 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 for 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"]}
@@ -114,7 +114,7 @@ export declare class PolyfaceBuilder extends NullGeometryHandler {
114
114
  addPoint(xyz: Point3d): number;
115
115
  /**
116
116
  * Announce point coordinates.
117
- * @deprecated Use addPoint instead.
117
+ * @deprecated in 3.x. Use addPoint instead.
118
118
  */
119
119
  findOrAddPoint(xyz: Point3d): number;
120
120
  /**
@@ -123,7 +123,7 @@ export declare class PolyfaceBuilder extends NullGeometryHandler {
123
123
  addParamXY(x: number, y: number): number;
124
124
  /**
125
125
  * Announce uv parameter coordinates.
126
- * @deprecated Use addParamXY instead.
126
+ * @deprecated in 3.x. Use addParamXY instead.
127
127
  */
128
128
  findOrAddParamXY(x: number, y: number): number;
129
129
  private static _workPointFindOrAddA;
@@ -155,7 +155,7 @@ export declare class PolyfaceBuilder extends NullGeometryHandler {
155
155
  addParamInGrowableXYArray(data: GrowableXYArray, index: number): number | undefined;
156
156
  /**
157
157
  * Announce uv parameter coordinates.
158
- * @deprecated Use addParamInGrowableXYArray instead.
158
+ * @deprecated in 3.x. Use addParamInGrowableXYArray instead.
159
159
  */
160
160
  findOrAddParamInGrowableXYArray(data: GrowableXYArray, index: number): number | undefined;
161
161
  /**
@@ -177,7 +177,7 @@ export declare class PolyfaceBuilder extends NullGeometryHandler {
177
177
  addPointXYZ(x: number, y: number, z: number): number;
178
178
  /**
179
179
  * Announce point coordinates.
180
- * @deprecated Use addPointXYZ instead.
180
+ * @deprecated in 3.x. Use addPointXYZ instead.
181
181
  */
182
182
  findOrAddPointXYZ(x: number, y: number, z: number): number;
183
183
  /** Returns a transform who can be applied to points on a triangular facet in order to obtain UV parameters. */
@@ -302,7 +302,7 @@ class PolyfaceBuilder extends GeometryHandler_1.NullGeometryHandler {
302
302
  }
303
303
  /**
304
304
  * Announce point coordinates.
305
- * @deprecated Use addPoint instead.
305
+ * @deprecated in 3.x. Use addPoint instead.
306
306
  */
307
307
  findOrAddPoint(xyz) {
308
308
  return this.addPoint(xyz);
@@ -315,7 +315,7 @@ class PolyfaceBuilder extends GeometryHandler_1.NullGeometryHandler {
315
315
  }
316
316
  /**
317
317
  * Announce uv parameter coordinates.
318
- * @deprecated Use addParamXY instead.
318
+ * @deprecated in 3.x. Use addParamXY instead.
319
319
  */
320
320
  findOrAddParamXY(x, y) {
321
321
  return this.addParamXY(x, y);
@@ -378,7 +378,7 @@ class PolyfaceBuilder extends GeometryHandler_1.NullGeometryHandler {
378
378
  }
379
379
  /**
380
380
  * Announce uv parameter coordinates.
381
- * @deprecated Use addParamInGrowableXYArray instead.
381
+ * @deprecated in 3.x. Use addParamInGrowableXYArray instead.
382
382
  */
383
383
  findOrAddParamInGrowableXYArray(data, index) {
384
384
  return this.addParamInGrowableXYArray(data, index);
@@ -418,7 +418,7 @@ class PolyfaceBuilder extends GeometryHandler_1.NullGeometryHandler {
418
418
  }
419
419
  /**
420
420
  * Announce point coordinates.
421
- * @deprecated Use addPointXYZ instead.
421
+ * @deprecated in 3.x. Use addPointXYZ instead.
422
422
  */
423
423
  findOrAddPointXYZ(x, y, z) {
424
424
  return this.addPointXYZ(x, y, z);