@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"}
@@ -9,39 +9,62 @@ import { Geometry } from "../Geometry";
9
9
  import { Angle } from "./Angle";
10
10
  import { Matrix3d } from "./Matrix3d";
11
11
  import { Point3d } from "./Point3dVector3d";
12
- // cspell:word Tait
13
- /** 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).
12
+ /**
13
+ * Three angles that determine the orientation of an object in space, sometimes referred to as [Tait–Bryan angles]
14
+ * (https://en.wikipedia.org/wiki/Euler_angles).
14
15
  * * The matrix construction can be replicated by this logic:
15
16
  * * xyz coordinates have
16
17
  * * x forward
17
18
  * * y to left
18
19
  * * z up
19
- * * Note that this is a right handed coordinate system.
20
- * * yaw is a rotation of x towards y, i.e. around positive z:
20
+ * * Note that this is a right handed coordinate system.
21
+ * * yaw is a rotation of x towards y, i.e. around positive z (counterclockwise):
21
22
  * * `yawMatrix = Matrix3d.createRotationAroundAxisIndex(2, Angle.createDegrees(yawDegrees));`
22
- * * pitch is a rotation that raises x towards z, i.e. rotation around negative y:
23
+ * * pitch is a rotation that raises x towards z, i.e. rotation around **negative y** (**clockwise**):
23
24
  * * `pitchMatrix = Matrix3d.createRotationAroundAxisIndex(1, Angle.createDegrees(-pitchDegrees));`
24
- * * roll is rotation of y towards z, i.e. rotation around positive x:
25
+ * * roll is rotation of y towards z, i.e. rotation around positive x (counterclockwise):
25
26
  * * `rollMatrix = Matrix3d.createRotationAroundAxisIndex(0, Angle.createDegrees(rollDegrees));`
26
- * * The YPR matrix is the product
27
+ * * The YPR matrix is the product
27
28
  * * `result = yawMatrix.multiplyMatrixMatrix(pitchMatrix.multiplyMatrixMatrix(rollMatrix));`
28
- * * Note that this is for "column based" matrix, with vectors appearing to the right
29
- * * Hence a vector is first rotated by roll, then the pitch, finally yaw.
29
+ * * Note that this is for "column based" matrix with vectors multiplying on the right of the matrix.
30
+ * Hence a vector is first rotated by roll, then the pitch, finally yaw. So multiplication order in
31
+ * the sense of AxisOrder is `RPY` (i.e., XYZ), in contrast to the familiar name `YPR`.
30
32
  * @public
31
33
  */
32
34
  export class YawPitchRollAngles {
35
+ /**
36
+ * constructor
37
+ * @param yaw counterclockwise rotation angle around z
38
+ * @param pitch **clockwise** rotation angle around y
39
+ * @param roll counterclockwise rotation angle around x
40
+ * */
33
41
  constructor(yaw = Angle.zero(), pitch = Angle.zero(), roll = Angle.zero()) {
34
42
  this.yaw = yaw;
35
43
  this.pitch = pitch;
36
44
  this.roll = roll;
37
45
  }
38
46
  /** Freeze this YawPitchRollAngles */
39
- freeze() { this.yaw.freeze(); this.pitch.freeze(); this.roll.freeze(); return Object.freeze(this); }
40
- /** constructor for YawPitchRollAngles with angles in degrees. */
47
+ freeze() {
48
+ this.yaw.freeze();
49
+ this.pitch.freeze();
50
+ this.roll.freeze();
51
+ return Object.freeze(this);
52
+ }
53
+ /**
54
+ * constructor for YawPitchRollAngles with angles in degrees.
55
+ * @param yawDegrees counterclockwise rotation angle (in degrees) around z
56
+ * @param pitchDegrees **clockwise** rotation angle (in degrees) around y
57
+ * @param rollDegrees counterclockwise rotation angle (in degrees) around x
58
+ * */
41
59
  static createDegrees(yawDegrees, pitchDegrees, rollDegrees) {
42
60
  return new YawPitchRollAngles(Angle.createDegrees(yawDegrees), Angle.createDegrees(pitchDegrees), Angle.createDegrees(rollDegrees));
43
61
  }
44
- /** constructor for YawPitchRollAngles with angles in radians. */
62
+ /**
63
+ * constructor for YawPitchRollAngles with angles in radians.
64
+ * @param yawRadians counterclockwise rotation angle (in radians) around z
65
+ * @param pitchRadians **clockwise** rotation angle (in radians) around y
66
+ * @param rollRadians counterclockwise rotation angle (in radians) around x
67
+ * */
45
68
  static createRadians(yawRadians, pitchRadians, rollRadians) {
46
69
  return new YawPitchRollAngles(Angle.createRadians(yawRadians), Angle.createRadians(pitchRadians), Angle.createRadians(rollRadians));
47
70
  }
@@ -57,7 +80,10 @@ export class YawPitchRollAngles {
57
80
  this.pitch = Angle.fromJSON(json.pitch);
58
81
  this.roll = Angle.fromJSON(json.roll);
59
82
  }
60
- /** 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. */
83
+ /**
84
+ * Convert to a JSON object of form { pitch: 20 , roll: 30 , yaw: 10 }. Angles are in degrees.
85
+ * Any values that are exactly zero (with tolerance `Geometry.smallAngleRadians`) are omitted.
86
+ **/
61
87
  toJSON() {
62
88
  const val = {};
63
89
  if (!this.pitch.isAlmostZero)
@@ -78,7 +104,7 @@ export class YawPitchRollAngles {
78
104
  this.roll.setFrom(other.roll);
79
105
  }
80
106
  /**
81
- * * Compare angles between `this` and `other`.
107
+ * Compare angles between `this` and `other`.
82
108
  * * Comparisons are via `isAlmostEqualAllowPeriodShift`.
83
109
  * @param other YawPitchRollAngles source
84
110
  */
@@ -90,30 +116,47 @@ export class YawPitchRollAngles {
90
116
  /**
91
117
  * Make a copy of this YawPitchRollAngles.
92
118
  */
93
- clone() { return new YawPitchRollAngles(this.yaw.clone(), this.pitch.clone(), this.roll.clone()); }
119
+ clone() {
120
+ return new YawPitchRollAngles(this.yaw.clone(), this.pitch.clone(), this.roll.clone());
121
+ }
94
122
  /**
95
123
  * Expand the angles into a (rigid rotation) matrix.
96
124
  *
97
- * * The returned matrix is "rigid" -- unit length rows and columns, and its transpose is its inverse.
98
- * * The "rigid" matrix is always a right handed coordinate system.
125
+ * * The returned matrix is "rigid" (i.e., it has unit length rows and columns, and its transpose is its inverse).
126
+ * * The rigid matrix is always a right handed coordinate system.
99
127
  * @param result optional pre-allocated `Matrix3d`
100
128
  */
101
129
  toMatrix3d(result) {
102
- const c0 = Math.cos(this.yaw.radians);
103
- const s0 = Math.sin(this.yaw.radians);
104
- const c1 = Math.cos(this.pitch.radians);
105
- const s1 = Math.sin(this.pitch.radians);
106
- const c2 = Math.cos(this.roll.radians);
107
- const s2 = Math.sin(this.roll.radians);
108
- 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);
109
- }
110
- /** Return the largest angle in radians */
111
- maxAbsRadians() {
112
- return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
113
- }
114
- /** Return the sum of the angles in squared radians */
115
- sumSquaredRadians() {
116
- return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
130
+ const cz = Math.cos(this.yaw.radians);
131
+ const sz = Math.sin(this.yaw.radians);
132
+ const cy = Math.cos(this.pitch.radians);
133
+ const sy = Math.sin(this.pitch.radians);
134
+ const cx = Math.cos(this.roll.radians);
135
+ const sx = Math.sin(this.roll.radians);
136
+ /**
137
+ * The axis order is XYZ (i.e., RPY) so the rotation matrix is calculated via rZ*rY*rX where
138
+ * rX, rY, and rZ are base rotation matrixes:
139
+ *
140
+ * const rX = Matrix3d.createRowValues(
141
+ * 1, 0, 0,
142
+ * 0, Math.cos(x), -Math.sin(x),
143
+ * 0, Math.sin(x), Math.cos(x),
144
+ * );
145
+ * const rY = Matrix3d.createRowValues(
146
+ * Math.cos(y), 0, Math.sin(y),
147
+ * 0, 1, 0,
148
+ * -Math.sin(y), 0, Math.cos(y),
149
+ * );
150
+ * const rZ = Matrix3d.createRowValues(
151
+ * Math.cos(z), -Math.sin(z), 0,
152
+ * Math.sin(z), Math.cos(z), 0,
153
+ * 0, 0, 1,
154
+ * );
155
+ *
156
+ * Then we replace sin(y) with -sin(y) because y rotation (i.e., pitch) is clockwise (alternatively, you
157
+ * can use transpose of rY in the matrix multiplication to get the same result)
158
+ */
159
+ return 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);
117
160
  }
118
161
  /** Returns true if this rotation does nothing.
119
162
  * * If allowPeriodShift is false, any nonzero angle is considered a non-identity
@@ -129,52 +172,104 @@ export class YawPitchRollAngles {
129
172
  && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.pitch.radians)
130
173
  && Angle.isAlmostEqualRadiansNoPeriodShift(0.0, this.roll.radians);
131
174
  }
175
+ /** Return the largest angle in radians */
176
+ maxAbsRadians() {
177
+ return Geometry.maxAbsXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
178
+ }
179
+ /** Return the sum of the angles in squared radians */
180
+ sumSquaredRadians() {
181
+ return Geometry.hypotenuseSquaredXYZ(this.yaw.radians, this.pitch.radians, this.roll.radians);
182
+ }
132
183
  /** Return the largest difference of angles (in radians) between this and other */
133
184
  maxDiffRadians(other) {
134
185
  return Math.max(this.yaw.radians - other.yaw.radians, this.pitch.radians - other.pitch.radians, this.roll.radians - other.roll.radians);
135
186
  }
136
187
  /** Return the largest angle in degrees. */
137
- maxAbsDegrees() { return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }
188
+ maxAbsDegrees() {
189
+ return Geometry.maxAbsXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);
190
+ }
138
191
  /** Return the sum of squared angles in degrees. */
139
- sumSquaredDegrees() { return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees); }
192
+ sumSquaredDegrees() {
193
+ return Geometry.hypotenuseSquaredXYZ(this.yaw.degrees, this.pitch.degrees, this.roll.degrees);
194
+ }
195
+ /** Return the largest difference of angles (in degrees) between this and other */
196
+ maxDiffDegrees(other) {
197
+ return Math.max(this.yaw.degrees - other.yaw.degrees, this.pitch.degrees - other.pitch.degrees, this.roll.degrees - other.roll.degrees);
198
+ }
140
199
  /** Return an object from a Transform as an origin and YawPitchRollAngles. */
141
200
  static tryFromTransform(transform) {
142
- // bundle up the transform's origin with the angle data extracted from the transform
143
201
  return {
144
- angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),
145
202
  origin: Point3d.createFrom(transform.origin),
203
+ angles: YawPitchRollAngles.createFromMatrix3d(transform.matrix),
146
204
  };
147
205
  }
148
- /** Attempts to create a YawPitchRollAngles object from an Matrix3d
149
- * * This conversion fails if the matrix is not rigid (unit rows and columns, transpose is inverse)
206
+ /** Attempts to create a YawPitchRollAngles object from a Matrix3d
207
+ * * This conversion fails if the matrix is not rigid (unit rows and columns, and transpose is inverse)
150
208
  * * In the failure case the method's return value is `undefined`.
151
- * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with a set of angles.
209
+ * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
210
+ * a set of angles.
152
211
  */
153
212
  static createFromMatrix3d(matrix, result) {
154
- const s1 = matrix.at(2, 0);
155
- const c1 = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2));
156
- const pitchA = Angle.createAtan2(s1, c1); // with positive cosine
157
- const pitchB = Angle.createAtan2(s1, -c1); // with negative cosine
158
- const angles = result ? result : new YawPitchRollAngles(); // default undefined . . .
159
- if (c1 < Geometry.smallAngleRadians) { // This is a radians test !!!
213
+ /**
214
+ * The rotation matrix for is
215
+ *
216
+ * Matrix3d.createRowValues(
217
+ * cz * cy, -(sz * cx + cz * sy * sx), (sz * sx - cz * sy * cx),
218
+ * sz * cy, (cz * cx - sz * sy * sx), -(cz * sx + sz * sy * cx),
219
+ * sy, cy * sx, cy * cx
220
+ * );
221
+ *
222
+ * where cx = cos(x), sx = sin(x), cy = cos(y), sy = sin(y), cz = cos(z), and sz = sin(z)
223
+ */
224
+ const sy = matrix.at(2, 0); // sin(y)
225
+ const cy = Math.sqrt(matrix.at(2, 1) * matrix.at(2, 1) + matrix.at(2, 2) * matrix.at(2, 2)); // |cos(y)|
226
+ const pitchA = Angle.createAtan2(sy, cy); // with positive cosine
227
+ const pitchB = Angle.createAtan2(sy, -cy); // with negative cosine
228
+ const angles = result ? result : new YawPitchRollAngles();
229
+ /**
230
+ * If cos(y) = 0 then y = +-90 degrees so we have a gimbal lock.
231
+ * This means x and z can be anything as long as their sum x + z is constant.
232
+ * so we can pick z = 0 and calculate x (or pick x = 0 and calculate z).
233
+ * Math details can be found
234
+ * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles
235
+ *
236
+ * The rotation matrix for y = +-90 degrees and x = 0 becomes
237
+ *
238
+ * Matrix3d.createRowValues(
239
+ * 0, -sz, -+cz,
240
+ * 0, cz, -+sz,
241
+ * +-1, 0, 0
242
+ * );
243
+ *
244
+ * so z = atan(sz/cz) = atan(-matrix.at(0, 1), matrix.at(1, 1))
245
+ */
246
+ if (cy < Geometry.smallAngleRadians) {
160
247
  angles.yaw = Angle.createAtan2(-matrix.at(0, 1), matrix.at(1, 1));
161
- angles.pitch = pitchA;
248
+ angles.pitch = pitchA; // this is an arbitrary choice. can pick pitchB instead.
162
249
  angles.roll = Angle.createRadians(0.0);
163
250
  }
164
251
  else {
252
+ /**
253
+ * positive cosine
254
+ * z = atan(sz/cz) = atan(matrix.at(1, 0), matrix.at(0, 0))
255
+ * x = atan(sx/cx) = atan(matrix.at(2, 1), matrix.at(2, 2))
256
+ */
165
257
  const yawA = Angle.createAtan2(matrix.at(1, 0), matrix.at(0, 0));
166
258
  const rollA = Angle.createAtan2(matrix.at(2, 1), matrix.at(2, 2));
259
+ // similar with negative cosine
167
260
  const yawB = Angle.createAtan2(-matrix.at(1, 0), -matrix.at(0, 0));
168
261
  const rollB = Angle.createAtan2(-matrix.at(2, 1), -matrix.at(2, 2));
262
+ // create YPR
169
263
  const yprA = new YawPitchRollAngles(yawA, pitchA, rollA);
170
264
  const yprB = new YawPitchRollAngles(yawB, pitchB, rollB);
265
+ // decide to pick yprA or yprB with smallest magnitude angles
171
266
  const absFactor = 0.95;
172
- const radiansA = yprA.maxAbsRadians();
173
- const radiansB = yprB.maxAbsRadians();
174
- if (radiansA < absFactor * radiansB) {
267
+ const maxRadiansA = yprA.maxAbsRadians();
268
+ const maxRadiansB = yprB.maxAbsRadians();
269
+ if (maxRadiansA < absFactor * maxRadiansB) {
175
270
  angles.setFrom(yprA);
176
271
  }
177
- else if (radiansB < absFactor * radiansA) {
272
+ else if (maxRadiansB < absFactor * maxRadiansA) {
178
273
  angles.setFrom(yprB);
179
274
  }
180
275
  else {
@@ -188,6 +283,7 @@ export class YawPitchRollAngles {
188
283
  }
189
284
  }
190
285
  }
286
+ // sanity check
191
287
  const matrix1 = angles.toMatrix3d();
192
288
  return matrix.maxDiff(matrix1) < Geometry.smallAngleRadians ? angles : undefined;
193
289
  }
@@ -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,C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F;SACF;QACD,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/** 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,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;;;;;SAKK;IACL,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,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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S,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 /**\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. */
@@ -299,7 +299,7 @@ export class PolyfaceBuilder extends NullGeometryHandler {
299
299
  }
300
300
  /**
301
301
  * Announce point coordinates.
302
- * @deprecated Use addPoint instead.
302
+ * @deprecated in 3.x. Use addPoint instead.
303
303
  */
304
304
  findOrAddPoint(xyz) {
305
305
  return this.addPoint(xyz);
@@ -312,7 +312,7 @@ export class PolyfaceBuilder extends NullGeometryHandler {
312
312
  }
313
313
  /**
314
314
  * Announce uv parameter coordinates.
315
- * @deprecated Use addParamXY instead.
315
+ * @deprecated in 3.x. Use addParamXY instead.
316
316
  */
317
317
  findOrAddParamXY(x, y) {
318
318
  return this.addParamXY(x, y);
@@ -375,7 +375,7 @@ export class PolyfaceBuilder extends NullGeometryHandler {
375
375
  }
376
376
  /**
377
377
  * Announce uv parameter coordinates.
378
- * @deprecated Use addParamInGrowableXYArray instead.
378
+ * @deprecated in 3.x. Use addParamInGrowableXYArray instead.
379
379
  */
380
380
  findOrAddParamInGrowableXYArray(data, index) {
381
381
  return this.addParamInGrowableXYArray(data, index);
@@ -415,7 +415,7 @@ export class PolyfaceBuilder extends NullGeometryHandler {
415
415
  }
416
416
  /**
417
417
  * Announce point coordinates.
418
- * @deprecated Use addPointXYZ instead.
418
+ * @deprecated in 3.x. Use addPointXYZ instead.
419
419
  */
420
420
  findOrAddPointXYZ(x, y, z) {
421
421
  return this.addPointXYZ(x, y, z);