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

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 (171) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Geometry.d.ts +28 -17
  4. package/lib/cjs/Geometry.d.ts.map +1 -1
  5. package/lib/cjs/Geometry.js +52 -25
  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 +29 -31
  10. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  11. package/lib/cjs/curve/CurveCurve.d.ts +11 -8
  12. package/lib/cjs/curve/CurveCurve.d.ts.map +1 -1
  13. package/lib/cjs/curve/CurveCurve.js +16 -12
  14. package/lib/cjs/curve/CurveCurve.js.map +1 -1
  15. package/lib/cjs/curve/CurveCurveIntersectXY.d.ts +5 -1
  16. package/lib/cjs/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  17. package/lib/cjs/curve/CurveCurveIntersectXY.js +11 -10
  18. package/lib/cjs/curve/CurveCurveIntersectXY.js.map +1 -1
  19. package/lib/cjs/geometry3d/Angle.d.ts +19 -0
  20. package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
  21. package/lib/cjs/geometry3d/Angle.js +39 -0
  22. package/lib/cjs/geometry3d/Angle.js.map +1 -1
  23. package/lib/cjs/geometry3d/AngleSweep.d.ts +1 -0
  24. package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
  25. package/lib/cjs/geometry3d/AngleSweep.js +1 -0
  26. package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
  27. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +1 -0
  28. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  29. package/lib/cjs/geometry3d/CoincidentGeometryOps.js +3 -0
  30. package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
  31. package/lib/cjs/geometry3d/GrowableXYArray.d.ts +1 -1
  32. package/lib/cjs/geometry3d/GrowableXYArray.js +1 -1
  33. package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
  34. package/lib/cjs/geometry3d/Matrix3d.d.ts +369 -254
  35. package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
  36. package/lib/cjs/geometry3d/Matrix3d.js +807 -660
  37. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  38. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts +71 -14
  39. package/lib/cjs/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  40. package/lib/cjs/geometry3d/OrderedRotationAngles.js +204 -114
  41. package/lib/cjs/geometry3d/OrderedRotationAngles.js.map +1 -1
  42. package/lib/cjs/geometry3d/Point2dVector2d.d.ts +1 -0
  43. package/lib/cjs/geometry3d/Point2dVector2d.d.ts.map +1 -1
  44. package/lib/cjs/geometry3d/Point2dVector2d.js +1 -0
  45. package/lib/cjs/geometry3d/Point2dVector2d.js.map +1 -1
  46. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +16 -16
  47. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  48. package/lib/cjs/geometry3d/Point3dVector3d.js +21 -18
  49. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  50. package/lib/cjs/geometry3d/Segment1d.d.ts +1 -1
  51. package/lib/cjs/geometry3d/Segment1d.js +1 -1
  52. package/lib/cjs/geometry3d/Segment1d.js.map +1 -1
  53. package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts +49 -25
  54. package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
  55. package/lib/cjs/geometry3d/YawPitchRollAngles.js +146 -50
  56. package/lib/cjs/geometry3d/YawPitchRollAngles.js.map +1 -1
  57. package/lib/cjs/numerics/Polynomials.d.ts +12 -0
  58. package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
  59. package/lib/cjs/numerics/Polynomials.js +14 -0
  60. package/lib/cjs/numerics/Polynomials.js.map +1 -1
  61. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +5 -4
  62. package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
  63. package/lib/cjs/polyface/PolyfaceBuilder.js +50 -10
  64. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  65. package/lib/cjs/polyface/PolyfaceQuery.d.ts +82 -0
  66. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  67. package/lib/cjs/polyface/PolyfaceQuery.js +150 -1
  68. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  69. package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts +202 -0
  70. package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -0
  71. package/lib/cjs/polyface/multiclip/OffsetMeshContext.js +1038 -0
  72. package/lib/cjs/polyface/multiclip/OffsetMeshContext.js.map +1 -0
  73. package/lib/cjs/serialization/GeometrySamples.d.ts +4 -1
  74. package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
  75. package/lib/cjs/serialization/GeometrySamples.js +14 -6
  76. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  77. package/lib/cjs/serialization/IModelJsonSchema.d.ts +1 -1
  78. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  79. package/lib/cjs/topology/Graph.d.ts +113 -7
  80. package/lib/cjs/topology/Graph.d.ts.map +1 -1
  81. package/lib/cjs/topology/Graph.js +185 -7
  82. package/lib/cjs/topology/Graph.js.map +1 -1
  83. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +38 -0
  84. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts.map +1 -0
  85. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js +82 -0
  86. package/lib/cjs/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -0
  87. package/lib/esm/Geometry.d.ts +28 -17
  88. package/lib/esm/Geometry.d.ts.map +1 -1
  89. package/lib/esm/Geometry.js +52 -25
  90. package/lib/esm/Geometry.js.map +1 -1
  91. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +10 -6
  92. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  93. package/lib/esm/curve/CurveChainWithDistanceIndex.js +30 -32
  94. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  95. package/lib/esm/curve/CurveCurve.d.ts +11 -8
  96. package/lib/esm/curve/CurveCurve.d.ts.map +1 -1
  97. package/lib/esm/curve/CurveCurve.js +16 -12
  98. package/lib/esm/curve/CurveCurve.js.map +1 -1
  99. package/lib/esm/curve/CurveCurveIntersectXY.d.ts +5 -1
  100. package/lib/esm/curve/CurveCurveIntersectXY.d.ts.map +1 -1
  101. package/lib/esm/curve/CurveCurveIntersectXY.js +11 -10
  102. package/lib/esm/curve/CurveCurveIntersectXY.js.map +1 -1
  103. package/lib/esm/geometry3d/Angle.d.ts +19 -0
  104. package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
  105. package/lib/esm/geometry3d/Angle.js +39 -0
  106. package/lib/esm/geometry3d/Angle.js.map +1 -1
  107. package/lib/esm/geometry3d/AngleSweep.d.ts +1 -0
  108. package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
  109. package/lib/esm/geometry3d/AngleSweep.js +1 -0
  110. package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
  111. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +1 -0
  112. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  113. package/lib/esm/geometry3d/CoincidentGeometryOps.js +3 -0
  114. package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
  115. package/lib/esm/geometry3d/GrowableXYArray.d.ts +1 -1
  116. package/lib/esm/geometry3d/GrowableXYArray.js +1 -1
  117. package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
  118. package/lib/esm/geometry3d/Matrix3d.d.ts +369 -254
  119. package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
  120. package/lib/esm/geometry3d/Matrix3d.js +807 -660
  121. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  122. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts +71 -14
  123. package/lib/esm/geometry3d/OrderedRotationAngles.d.ts.map +1 -1
  124. package/lib/esm/geometry3d/OrderedRotationAngles.js +205 -115
  125. package/lib/esm/geometry3d/OrderedRotationAngles.js.map +1 -1
  126. package/lib/esm/geometry3d/Point2dVector2d.d.ts +1 -0
  127. package/lib/esm/geometry3d/Point2dVector2d.d.ts.map +1 -1
  128. package/lib/esm/geometry3d/Point2dVector2d.js +1 -0
  129. package/lib/esm/geometry3d/Point2dVector2d.js.map +1 -1
  130. package/lib/esm/geometry3d/Point3dVector3d.d.ts +16 -16
  131. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  132. package/lib/esm/geometry3d/Point3dVector3d.js +21 -18
  133. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  134. package/lib/esm/geometry3d/Segment1d.d.ts +1 -1
  135. package/lib/esm/geometry3d/Segment1d.js +1 -1
  136. package/lib/esm/geometry3d/Segment1d.js.map +1 -1
  137. package/lib/esm/geometry3d/YawPitchRollAngles.d.ts +49 -25
  138. package/lib/esm/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
  139. package/lib/esm/geometry3d/YawPitchRollAngles.js +146 -50
  140. package/lib/esm/geometry3d/YawPitchRollAngles.js.map +1 -1
  141. package/lib/esm/numerics/Polynomials.d.ts +12 -0
  142. package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
  143. package/lib/esm/numerics/Polynomials.js +14 -0
  144. package/lib/esm/numerics/Polynomials.js.map +1 -1
  145. package/lib/esm/polyface/PolyfaceBuilder.d.ts +5 -4
  146. package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
  147. package/lib/esm/polyface/PolyfaceBuilder.js +50 -10
  148. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  149. package/lib/esm/polyface/PolyfaceQuery.d.ts +82 -0
  150. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  151. package/lib/esm/polyface/PolyfaceQuery.js +148 -0
  152. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  153. package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts +202 -0
  154. package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -0
  155. package/lib/esm/polyface/multiclip/OffsetMeshContext.js +1032 -0
  156. package/lib/esm/polyface/multiclip/OffsetMeshContext.js.map +1 -0
  157. package/lib/esm/serialization/GeometrySamples.d.ts +4 -1
  158. package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
  159. package/lib/esm/serialization/GeometrySamples.js +14 -6
  160. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  161. package/lib/esm/serialization/IModelJsonSchema.d.ts +1 -1
  162. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  163. package/lib/esm/topology/Graph.d.ts +113 -7
  164. package/lib/esm/topology/Graph.d.ts.map +1 -1
  165. package/lib/esm/topology/Graph.js +185 -7
  166. package/lib/esm/topology/Graph.js.map +1 -1
  167. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts +38 -0
  168. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.d.ts.map +1 -0
  169. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js +78 -0
  170. package/lib/esm/topology/HalfEdgeGraphFromIndexedLoopsContext.js.map +1 -0
  171. package/package.json +4 -4
@@ -5,19 +5,28 @@ import { AxisOrder } from "../Geometry";
5
5
  import { Angle } from "./Angle";
6
6
  import { Matrix3d } from "./Matrix3d";
7
7
  /**
8
- * * OrderedRotationAngles represents a non-trivial rotation using three simple axis rotation angles, and an order in which to apply them.
9
- * * This class accommodates application-specific interpretation of "Multiplying 3 rotation matrices" with regard to
8
+ * represents a non-trivial rotation using three simple axis rotation angles and an order in which to apply them.
9
+ * * This class accommodates application-specific interpretation of "multiplying 3 rotation matrices" with regard to
10
10
  * * Whether a "vector" is a "row" or a "column"
11
- * * The order in which the X,Y, Z rotations are applied.
11
+ * * The order in which the X,Y,Z rotations are applied.
12
+ * * This class bakes in angle rotation directions via create functions (i.e., createRadians, createDegrees, and
13
+ * createAngles) so you can define each of the 3 rotations to be clockwise or counterclockwise. The default
14
+ * rotation is counterclockwise.
12
15
  * * Within the imodel geometry library, the preferred rotation order is encapsulated in `YawPitchRollAngles`.
13
16
  * @alpha
14
17
  */
15
18
  export declare class OrderedRotationAngles {
19
+ /** rotation around x */
16
20
  private _x;
21
+ /** rotation around y */
17
22
  private _y;
23
+ /** rotation around z */
18
24
  private _z;
25
+ /** rotation order. For example XYZ means to rotate around x axis first, then y axis, and finally Z axis */
19
26
  private _order;
27
+ /** treat vectors as matrix columns */
20
28
  private static _sTreatVectorsAsColumns;
29
+ /** constructor */
21
30
  private constructor();
22
31
  /** (Property accessor) Return the `AxisOrder` controlling matrix multiplication order. */
23
32
  get order(): AxisOrder;
@@ -39,23 +48,71 @@ export declare class OrderedRotationAngles {
39
48
  get zDegrees(): number;
40
49
  /** (Property accessor) Return the angle of rotation around z, in radians */
41
50
  get zRadians(): number;
42
- /** Flag controlling whether vectors are treated as rows or as columns */
51
+ /** the flag controlling whether vectors are treated as rows or as columns */
43
52
  static get treatVectorsAsColumns(): boolean;
44
53
  static set treatVectorsAsColumns(value: boolean);
45
- /** Create an OrderedRotationAngles from three angles and an ordering in which to apply them when rotating.
54
+ /**
55
+ * Create an OrderedRotationAngles from three angles (in radians), an ordering in which to apply them when
56
+ * rotating, and a flag triple controlling whether direction of x,y,z is clockwise or counterclockwise.
57
+ * @param xRadians rotation around x
58
+ * @param yRadians rotation around y
59
+ * @param zRadians rotation around z
60
+ * @param order left to right order of axis names identifies the order that rotations are applied.
61
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
62
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
63
+ * matrix multiplication would be zRot*yRot*xRot
64
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
65
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
66
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
67
+ * @param result caller-allocated OrderedRotationAngles
68
+ */
69
+ static createRadians(xRadians: number, yRadians: number, zRadians: number, order: AxisOrder, xyzRotationIsClockwise?: [boolean, boolean, boolean], result?: OrderedRotationAngles): OrderedRotationAngles;
70
+ /**
71
+ * Create an OrderedRotationAngles from three angles (in degrees) and an ordering in which to apply
72
+ * them when rotating.
73
+ * @param xDegrees rotation around x
74
+ * @param yDegrees rotation around y
75
+ * @param zDegrees rotation around z
76
+ * @param order left to right order of axis names identifies the order that rotations are applied.
77
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
78
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
79
+ * matrix multiplication would be zRot*yRot*xRot
80
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
81
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
82
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
83
+ * @param result caller-allocated OrderedRotationAngles
84
+ */
85
+ static createDegrees(xDegrees: number, yDegrees: number, zDegrees: number, order: AxisOrder, xyzRotationIsClockwise?: [boolean, boolean, boolean], result?: OrderedRotationAngles): OrderedRotationAngles;
86
+ /**
87
+ * Create an OrderedRotationAngles from three angles, an ordering in which to apply them when rotating,
88
+ * and a flag triple controlling whether direction of x,y,z is clockwise or counterclockwise.
46
89
  * @param xRotation rotation around x
47
90
  * @param yRotation rotation around y
48
91
  * @param zRotation rotation around z
49
- * @param axisOrder right to left order of axis names identifies the order that rotations are applied to xyz data.
92
+ * @param order left to right order of axis names identifies the order that rotations are applied
93
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
94
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
95
+ * matrix multiplication would be zRot*yRot*xRot
96
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
97
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
98
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
99
+ * @param result caller-allocated OrderedRotationAngles
50
100
  */
51
- static createAngles(xRotation: Angle, yRotation: Angle, zRotation: Angle, order: AxisOrder, result?: OrderedRotationAngles): OrderedRotationAngles;
52
- /** Create an OrderedRotationAngles from three angles (in radians) and an ordering in which to apply them when rotating. */
53
- static createRadians(xRadians: number, yRadians: number, zRadians: number, order: AxisOrder, result?: OrderedRotationAngles): OrderedRotationAngles;
54
- /** Create an OrderedRotationAngles from three angles (in degrees) and an ordering in which to apply them when rotating. */
55
- static createDegrees(xDegrees: number, yDegrees: number, zDegrees: number, order: AxisOrder, result?: OrderedRotationAngles): OrderedRotationAngles;
56
- /** Create an OrderedRotationAngles from a 3x3 rotational matrix, given the ordering of axis rotations that the matrix derives from. */
57
- static createFromMatrix3d(matrix: Matrix3d, order: AxisOrder, result?: OrderedRotationAngles): OrderedRotationAngles;
58
- /** Create a 3x3 rotational matrix from this OrderedRotationAngles. */
101
+ static createAngles(xRotation: Angle, yRotation: Angle, zRotation: Angle, order: AxisOrder, xyzRotationIsClockwise?: [boolean, boolean, boolean], result?: OrderedRotationAngles): OrderedRotationAngles;
102
+ /**
103
+ * Create an OrderedRotationAngles from a 3x3 rotational matrix, given the ordering of axis rotations
104
+ * that the matrix derives from.
105
+ * * This function creates an OrderedRotationAngles with default angle rotation directions, i.e.,
106
+ * it assumes all x, y, and z rotations are counterclockwise.
107
+ * * In the failure case the method's return value is `undefined`.
108
+ * * In the failure case, if the optional result was supplied, that result will nonetheless be filled with
109
+ * a set of angles.
110
+ * */
111
+ static createFromMatrix3d(matrix: Matrix3d, order: AxisOrder, result?: OrderedRotationAngles): OrderedRotationAngles | undefined;
112
+ /**
113
+ * Create a 3x3 rotational matrix from this OrderedRotationAngles.
114
+ ** math details can be found at docs/learning/geometry/Angle.md
115
+ **/
59
116
  toMatrix3d(result?: Matrix3d): Matrix3d;
60
117
  }
61
118
  //# sourceMappingURL=OrderedRotationAngles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OrderedRotationAngles.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/OrderedRotationAngles.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;;;GAOG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,EAAE,CAAQ;IAClB,OAAO,CAAC,EAAE,CAAQ;IAClB,OAAO,CAAC,EAAE,CAAQ;IAClB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAkB;IAExD,OAAO;IAOP,0FAA0F;IAC1F,IAAW,KAAK,IAAI,SAAS,CAAwB;IACrD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAA4B;IACtD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAA4B;IACtD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAA4B;IACtD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAA4B;IACzD,yEAAyE;IACzE,WAAkB,qBAAqB,IAAI,OAAO,CAA0D;IAC5G,WAAkB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAA4D;IAElH;;;;;OAKG;WACW,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAWzJ,2HAA2H;WAC7G,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAW1J,2HAA2H;WAC7G,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAW1J,uIAAuI;WACzH,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IA+F3H,sEAAsE;IAC/D,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ;CA6D/C"}
1
+ {"version":3,"file":"OrderedRotationAngles.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/OrderedRotationAngles.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAY,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAChC,wBAAwB;IACxB,OAAO,CAAC,EAAE,CAAQ;IAClB,wBAAwB;IACxB,OAAO,CAAC,EAAE,CAAQ;IAClB,wBAAwB;IACxB,OAAO,CAAC,EAAE,CAAQ;IAClB,2GAA2G;IAC3G,OAAO,CAAC,MAAM,CAAY;IAC1B,sCAAsC;IACtC,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAkB;IACxD,kBAAkB;IAClB,OAAO;IAMP,0FAA0F;IAC1F,IAAW,KAAK,IAAI,SAAS,CAE5B;IACD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAEzB;IACD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAEzB;IACD,gFAAgF;IAChF,IAAW,MAAM,IAAI,KAAK,CAEzB;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,4EAA4E;IAC5E,IAAW,QAAQ,IAAI,MAAM,CAE5B;IACD,6EAA6E;IAC7E,WAAkB,qBAAqB,IAAI,OAAO,CAEjD;IACD,WAAkB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAErD;IACD;;;;;;;;;;;;;;OAcG;WACW,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAChG,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAqB9G;;;;;;;;;;;;;;OAcG;WACW,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAChG,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAU9G;;;;;;;;;;;;;;OAcG;WACW,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAC/F,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB;IAU9G;;;;;;;;SAQK;WACS,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,qBAAqB,GACjG,qBAAqB,GAAG,SAAS;IAoHnC;;;QAGI;IACG,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ;CA2D/C"}
@@ -5,18 +5,23 @@
5
5
  /** @packageDocumentation
6
6
  * @module CartesianGeometry
7
7
  */
8
- import { AxisOrder } from "../Geometry";
8
+ import { AxisOrder, Geometry } from "../Geometry";
9
9
  import { Angle } from "./Angle";
10
10
  import { Matrix3d } from "./Matrix3d";
11
+ /* cspell:word cxcz, cxsz, cxcy, cxsy, sxcz, sxsz, sxcy, sxsy, cycz, cysz, sycz, sysz */
11
12
  /**
12
- * * OrderedRotationAngles represents a non-trivial rotation using three simple axis rotation angles, and an order in which to apply them.
13
- * * This class accommodates application-specific interpretation of "Multiplying 3 rotation matrices" with regard to
13
+ * represents a non-trivial rotation using three simple axis rotation angles and an order in which to apply them.
14
+ * * This class accommodates application-specific interpretation of "multiplying 3 rotation matrices" with regard to
14
15
  * * Whether a "vector" is a "row" or a "column"
15
- * * The order in which the X,Y, Z rotations are applied.
16
+ * * The order in which the X,Y,Z rotations are applied.
17
+ * * This class bakes in angle rotation directions via create functions (i.e., createRadians, createDegrees, and
18
+ * createAngles) so you can define each of the 3 rotations to be clockwise or counterclockwise. The default
19
+ * rotation is counterclockwise.
16
20
  * * Within the imodel geometry library, the preferred rotation order is encapsulated in `YawPitchRollAngles`.
17
21
  * @alpha
18
22
  */
19
23
  export class OrderedRotationAngles {
24
+ /** constructor */
20
25
  constructor(x, y, z, axisOrder) {
21
26
  this._x = x;
22
27
  this._y = y;
@@ -24,149 +29,224 @@ export class OrderedRotationAngles {
24
29
  this._order = axisOrder;
25
30
  }
26
31
  /** (Property accessor) Return the `AxisOrder` controlling matrix multiplication order. */
27
- get order() { return this._order; }
32
+ get order() {
33
+ return this._order;
34
+ }
28
35
  /** (Property accessor) Return the strongly typed angle of rotation around x. */
29
- get xAngle() { return this._x.clone(); }
36
+ get xAngle() {
37
+ return this._x.clone();
38
+ }
30
39
  /** (Property accessor) Return the strongly typed angle of rotation around y. */
31
- get yAngle() { return this._y.clone(); }
40
+ get yAngle() {
41
+ return this._y.clone();
42
+ }
32
43
  /** (Property accessor) Return the strongly typed angle of rotation around z. */
33
- get zAngle() { return this._z.clone(); }
44
+ get zAngle() {
45
+ return this._z.clone();
46
+ }
34
47
  /** (Property accessor) Return the angle of rotation around x, in degrees */
35
- get xDegrees() { return this._x.degrees; }
48
+ get xDegrees() {
49
+ return this._x.degrees;
50
+ }
36
51
  /** (Property accessor) Return the angle of rotation around y, in degrees */
37
- get xRadians() { return this._x.radians; }
52
+ get xRadians() {
53
+ return this._x.radians;
54
+ }
38
55
  /** (Property accessor) Return the angle of rotation around z, in degrees */
39
- get yDegrees() { return this._y.degrees; }
56
+ get yDegrees() {
57
+ return this._y.degrees;
58
+ }
40
59
  /** (Property accessor) Return the angle of rotation around x, in radians */
41
- get yRadians() { return this._y.radians; }
60
+ get yRadians() {
61
+ return this._y.radians;
62
+ }
42
63
  /** (Property accessor) Return the angle of rotation around y, in radians */
43
- get zDegrees() { return this._z.degrees; }
64
+ get zDegrees() {
65
+ return this._z.degrees;
66
+ }
44
67
  /** (Property accessor) Return the angle of rotation around z, in radians */
45
- get zRadians() { return this._z.radians; }
46
- /** Flag controlling whether vectors are treated as rows or as columns */
47
- static get treatVectorsAsColumns() { return OrderedRotationAngles._sTreatVectorsAsColumns; }
48
- static set treatVectorsAsColumns(value) { OrderedRotationAngles._sTreatVectorsAsColumns = value; }
49
- /** Create an OrderedRotationAngles from three angles and an ordering in which to apply them when rotating.
50
- * @param xRotation rotation around x
51
- * @param yRotation rotation around y
52
- * @param zRotation rotation around z
53
- * @param axisOrder right to left order of axis names identifies the order that rotations are applied to xyz data.
68
+ get zRadians() {
69
+ return this._z.radians;
70
+ }
71
+ /** the flag controlling whether vectors are treated as rows or as columns */
72
+ static get treatVectorsAsColumns() {
73
+ return OrderedRotationAngles._sTreatVectorsAsColumns;
74
+ }
75
+ static set treatVectorsAsColumns(value) {
76
+ OrderedRotationAngles._sTreatVectorsAsColumns = value;
77
+ }
78
+ /**
79
+ * Create an OrderedRotationAngles from three angles (in radians), an ordering in which to apply them when
80
+ * rotating, and a flag triple controlling whether direction of x,y,z is clockwise or counterclockwise.
81
+ * @param xRadians rotation around x
82
+ * @param yRadians rotation around y
83
+ * @param zRadians rotation around z
84
+ * @param order left to right order of axis names identifies the order that rotations are applied.
85
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
86
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
87
+ * matrix multiplication would be zRot*yRot*xRot
88
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
89
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
90
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
91
+ * @param result caller-allocated OrderedRotationAngles
54
92
  */
55
- static createAngles(xRotation, yRotation, zRotation, order, result) {
56
- if (result) {
57
- result._x.setFrom(xRotation);
58
- result._y.setFrom(yRotation);
59
- result._z.setFrom(zRotation);
60
- result._order = order;
61
- return result;
93
+ static createRadians(xRadians, yRadians, zRadians, order, xyzRotationIsClockwise, result) {
94
+ if (!xyzRotationIsClockwise) {
95
+ xyzRotationIsClockwise = [false, false, false];
62
96
  }
63
- return new OrderedRotationAngles(xRotation.clone(), yRotation.clone(), zRotation.clone(), order);
64
- }
65
- /** Create an OrderedRotationAngles from three angles (in radians) and an ordering in which to apply them when rotating. */
66
- static createRadians(xRadians, yRadians, zRadians, order, result) {
97
+ const xRadian = xyzRotationIsClockwise[0] ? -xRadians : xRadians;
98
+ const yRadian = xyzRotationIsClockwise[1] ? -yRadians : yRadians;
99
+ const zRadian = xyzRotationIsClockwise[2] ? -zRadians : zRadians;
67
100
  if (result) {
68
- result._x.setRadians(xRadians);
69
- result._y.setRadians(yRadians);
70
- result._z.setRadians(zRadians);
101
+ result._x.setRadians(xRadian);
102
+ result._y.setRadians(yRadian);
103
+ result._z.setRadians(zRadian);
71
104
  result._order = order;
72
105
  return result;
73
106
  }
74
- return new OrderedRotationAngles(Angle.createRadians(xRadians), Angle.createRadians(yRadians), Angle.createRadians(zRadians), order);
107
+ return new OrderedRotationAngles(Angle.createRadians(xRadian), Angle.createRadians(yRadian), Angle.createRadians(zRadian), order);
75
108
  }
76
- /** Create an OrderedRotationAngles from three angles (in degrees) and an ordering in which to apply them when rotating. */
77
- static createDegrees(xDegrees, yDegrees, zDegrees, order, result) {
78
- if (result) {
79
- result._x.setDegrees(xDegrees);
80
- result._y.setDegrees(yDegrees);
81
- result._z.setDegrees(zDegrees);
82
- result._order = order;
83
- return result;
84
- }
85
- return new OrderedRotationAngles(Angle.createDegrees(xDegrees), Angle.createDegrees(yDegrees), Angle.createDegrees(zDegrees), order);
109
+ /**
110
+ * Create an OrderedRotationAngles from three angles (in degrees) and an ordering in which to apply
111
+ * them when rotating.
112
+ * @param xDegrees rotation around x
113
+ * @param yDegrees rotation around y
114
+ * @param zDegrees rotation around z
115
+ * @param order left to right order of axis names identifies the order that rotations are applied.
116
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
117
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
118
+ * matrix multiplication would be zRot*yRot*xRot
119
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
120
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
121
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
122
+ * @param result caller-allocated OrderedRotationAngles
123
+ */
124
+ static createDegrees(xDegrees, yDegrees, zDegrees, order, xyzRotationIsClockwise, result) {
125
+ return OrderedRotationAngles.createRadians(Angle.degreesToRadians(xDegrees), Angle.degreesToRadians(yDegrees), Angle.degreesToRadians(zDegrees), order, xyzRotationIsClockwise, result);
126
+ }
127
+ /**
128
+ * Create an OrderedRotationAngles from three angles, an ordering in which to apply them when rotating,
129
+ * and a flag triple controlling whether direction of x,y,z is clockwise or counterclockwise.
130
+ * @param xRotation rotation around x
131
+ * @param yRotation rotation around y
132
+ * @param zRotation rotation around z
133
+ * @param order left to right order of axis names identifies the order that rotations are applied
134
+ * For example XYZ means to rotate around x axis first, then y axis, and finally Z axis.
135
+ * * Note that rotation order is reverse of rotation matrix multiplication so for XYZ the rotation
136
+ * matrix multiplication would be zRot*yRot*xRot
137
+ * @param xyzRotationIsClockwise the flags controlling whether direction of x,y,z is clockwise or counterclockwise.
138
+ * rotation direction of x,y,z: true ---> clockwise - false ---> counterclockwise.
139
+ * * if xyzRotationIsClockwise is undefined it's set to [false, false, false].
140
+ * @param result caller-allocated OrderedRotationAngles
141
+ */
142
+ static createAngles(xRotation, yRotation, zRotation, order, xyzRotationIsClockwise, result) {
143
+ return OrderedRotationAngles.createRadians(xRotation.radians, yRotation.radians, zRotation.radians, order, xyzRotationIsClockwise, result);
86
144
  }
87
- /** Create an OrderedRotationAngles from a 3x3 rotational matrix, given the ordering of axis rotations that the matrix derives from. */
145
+ /**
146
+ * Create an OrderedRotationAngles from a 3x3 rotational matrix, given the ordering of axis rotations
147
+ * that the matrix derives from.
148
+ * * This function creates an OrderedRotationAngles with default angle rotation directions, i.e.,
149
+ * it assumes all x, y, and z rotations are counterclockwise.
150
+ * * 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
152
+ * a set of angles.
153
+ * */
88
154
  static createFromMatrix3d(matrix, order, result) {
89
- let m11 = matrix.coffs[0], m12 = matrix.coffs[3], m13 = matrix.coffs[6];
90
- let m21 = matrix.coffs[1], m22 = matrix.coffs[4], m23 = matrix.coffs[7];
91
- let m31 = matrix.coffs[2], m32 = matrix.coffs[5], m33 = matrix.coffs[8];
92
- if (OrderedRotationAngles.treatVectorsAsColumns) {
93
- // the formulas are from row order .. flip the mIJ
94
- m11 = matrix.coffs[0], m12 = matrix.coffs[1], m13 = matrix.coffs[2];
95
- m21 = matrix.coffs[3], m22 = matrix.coffs[4], m23 = matrix.coffs[5];
96
- m31 = matrix.coffs[6], m32 = matrix.coffs[7], m33 = matrix.coffs[8];
155
+ // treat vector as columns
156
+ let m11 = matrix.coffs[0], m12 = matrix.coffs[1], m13 = matrix.coffs[2];
157
+ let m21 = matrix.coffs[3], m22 = matrix.coffs[4], m23 = matrix.coffs[5];
158
+ let m31 = matrix.coffs[6], m32 = matrix.coffs[7], m33 = matrix.coffs[8];
159
+ // treat vector as rows
160
+ if (!OrderedRotationAngles.treatVectorsAsColumns) {
161
+ m11 = matrix.coffs[0], m12 = matrix.coffs[3], m13 = matrix.coffs[6];
162
+ m21 = matrix.coffs[1], m22 = matrix.coffs[4], m23 = matrix.coffs[7];
163
+ m31 = matrix.coffs[2], m32 = matrix.coffs[5], m33 = matrix.coffs[8];
97
164
  }
98
165
  let xRad;
99
166
  let yRad;
100
167
  let zRad;
101
168
  switch (order) {
102
169
  case AxisOrder.XYZ: {
103
- yRad = Math.asin(Math.max(-1, Math.min(1, m13)));
104
- if (Math.abs(m13) < 0.99999) {
105
- xRad = Math.atan2(-m23, m33);
106
- zRad = Math.atan2(-m12, m11);
170
+ yRad = Math.asin(Math.max(-1, Math.min(1, -m31))); // limit asin domain to [-1,1]
171
+ if (Math.abs(m31) < 0.99999) {
172
+ xRad = Math.atan2(m32, m33);
173
+ zRad = Math.atan2(m21, m11);
107
174
  }
108
175
  else {
109
- xRad = Math.atan2(m32, m22);
176
+ /**
177
+ * If Math.abs(m31) = 1 then yRad = +-90 degrees and therefore, we have a gimbal lock.
178
+ * This means xRad and zRad can be anything as long as their sum xRad + zRad is constant.
179
+ * so we can pick zRad = 0 and calculate xRad (or pick xRad = 0 and calculate zRad).
180
+ * Therefore, rotation matrix becomes
181
+ * Matrix3d.createRowValues(
182
+ * 0, +-sx, +-cx,
183
+ * 0, cx, -sx,
184
+ * -+1, 0, 0
185
+ * );
186
+ * Math details can be found
187
+ * https://en.wikipedia.org/wiki/Gimbal_lock#Loss_of_a_degree_of_freedom_with_Euler_angles
188
+ */
189
+ xRad = Math.atan2(-m23, m22);
110
190
  zRad = 0;
111
191
  }
112
192
  break;
113
193
  }
114
194
  case AxisOrder.YXZ: {
115
- xRad = Math.asin(-Math.max(-1, Math.min(1, m23)));
116
- if (Math.abs(m23) < 0.99999) {
117
- yRad = Math.atan2(m13, m33);
118
- zRad = Math.atan2(m21, m22);
195
+ xRad = Math.asin(Math.max(-1, Math.min(1, m32))); // limit asin domain to [-1,1]
196
+ if (Math.abs(m32) < 0.99999) {
197
+ yRad = Math.atan2(-m31, m33);
198
+ zRad = Math.atan2(-m12, m22);
119
199
  }
120
200
  else {
121
- yRad = Math.atan2(-m31, m11);
201
+ yRad = Math.atan2(m13, m11);
122
202
  zRad = 0;
123
203
  }
124
204
  break;
125
205
  }
126
206
  case AxisOrder.ZXY: {
127
- xRad = Math.asin(Math.max(-1, Math.min(1, m32)));
128
- if (Math.abs(m32) < 0.99999) {
129
- yRad = Math.atan2(-m31, m33);
130
- zRad = Math.atan2(-m12, m22);
207
+ xRad = Math.asin(Math.max(-1, Math.min(1, -m23))); // limit asin domain to [-1,1]
208
+ if (Math.abs(m23) < 0.99999) {
209
+ yRad = Math.atan2(m13, m33);
210
+ zRad = Math.atan2(m21, m22);
131
211
  }
132
212
  else {
133
213
  yRad = 0;
134
- zRad = Math.atan2(m21, m11);
214
+ zRad = Math.atan2(-m12, m11);
135
215
  }
136
216
  break;
137
217
  }
138
218
  case AxisOrder.ZYX: {
139
- yRad = -Math.asin(Math.max(-1, Math.min(1, m31)));
140
- if (Math.abs(m31) < 0.99999) {
141
- xRad = Math.atan2(m32, m33);
142
- zRad = Math.atan2(m21, m11);
219
+ yRad = Math.asin(Math.max(-1, Math.min(1, m13))); // limit asin domain to [-1,1]
220
+ if (Math.abs(m13) < 0.99999) {
221
+ xRad = Math.atan2(-m23, m33);
222
+ zRad = Math.atan2(-m12, m11);
143
223
  }
144
224
  else {
145
225
  xRad = 0;
146
- zRad = Math.atan2(-m12, m22);
226
+ zRad = Math.atan2(m21, m22);
147
227
  }
148
228
  break;
149
229
  }
150
230
  case AxisOrder.YZX: {
151
- zRad = Math.asin(Math.max(-1, Math.min(1, m21)));
152
- if (Math.abs(m21) < 0.99999) {
153
- xRad = Math.atan2(-m23, m22);
154
- yRad = Math.atan2(-m31, m11);
231
+ zRad = Math.asin(Math.max(-1, Math.min(1, -m12))); // limit asin domain to [-1,1]
232
+ if (Math.abs(m12) < 0.99999) {
233
+ xRad = Math.atan2(m32, m22);
234
+ yRad = Math.atan2(m13, m11);
155
235
  }
156
236
  else {
157
237
  xRad = 0;
158
- yRad = Math.atan2(m13, m33);
238
+ yRad = Math.atan2(-m31, m33);
159
239
  }
160
240
  break;
161
241
  }
162
242
  case AxisOrder.XZY: {
163
- zRad = -Math.asin(Math.max(-1, Math.min(1, m12)));
164
- if (Math.abs(m12) < 0.99999) {
165
- xRad = Math.atan2(m32, m22);
166
- yRad = Math.atan2(m13, m11);
243
+ zRad = Math.asin(Math.max(-1, Math.min(1, m21))); // limit asin domain to [-1,1]
244
+ if (Math.abs(m21) < 0.99999) {
245
+ xRad = Math.atan2(-m23, m22);
246
+ yRad = Math.atan2(-m31, m11);
167
247
  }
168
248
  else {
169
- xRad = Math.atan2(-m23, m33);
249
+ xRad = Math.atan2(m32, m33);
170
250
  yRad = 0;
171
251
  }
172
252
  break;
@@ -175,54 +255,64 @@ export class OrderedRotationAngles {
175
255
  xRad = yRad = zRad = 0;
176
256
  }
177
257
  }
178
- if (OrderedRotationAngles.treatVectorsAsColumns)
179
- return OrderedRotationAngles.createRadians(-xRad, -yRad, -zRad, order, result);
180
- return OrderedRotationAngles.createRadians(xRad, yRad, zRad, order, result);
258
+ const xyzRotationIsClockwise = [false, false, false];
259
+ const angles = OrderedRotationAngles.createRadians(xRad, yRad, zRad, order, xyzRotationIsClockwise, result);
260
+ // sanity check
261
+ const matrix1 = angles.toMatrix3d();
262
+ /**
263
+ * Below tolerance loosened to allow sanity check to pass for
264
+ *
265
+ * OrderedRotationAngles.createFromMatrix3d(
266
+ * OrderedRotationAngles.createDegrees(0, 89.999, 0.001, AxisOrder.XYZ).toMatrix3d(),
267
+ * AxisOrder.XYZ
268
+ * );
269
+ *
270
+ * with treatVectorsAsColumns = true.
271
+ */
272
+ return (matrix.maxDiff(matrix1) < 10 * Geometry.smallFraction) ? angles : undefined;
181
273
  }
182
- /** Create a 3x3 rotational matrix from this OrderedRotationAngles. */
274
+ /**
275
+ * Create a 3x3 rotational matrix from this OrderedRotationAngles.
276
+ ** math details can be found at docs/learning/geometry/Angle.md
277
+ **/
183
278
  toMatrix3d(result) {
184
- const rot = result !== undefined ? result : new Matrix3d();
279
+ const rot = (result !== undefined) ? result : new Matrix3d();
185
280
  const axisOrder = this.order;
186
281
  const x = this.xAngle, y = this.yAngle, z = this.zAngle;
187
- const a = x.cos();
188
- let b = x.sin();
189
- const c = y.cos();
190
- let d = y.sin();
191
- const e = z.cos();
192
- let f = z.sin();
193
- if (OrderedRotationAngles.treatVectorsAsColumns) {
194
- b = -b;
195
- d = -d;
196
- f = -f;
197
- }
282
+ const cx = x.cos(), sx = x.sin();
283
+ const cy = y.cos(), sy = y.sin();
284
+ const cz = z.cos(), sz = z.sin();
285
+ const cxcz = cx * cz, cxsz = cx * sz, cxcy = cx * cy, cxsy = cx * sy;
286
+ const sxcz = sx * cz, sxsz = sx * sz, sxcy = sx * cy, sxsy = sx * sy;
287
+ const cycz = cy * cz, cysz = cy * sz, sycz = sy * cz, sysz = sy * sz;
288
+ // the rotation matrix we build below is created using column-based base rotation matrixes
198
289
  if (axisOrder === AxisOrder.XYZ) {
199
- const ae = a * e, af = a * f, be = b * e, bf = b * f;
200
- rot.setRowValues(c * e, af + be * d, bf - ae * d, -c * f, ae - bf * d, be + af * d, d, -b * c, a * c);
290
+ rot.setRowValues(cy * cz, sxcz * sy - cxsz, cxcz * sy + sxsz, cy * sz, cxcz + sxsz * sy, cxsz * sy - sxcz, -sy, sx * cy, cx * cy);
201
291
  }
202
292
  else if (axisOrder === AxisOrder.YXZ) {
203
- const ce = c * e, cf = c * f, de = d * e, df = d * f;
204
- rot.setRowValues(ce + df * b, a * f, cf * b - de, de * b - cf, a * e, df + ce * b, a * d, -b, a * c);
293
+ rot.setRowValues(cycz - sysz * sx, -cx * sz, cysz * sx + sycz, sycz * sx + cysz, cx * cz, sysz - cycz * sx, -cx * sy, sx, cx * cy);
205
294
  }
206
295
  else if (axisOrder === AxisOrder.ZXY) {
207
- const ce = c * e, cf = c * f, de = d * e, df = d * f;
208
- rot.setRowValues(ce - df * b, cf + de * b, -a * d, -a * f, a * e, b, de + cf * b, df - ce * b, a * c);
296
+ rot.setRowValues(cycz + sysz * sx, sycz * sx - cysz, cx * sy, cx * sz, cx * cz, -sx, cysz * sx - sycz, cycz * sx + sysz, cx * cy);
209
297
  }
210
298
  else if (axisOrder === AxisOrder.ZYX) {
211
- const ae = a * e, af = a * f, be = b * e, bf = b * f;
212
- rot.setRowValues(c * e, c * f, -d, be * d - af, bf * d + ae, b * c, ae * d + bf, af * d - be, a * c);
299
+ rot.setRowValues(cy * cz, -cy * sz, sy, sxcz * sy + cxsz, cxcz - sxsz * sy, -sx * cy, sxsz - cxcz * sy, sxcz + cxsz * sy, cx * cy);
213
300
  }
214
301
  else if (axisOrder === AxisOrder.YZX) {
215
- const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
216
- rot.setRowValues(c * e, f, -d * e, bd - ac * f, a * e, ad * f + bc, bc * f + ad, -b * e, ac - bd * f);
302
+ rot.setRowValues(cy * cz, -sz, sy * cz, sxsy + cxcy * sz, cx * cz, cxsy * sz - sxcy, sxcy * sz - cxsy, sx * cz, cxcy + sxsy * sz);
217
303
  }
218
304
  else if (axisOrder === AxisOrder.XZY) {
219
- const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
220
- rot.setRowValues(c * e, ac * f + bd, bc * f - ad, -f, a * e, b * e, d * e, ad * f - bc, bd * f + ac);
305
+ rot.setRowValues(cy * cz, sxsy - cxcy * sz, cxsy + sxcy * sz, sz, cx * cz, -sx * cz, -sy * cz, sxcy + cxsy * sz, cxcy - sxsy * sz);
306
+ }
307
+ else {
308
+ rot.setIdentity();
221
309
  }
222
- if (OrderedRotationAngles.treatVectorsAsColumns)
310
+ // if we need row-based rotation matrix, we transpose the rotation matrix
311
+ if (!OrderedRotationAngles.treatVectorsAsColumns)
223
312
  rot.transposeInPlace();
224
313
  return rot;
225
314
  }
226
315
  }
316
+ /** treat vectors as matrix columns */
227
317
  OrderedRotationAngles._sTreatVectorsAsColumns = false;
228
318
  //# sourceMappingURL=OrderedRotationAngles.js.map