@itwin/core-geometry 3.5.0-dev.45 → 3.5.0-dev.47

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.
@@ -518,7 +518,10 @@ class Point3d extends XYZ {
518
518
  crossProductToPointsXY(pointA, pointB) {
519
519
  return Geometry_1.Geometry.crossProductXYXY(pointA.x - this.x, pointA.y - this.y, pointB.x - this.x, pointB.y - this.y);
520
520
  }
521
- /** Return a point interpolated between this point and the right param. */
521
+ /**
522
+ * Return a point interpolated between `this` point and the `other` point.
523
+ * * fraction specifies where the interpolated point is located on the line passing `this` and `other`.
524
+ * */
522
525
  interpolate(fraction, other, result) {
523
526
  if (fraction <= 0.5)
524
527
  return Point3d.create(this.x + fraction * (other.x - this.x), this.y + fraction * (other.y - this.y), this.z + fraction * (other.z - this.z), result);
@@ -865,8 +868,18 @@ class Vector3d extends XYZ {
865
868
  this.z *= a;
866
869
  return true;
867
870
  }
868
- /** Return the fractional projection of spaceVector onto this */
871
+ /**
872
+ * Return fractional projection of target vector onto this
873
+ * * It's returning the signed projection magnitude divided by the target magnitude. In other words,
874
+ * it's returning the length of the projection as a fraction of the target magnitude.
875
+ * @param target the target vector
876
+ * @param defaultFraction the returned value in case magnitude square of target vector is very small
877
+ * */
869
878
  fractionOfProjectionToVector(target, defaultFraction = 0) {
879
+ /*
880
+ * projection length is (this.target)/||target||
881
+ * but here we return (this.target)/||target||^2
882
+ */
870
883
  const numerator = this.dotProduct(target);
871
884
  const denominator = target.magnitudeSquared();
872
885
  if (denominator < Geometry_1.Geometry.smallMetricDistanceSquared)
@@ -1109,7 +1122,8 @@ class Vector3d extends XYZ {
1109
1122
  return true;
1110
1123
  }
1111
1124
  /**
1112
- * Compute cross product with `vectorB`.
1125
+ * Compute cross product with `vectorB`
1126
+ * * cross product vector will have the given length.
1113
1127
  * @param vectorB second vector for cross product.
1114
1128
  * @param productLength desired length of result vector.
1115
1129
  * @param result optional preallocated vector
@@ -1255,7 +1269,7 @@ class Vector3d extends XYZ {
1255
1269
  * * The returned angle is always positive and no larger than 180 degrees (PI radians)
1256
1270
  * * The returned angle is "in the plane containing the two vectors"
1257
1271
  * * Use `planarRadiansTo` and `signedRadiansTo` to take have angle measured in specific plane.
1258
- * @param vectorB target vector of rotation.
1272
+ * @param vectorB target vector.
1259
1273
  */
1260
1274
  radiansTo(vectorB) {
1261
1275
  // ||axb|| = ||a|| ||b|| |sin(t)| and a.b = ||a|| ||b|| cos(t) ==>
@@ -1267,7 +1281,7 @@ class Vector3d extends XYZ {
1267
1281
  * * The returned angle is always positive and no larger than 180 degrees (PI radians)
1268
1282
  * * The returned angle is "in the plane containing the two vectors"
1269
1283
  * * Use `planarAngleTo` and `signedAngleTo` to take have angle measured in specific plane.
1270
- * @param vectorB target vector of rotation.
1284
+ * @param vectorB target vector.
1271
1285
  */
1272
1286
  angleTo(vectorB) {
1273
1287
  return Angle_1.Angle.createRadians(this.radiansTo(vectorB));
@@ -1287,7 +1301,7 @@ class Vector3d extends XYZ {
1287
1301
  * * The returned angle can range from negative 180 degrees (negative PI radians) to positive 180
1288
1302
  * * degrees (positive PI radians), not closed on the negative side.
1289
1303
  * * Use `planarAngleTo` and `signedAngleTo` to take have angle measured in other planes.
1290
- * @param vectorB target vector of rotation.
1304
+ * @param vectorB target vector.
1291
1305
  */
1292
1306
  angleToXY(vectorB) {
1293
1307
  return Angle_1.Angle.createAtan2(this.crossProductXY(vectorB), this.dotProductXY(vectorB));
@@ -1299,7 +1313,8 @@ class Vector3d extends XYZ {
1299
1313
  * * The returned angle is "in the plane containing the two vectors"
1300
1314
  * * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
1301
1315
  * * vectorW does not have to be perpendicular to the plane.
1302
- * @param vectorB target vector of rotation.
1316
+ * * Use planarRadiansTo to measure the angle between vectors that are projected to another plane.
1317
+ * @param vectorB target vector.
1303
1318
  * @param vectorW distinguishes between the sides of the plane.
1304
1319
  */
1305
1320
  signedRadiansTo(vectorB, vectorW) {
@@ -1318,34 +1333,39 @@ class Vector3d extends XYZ {
1318
1333
  * * The returned angle is "in the plane containing the two vectors"
1319
1334
  * * `vectorW` distinguishes between the sides of the plane, but does not have to be perpendicular.
1320
1335
  * * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
1321
- * @param vectorB target vector of rotation.
1336
+ * * Use planarRadiansTo to measure the angle between vectors that are projected to another plane.
1337
+ * @param vectorB target vector.
1322
1338
  * @param vectorW distinguishes between the sides of the plane.
1323
1339
  */
1324
1340
  signedAngleTo(vectorB, vectorW) {
1325
1341
  return Angle_1.Angle.createRadians(this.signedRadiansTo(vectorB, vectorW));
1326
1342
  }
1327
1343
  /**
1328
- * Return the (radians as a simple number, not strongly typed Angle) radians from this vector to vectorB.
1344
+ * Return the radians (as a simple number, not strongly typed Angle) from this vector to vectorB,
1345
+ * measured between their projections to the plane with the given normal.
1329
1346
  * * The returned angle can be positive or negative, with magnitude no larger than PI radians
1330
- * * Use signedRadiansTo` to take have angle measured in other planes.
1331
- * @param vectorB target vector of rotation.
1332
- * @param planeNormal a normal vector to the plane.
1347
+ * @param vectorB target vector
1348
+ * @param planeNormal the normal vector to the plane.
1333
1349
  */
1334
1350
  planarRadiansTo(vectorB, planeNormal) {
1335
1351
  const square = planeNormal.dotProduct(planeNormal);
1336
1352
  if (square === 0.0)
1337
1353
  return 0.0;
1338
1354
  const factor = 1.0 / square;
1339
- const projection0 = this.plusScaled(planeNormal, -this.dotProduct(planeNormal) * factor);
1340
- const projection1 = vectorB.plusScaled(planeNormal, -vectorB.dotProduct(planeNormal) * factor);
1341
- return projection0.signedRadiansTo(projection1, planeNormal);
1355
+ /*
1356
+ * projection of vector 'v' on normal 'n' is given by vProj = [dot(v,n)/||n||^2]*n
1357
+ * and projection of 'v' on the plane is given by 'v - vProj'
1358
+ */
1359
+ const thisProj = this.plusScaled(planeNormal, -this.dotProduct(planeNormal) * factor);
1360
+ const vectorBProj = vectorB.plusScaled(planeNormal, -vectorB.dotProduct(planeNormal) * factor);
1361
+ return thisProj.signedRadiansTo(vectorBProj, planeNormal);
1342
1362
  }
1343
1363
  /**
1344
- * Return the (as strongly typed Angle) Angle from this vector to vectorB.
1364
+ * Return the angle (as strongly typed Angle) from this vector to vectorB,
1365
+ * measured between their projections to the plane with the given normal.
1345
1366
  * * The returned angle can range from negative PI to positive PI (not closed on negative side)
1346
- * * Use signedRadiansTo` to take have angle measured in other planes.
1347
- * @param vectorB target vector of rotation.
1348
- * @param planeNormal a normal vector to the plane.
1367
+ * @param vectorB target vector.
1368
+ * @param planeNormal the normal vector to the plane.
1349
1369
  */
1350
1370
  planarAngleTo(vectorB, planeNormal) {
1351
1371
  return Angle_1.Angle.createRadians(this.planarRadiansTo(vectorB, planeNormal));