@itwin/core-geometry 3.5.0-dev.35 → 3.5.0-dev.41
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.
- package/lib/cjs/Geometry.d.ts +13 -0
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/bspline/BSplineCurve.d.ts +1 -1
- package/lib/cjs/bspline/BSplineCurve.js +1 -1
- package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
- package/lib/cjs/bspline/KnotVector.d.ts.map +1 -1
- package/lib/cjs/bspline/KnotVector.js +3 -0
- package/lib/cjs/bspline/KnotVector.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +7 -5
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js +37 -29
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts +4 -2
- package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCollection.js +14 -2
- package/lib/cjs/curve/CurveCollection.js.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.d.ts +13 -17
- package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/cjs/curve/CurvePrimitive.js +51 -340
- package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
- package/lib/cjs/curve/LineString3d.d.ts +11 -1
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +30 -23
- package/lib/cjs/curve/LineString3d.js.map +1 -1
- package/lib/cjs/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.d.ts +55 -0
- package/lib/cjs/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.d.ts.map +1 -0
- package/lib/cjs/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.js +143 -0
- package/lib/cjs/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.js.map +1 -0
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.d.ts +43 -0
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.d.ts.map +1 -0
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.js +146 -0
- package/lib/cjs/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -0
- package/lib/cjs/curve/internalContexts/CurveLengthContext.d.ts +33 -0
- package/lib/cjs/curve/internalContexts/CurveLengthContext.d.ts.map +1 -0
- package/lib/cjs/curve/internalContexts/CurveLengthContext.js +91 -0
- package/lib/cjs/curve/internalContexts/CurveLengthContext.js.map +1 -0
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts +21 -0
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts.map +1 -0
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.js +34 -0
- package/lib/cjs/curve/internalContexts/NewtonRtoRStrokeHandler.js.map +1 -0
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts +2 -2
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/DirectSpiral3d.js +15 -8
- package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/cjs/geometry3d/Angle.d.ts +20 -10
- package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Angle.js +30 -15
- package/lib/cjs/geometry3d/Angle.js.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.d.ts +25 -8
- package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.js +67 -15
- package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
- package/lib/cjs/geometry3d/Point2dVector2d.d.ts +23 -8
- package/lib/cjs/geometry3d/Point2dVector2d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point2dVector2d.js +40 -13
- package/lib/cjs/geometry3d/Point2dVector2d.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts +90 -55
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js +254 -123
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry3d/Range.d.ts +0 -1
- package/lib/cjs/geometry3d/Range.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Range.js +0 -1
- package/lib/cjs/geometry3d/Range.js.map +1 -1
- package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/cjs/serialization/IModelJsonSchema.d.ts +1 -1
- package/lib/cjs/serialization/IModelJsonSchema.d.ts.map +1 -1
- package/lib/cjs/serialization/IModelJsonSchema.js +4 -3
- package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
- package/lib/cjs/solid/Sphere.d.ts +1 -1
- package/lib/cjs/solid/Sphere.js +3 -3
- package/lib/cjs/solid/Sphere.js.map +1 -1
- package/lib/cjs/solid/TorusPipe.d.ts +17 -13
- package/lib/cjs/solid/TorusPipe.d.ts.map +1 -1
- package/lib/cjs/solid/TorusPipe.js +67 -38
- package/lib/cjs/solid/TorusPipe.js.map +1 -1
- package/lib/cjs/topology/Graph.d.ts +1 -1
- package/lib/cjs/topology/Graph.js +1 -1
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/Triangulation.d.ts +1 -1
- package/lib/cjs/topology/Triangulation.js +1 -1
- package/lib/cjs/topology/Triangulation.js.map +1 -1
- package/lib/esm/Geometry.d.ts +13 -0
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/bspline/BSplineCurve.d.ts +1 -1
- package/lib/esm/bspline/BSplineCurve.js +1 -1
- package/lib/esm/bspline/BSplineCurve.js.map +1 -1
- package/lib/esm/bspline/KnotVector.d.ts.map +1 -1
- package/lib/esm/bspline/KnotVector.js +3 -0
- package/lib/esm/bspline/KnotVector.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +7 -5
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js +37 -29
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/CurveCollection.d.ts +4 -2
- package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
- package/lib/esm/curve/CurveCollection.js +14 -2
- package/lib/esm/curve/CurveCollection.js.map +1 -1
- package/lib/esm/curve/CurvePrimitive.d.ts +13 -17
- package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
- package/lib/esm/curve/CurvePrimitive.js +46 -335
- package/lib/esm/curve/CurvePrimitive.js.map +1 -1
- package/lib/esm/curve/LineString3d.d.ts +11 -1
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +30 -23
- package/lib/esm/curve/LineString3d.js.map +1 -1
- package/lib/esm/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.d.ts +55 -0
- package/lib/esm/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.d.ts.map +1 -0
- package/lib/esm/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.js +139 -0
- package/lib/esm/curve/internalContexts/AppendPlaneIntersectionStrokeHandler.js.map +1 -0
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.d.ts +43 -0
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.d.ts.map +1 -0
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.js +142 -0
- package/lib/esm/curve/internalContexts/ClosestPointStrokeHandler.js.map +1 -0
- package/lib/esm/curve/internalContexts/CurveLengthContext.d.ts +33 -0
- package/lib/esm/curve/internalContexts/CurveLengthContext.d.ts.map +1 -0
- package/lib/esm/curve/internalContexts/CurveLengthContext.js +87 -0
- package/lib/esm/curve/internalContexts/CurveLengthContext.js.map +1 -0
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts +21 -0
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.d.ts.map +1 -0
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.js +30 -0
- package/lib/esm/curve/internalContexts/NewtonRtoRStrokeHandler.js.map +1 -0
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts +2 -2
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/DirectSpiral3d.js +15 -8
- package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/esm/geometry3d/Angle.d.ts +20 -10
- package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
- package/lib/esm/geometry3d/Angle.js +30 -15
- package/lib/esm/geometry3d/Angle.js.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.d.ts +25 -8
- package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.js +67 -15
- package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
- package/lib/esm/geometry3d/Point2dVector2d.d.ts +23 -8
- package/lib/esm/geometry3d/Point2dVector2d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point2dVector2d.js +40 -13
- package/lib/esm/geometry3d/Point2dVector2d.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts +90 -55
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js +254 -123
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry3d/Range.d.ts +0 -1
- package/lib/esm/geometry3d/Range.d.ts.map +1 -1
- package/lib/esm/geometry3d/Range.js +0 -1
- package/lib/esm/geometry3d/Range.js.map +1 -1
- package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/esm/serialization/IModelJsonSchema.d.ts +1 -1
- package/lib/esm/serialization/IModelJsonSchema.d.ts.map +1 -1
- package/lib/esm/serialization/IModelJsonSchema.js +4 -3
- package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
- package/lib/esm/solid/Sphere.d.ts +1 -1
- package/lib/esm/solid/Sphere.js +3 -3
- package/lib/esm/solid/Sphere.js.map +1 -1
- package/lib/esm/solid/TorusPipe.d.ts +17 -13
- package/lib/esm/solid/TorusPipe.d.ts.map +1 -1
- package/lib/esm/solid/TorusPipe.js +67 -38
- package/lib/esm/solid/TorusPipe.js.map +1 -1
- package/lib/esm/topology/Graph.d.ts +1 -1
- package/lib/esm/topology/Graph.js +1 -1
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/Triangulation.d.ts +1 -1
- package/lib/esm/topology/Triangulation.js +1 -1
- package/lib/esm/topology/Triangulation.js.map +1 -1
- package/package.json +4 -4
|
@@ -17,24 +17,42 @@ import { XYAndZ } from "./XYZProps";
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export class XYZ {
|
|
20
|
-
constructor(x = 0, y = 0, z = 0) {
|
|
20
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
21
|
+
this.x = x;
|
|
22
|
+
this.y = y;
|
|
23
|
+
this.z = z;
|
|
24
|
+
}
|
|
21
25
|
/**
|
|
22
26
|
* Set the x,y,z parts.
|
|
23
27
|
* @param x (optional) x part
|
|
24
28
|
* @param y (optional) y part
|
|
25
29
|
* @param z (optional) z part
|
|
26
30
|
*/
|
|
27
|
-
set(x = 0, y = 0, z = 0) {
|
|
31
|
+
set(x = 0, y = 0, z = 0) {
|
|
32
|
+
this.x = x;
|
|
33
|
+
this.y = y;
|
|
34
|
+
this.z = z;
|
|
35
|
+
}
|
|
28
36
|
/** Set the x,y,z parts to zero. */
|
|
29
|
-
setZero() {
|
|
37
|
+
setZero() {
|
|
38
|
+
this.x = 0;
|
|
39
|
+
this.y = 0;
|
|
40
|
+
this.z = 0;
|
|
41
|
+
}
|
|
30
42
|
/** Type guard for XAndY.
|
|
31
43
|
* @note this will return true for an XYAndZ. If you wish to distinguish between the two, call isXYAndZ first.
|
|
32
44
|
*/
|
|
33
|
-
static isXAndY(arg) {
|
|
45
|
+
static isXAndY(arg) {
|
|
46
|
+
return arg.x !== undefined && arg.y !== undefined;
|
|
47
|
+
}
|
|
34
48
|
/** Type guard to determine whether an object has a member called "z" */
|
|
35
|
-
static hasZ(arg) {
|
|
49
|
+
static hasZ(arg) {
|
|
50
|
+
return arg.z !== undefined;
|
|
51
|
+
}
|
|
36
52
|
/** Type guard for XYAndZ. */
|
|
37
|
-
static isXYAndZ(arg) {
|
|
53
|
+
static isXYAndZ(arg) {
|
|
54
|
+
return this.isXAndY(arg) && this.hasZ(arg);
|
|
55
|
+
}
|
|
38
56
|
/** Test if arg is any of:
|
|
39
57
|
* * XAndY
|
|
40
58
|
* * XYAndZ
|
|
@@ -117,6 +135,7 @@ export class XYZ {
|
|
|
117
135
|
/**
|
|
118
136
|
* Set the x,y,z parts from a Vector3d
|
|
119
137
|
* This is the same effect as `setFrom(other)` with no pretesting of variant input type
|
|
138
|
+
* * Set to zeros if `other` is undefined.
|
|
120
139
|
*/
|
|
121
140
|
setFromVector3d(other) {
|
|
122
141
|
if (other) {
|
|
@@ -147,13 +166,21 @@ export class XYZ {
|
|
|
147
166
|
&& Geometry.isSameCoordinate(this.y, other.y, tol);
|
|
148
167
|
}
|
|
149
168
|
/** Return a JSON object as array `[x,y,z]` */
|
|
150
|
-
toJSON() {
|
|
169
|
+
toJSON() {
|
|
170
|
+
return this.toArray();
|
|
171
|
+
}
|
|
151
172
|
/** Return as an array `[x,y,z]` */
|
|
152
|
-
toArray() {
|
|
173
|
+
toArray() {
|
|
174
|
+
return [this.x, this.y, this.z];
|
|
175
|
+
}
|
|
153
176
|
/** Return a JSON object as key value pairs `{x: value, y: value, z: value}` */
|
|
154
|
-
toJSONXYZ() {
|
|
177
|
+
toJSONXYZ() {
|
|
178
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
179
|
+
}
|
|
155
180
|
/** Pack the x,y,z values in a Float64Array. */
|
|
156
|
-
toFloat64Array() {
|
|
181
|
+
toFloat64Array() {
|
|
182
|
+
return Float64Array.of(this.x, this.y, this.z);
|
|
183
|
+
}
|
|
157
184
|
/**
|
|
158
185
|
* Set the x,y,z properties from one of several json forms:
|
|
159
186
|
*
|
|
@@ -239,28 +266,54 @@ export class XYZ {
|
|
|
239
266
|
}
|
|
240
267
|
/** Return true if the x,y,z components are all nearly zero to tolerance Geometry.smallMetricDistance */
|
|
241
268
|
get isAlmostZero() {
|
|
242
|
-
return Geometry.isSmallMetricDistance(this.x) &&
|
|
269
|
+
return Geometry.isSmallMetricDistance(this.x) &&
|
|
270
|
+
Geometry.isSmallMetricDistance(this.y) &&
|
|
271
|
+
Geometry.isSmallMetricDistance(this.z);
|
|
243
272
|
}
|
|
244
273
|
/** Return true if the x,y,z components are all exactly zero */
|
|
245
|
-
get isZero() {
|
|
274
|
+
get isZero() {
|
|
275
|
+
return this.x === 0.0 && this.y === 0.0 && this.z === 0.0;
|
|
276
|
+
}
|
|
246
277
|
/** Return the largest absolute value of any component */
|
|
247
|
-
maxAbs() {
|
|
278
|
+
maxAbs() {
|
|
279
|
+
return Math.max(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z));
|
|
280
|
+
}
|
|
248
281
|
/** Return the sqrt of the sum of squared x,y,z parts */
|
|
249
|
-
magnitude() {
|
|
282
|
+
magnitude() {
|
|
283
|
+
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
284
|
+
}
|
|
250
285
|
/** Return the sum of squared x,y,z parts */
|
|
251
|
-
magnitudeSquared() {
|
|
286
|
+
magnitudeSquared() {
|
|
287
|
+
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
288
|
+
}
|
|
252
289
|
/** Return sqrt of the sum of squared x,y parts */
|
|
253
|
-
magnitudeXY() {
|
|
290
|
+
magnitudeXY() {
|
|
291
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
292
|
+
}
|
|
254
293
|
/** Return the sum of squared x,y parts */
|
|
255
|
-
magnitudeSquaredXY() {
|
|
294
|
+
magnitudeSquaredXY() {
|
|
295
|
+
return this.x * this.x + this.y * this.y;
|
|
296
|
+
}
|
|
256
297
|
/** exact equality test. */
|
|
257
|
-
isExactEqual(other) {
|
|
298
|
+
isExactEqual(other) {
|
|
299
|
+
return this.x === other.x && this.y === other.y && this.z === other.z;
|
|
300
|
+
}
|
|
258
301
|
/** equality test with Geometry.smallMetricDistance tolerance */
|
|
259
|
-
isAlmostEqualMetric(other) {
|
|
302
|
+
isAlmostEqualMetric(other) {
|
|
303
|
+
return this.maxDiff(other) <= Geometry.smallMetricDistance;
|
|
304
|
+
}
|
|
260
305
|
/** add x,y,z from other in place. */
|
|
261
|
-
addInPlace(other) {
|
|
306
|
+
addInPlace(other) {
|
|
307
|
+
this.x += other.x;
|
|
308
|
+
this.y += other.y;
|
|
309
|
+
this.z += other.z;
|
|
310
|
+
}
|
|
262
311
|
/** add x,y,z from other in place. */
|
|
263
|
-
subtractInPlace(other) {
|
|
312
|
+
subtractInPlace(other) {
|
|
313
|
+
this.x -= other.x;
|
|
314
|
+
this.y -= other.y;
|
|
315
|
+
this.z -= other.z;
|
|
316
|
+
}
|
|
264
317
|
/** add (in place) the scaled x,y,z of other */
|
|
265
318
|
addScaledInPlace(other, scale) {
|
|
266
319
|
this.x += scale * other.x;
|
|
@@ -268,11 +321,21 @@ export class XYZ {
|
|
|
268
321
|
this.z += scale * other.z;
|
|
269
322
|
}
|
|
270
323
|
/** Multiply the x, y, z parts by scale. */
|
|
271
|
-
scaleInPlace(scale) {
|
|
324
|
+
scaleInPlace(scale) {
|
|
325
|
+
this.x *= scale;
|
|
326
|
+
this.y *= scale;
|
|
327
|
+
this.z *= scale;
|
|
328
|
+
}
|
|
272
329
|
/** add to x, y, z parts */
|
|
273
|
-
addXYZInPlace(dx = 0.0, dy = 0.0, dz = 0.0) {
|
|
330
|
+
addXYZInPlace(dx = 0.0, dy = 0.0, dz = 0.0) {
|
|
331
|
+
this.x += dx;
|
|
332
|
+
this.y += dy;
|
|
333
|
+
this.z += dz;
|
|
334
|
+
}
|
|
274
335
|
/** Clone strongly typed as Point3d */
|
|
275
|
-
cloneAsPoint3d() {
|
|
336
|
+
cloneAsPoint3d() {
|
|
337
|
+
return Point3d.create(this.x, this.y, this.z);
|
|
338
|
+
}
|
|
276
339
|
/** Return a (full length) vector from this point to other */
|
|
277
340
|
vectorTo(other, result) {
|
|
278
341
|
return Vector3d.create(other.x - this.x, other.y - this.y, other.z - this.z, result);
|
|
@@ -285,9 +348,13 @@ export class XYZ {
|
|
|
285
348
|
* @param other target of created vector.
|
|
286
349
|
* @param result optional result vector.
|
|
287
350
|
*/
|
|
288
|
-
unitVectorTo(target, result) {
|
|
351
|
+
unitVectorTo(target, result) {
|
|
352
|
+
return this.vectorTo(target, result).normalize(result);
|
|
353
|
+
}
|
|
289
354
|
/** Freeze this XYZ */
|
|
290
|
-
freeze() {
|
|
355
|
+
freeze() {
|
|
356
|
+
return Object.freeze(this);
|
|
357
|
+
}
|
|
291
358
|
/** access x part of XYZProps (which may be .x or [0]) */
|
|
292
359
|
static x(xyz, defaultValue = 0) {
|
|
293
360
|
if (xyz === undefined)
|
|
@@ -324,7 +391,9 @@ export class XYZ {
|
|
|
324
391
|
*/
|
|
325
392
|
export class Point3d extends XYZ {
|
|
326
393
|
/** Constructor for Point3d */
|
|
327
|
-
constructor(x = 0, y = 0, z = 0) {
|
|
394
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
395
|
+
super(x, y, z);
|
|
396
|
+
}
|
|
328
397
|
/**
|
|
329
398
|
* Convert json to Point3d. Accepted forms are:
|
|
330
399
|
* * `[1,2,3]` --- array of numbers
|
|
@@ -332,9 +401,15 @@ export class Point3d extends XYZ {
|
|
|
332
401
|
* * object with x,y, and (optional) z as numeric properties {x: xValue, y: yValue, z: zValue}
|
|
333
402
|
* @param json json value.
|
|
334
403
|
*/
|
|
335
|
-
static fromJSON(json) {
|
|
404
|
+
static fromJSON(json) {
|
|
405
|
+
const val = new Point3d();
|
|
406
|
+
val.setFromJSON(json);
|
|
407
|
+
return val;
|
|
408
|
+
}
|
|
336
409
|
/** Return a new Point3d with the same coordinates */
|
|
337
|
-
clone(result) {
|
|
410
|
+
clone(result) {
|
|
411
|
+
return Point3d.create(this.x, this.y, this.z, result);
|
|
412
|
+
}
|
|
338
413
|
/** Create a new Point3d with given coordinates
|
|
339
414
|
* @param x x part
|
|
340
415
|
* @param y y part
|
|
@@ -380,7 +455,7 @@ export class Point3d extends XYZ {
|
|
|
380
455
|
/**
|
|
381
456
|
* Copy and unweight xyzw.
|
|
382
457
|
* @param xyzData flat array of x,y,z,w,x,y,z,w for multiple points
|
|
383
|
-
* @param pointIndex index of point to extract.
|
|
458
|
+
* @param pointIndex index of point to extract. This index is multiplied by 4 to obtain starting index in the array.
|
|
384
459
|
* @param result optional result point.
|
|
385
460
|
*/
|
|
386
461
|
static createFromPackedXYZW(xyzData, pointIndex, result) {
|
|
@@ -405,7 +480,9 @@ export class Point3d extends XYZ {
|
|
|
405
480
|
return result;
|
|
406
481
|
}
|
|
407
482
|
/** Create a new point with 000 xyz */
|
|
408
|
-
static createZero(result) {
|
|
483
|
+
static createZero(result) {
|
|
484
|
+
return Point3d.create(0, 0, 0, result);
|
|
485
|
+
}
|
|
409
486
|
/** Return the cross product of the vectors from this to pointA and pointB
|
|
410
487
|
*
|
|
411
488
|
* * the result is a vector
|
|
@@ -423,7 +500,7 @@ export class Point3d extends XYZ {
|
|
|
423
500
|
/** Return the triple product of the vectors from this to pointA, pointB, pointC
|
|
424
501
|
*
|
|
425
502
|
* * This is a scalar (number)
|
|
426
|
-
* *
|
|
503
|
+
* * This is 6 times the (signed) volume of the tetrahedron on the 4 points.
|
|
427
504
|
*/
|
|
428
505
|
tripleProductToPoints(pointA, pointB, pointC) {
|
|
429
506
|
return Geometry.tripleProduct(pointA.x - this.x, pointA.y - this.y, pointA.z - this.z, pointB.x - this.x, pointB.y - this.y, pointB.z - this.z, pointC.x - this.x, pointC.y - this.y, pointC.z - this.z);
|
|
@@ -520,9 +597,7 @@ export class Point3d extends XYZ {
|
|
|
520
597
|
(targetA.y - this.y) * (targetB.y - this.y) +
|
|
521
598
|
(targetA.z - this.z) * (targetB.z - this.z);
|
|
522
599
|
}
|
|
523
|
-
/** Return the fractional projection of this onto a line between points.
|
|
524
|
-
*
|
|
525
|
-
*/
|
|
600
|
+
/** Return the fractional projection of this onto a line between points. */
|
|
526
601
|
fractionOfProjectionToLine(startPoint, endPoint, defaultFraction = 0) {
|
|
527
602
|
const denominator = startPoint.distanceSquared(endPoint);
|
|
528
603
|
if (denominator < Geometry.smallMetricDistanceSquared)
|
|
@@ -534,7 +609,9 @@ export class Point3d extends XYZ {
|
|
|
534
609
|
* @public
|
|
535
610
|
*/
|
|
536
611
|
export class Vector3d extends XYZ {
|
|
537
|
-
constructor(x = 0, y = 0, z = 0) {
|
|
612
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
613
|
+
super(x, y, z);
|
|
614
|
+
}
|
|
538
615
|
/**
|
|
539
616
|
* Return an array of vectors constructed from groups of 3 entries in a Float64Array.
|
|
540
617
|
* Any incomplete group at the tail of the array is ignored.
|
|
@@ -549,7 +626,9 @@ export class Vector3d extends XYZ {
|
|
|
549
626
|
* Copy xyz from this instance to a new (or optionally reused) Vector3d
|
|
550
627
|
* @param result optional instance to reuse.
|
|
551
628
|
*/
|
|
552
|
-
clone(result) {
|
|
629
|
+
clone(result) {
|
|
630
|
+
return Vector3d.create(this.x, this.y, this.z, result);
|
|
631
|
+
}
|
|
553
632
|
/**
|
|
554
633
|
* return a Vector3d (new or reused from optional result)
|
|
555
634
|
* @param x x component
|
|
@@ -638,7 +717,11 @@ export class Vector3d extends XYZ {
|
|
|
638
717
|
* * object with x,y, and (optional) z as numeric properties {x: xValue, y: yValue, z: zValue}
|
|
639
718
|
* @param json json value.
|
|
640
719
|
*/
|
|
641
|
-
static fromJSON(json) {
|
|
720
|
+
static fromJSON(json) {
|
|
721
|
+
const val = new Vector3d();
|
|
722
|
+
val.setFromJSON(json);
|
|
723
|
+
return val;
|
|
724
|
+
}
|
|
642
725
|
/** Copy contents from another Point3d, Point2d, Vector2d, or Vector3d */
|
|
643
726
|
static createFrom(data, result) {
|
|
644
727
|
if (data instanceof Float64Array) {
|
|
@@ -714,7 +797,7 @@ export class Vector3d extends XYZ {
|
|
|
714
797
|
return undefined;
|
|
715
798
|
}
|
|
716
799
|
/**
|
|
717
|
-
* Set (replace)
|
|
800
|
+
* Set (replace) xyz components so they are a vector from point0 to point1
|
|
718
801
|
* @param point0 start point of computed vector
|
|
719
802
|
* @param point1 end point of computed vector.
|
|
720
803
|
*/
|
|
@@ -724,13 +807,21 @@ export class Vector3d extends XYZ {
|
|
|
724
807
|
this.z = point1.z - point0.z;
|
|
725
808
|
}
|
|
726
809
|
/** Return a vector with 000 xyz parts. */
|
|
727
|
-
static createZero(result) {
|
|
810
|
+
static createZero(result) {
|
|
811
|
+
return Vector3d.create(0, 0, 0, result);
|
|
812
|
+
}
|
|
728
813
|
/** Return a unit X vector optionally multiplied by a scale */
|
|
729
|
-
static unitX(scale = 1) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
/** Return a unit
|
|
733
|
-
static
|
|
814
|
+
static unitX(scale = 1) {
|
|
815
|
+
return new Vector3d(scale, 0, 0);
|
|
816
|
+
}
|
|
817
|
+
/** Return a unit Y vector optionally multiplied by a scale */
|
|
818
|
+
static unitY(scale = 1) {
|
|
819
|
+
return new Vector3d(0, scale, 0);
|
|
820
|
+
}
|
|
821
|
+
/** Return a unit Z vector optionally multiplied by a scale */
|
|
822
|
+
static unitZ(scale = 1) {
|
|
823
|
+
return new Vector3d(0, 0, scale);
|
|
824
|
+
}
|
|
734
825
|
/** Divide by denominator, but return undefined if denominator is zero. */
|
|
735
826
|
safeDivideOrNull(denominator, result) {
|
|
736
827
|
if (denominator !== 0.0) {
|
|
@@ -739,8 +830,8 @@ export class Vector3d extends XYZ {
|
|
|
739
830
|
return undefined;
|
|
740
831
|
}
|
|
741
832
|
/**
|
|
742
|
-
* Return a pair object containing (a) property `v` which is a unit vector in the direction
|
|
743
|
-
*
|
|
833
|
+
* Return a pair object containing (a) property `v` which is a unit vector in the direction of the input
|
|
834
|
+
* and (b) property mag which is the magnitude (length) of the input (instance) prior to normalization.
|
|
744
835
|
* If the instance (input) is a near zero length the `v` property of the output is undefined.
|
|
745
836
|
* @param result optional result.
|
|
746
837
|
*/
|
|
@@ -753,7 +844,9 @@ export class Vector3d extends XYZ {
|
|
|
753
844
|
* Return a unit vector parallel with this. Return undefined if this.magnitude is near zero.
|
|
754
845
|
* @param result optional result.
|
|
755
846
|
*/
|
|
756
|
-
normalize(result) {
|
|
847
|
+
normalize(result) {
|
|
848
|
+
return this.normalizeWithLength(result).v;
|
|
849
|
+
}
|
|
757
850
|
/**
|
|
758
851
|
* If this vector has nonzero length, divide by the length to change to a unit vector.
|
|
759
852
|
* @returns true if normalization completed.
|
|
@@ -788,7 +881,7 @@ export class Vector3d extends XYZ {
|
|
|
788
881
|
/** Return a vector same length as this but rotate 90 degrees CCW */
|
|
789
882
|
rotate90CCWXY(result) {
|
|
790
883
|
result = result ? result : new Vector3d();
|
|
791
|
-
// save x,y to allow aliasing
|
|
884
|
+
// save x,y to allow aliasing ("this" can be passed to the function as "result")
|
|
792
885
|
const xx = this.x;
|
|
793
886
|
const yy = this.y;
|
|
794
887
|
result.x = -yy;
|
|
@@ -834,17 +927,23 @@ export class Vector3d extends XYZ {
|
|
|
834
927
|
return result;
|
|
835
928
|
}
|
|
836
929
|
/**
|
|
837
|
-
* Return a (new or optionally preallocated) vector that is rotated 90 degrees in
|
|
930
|
+
* Return a (new or optionally preallocated) vector that is rotated 90 degrees in
|
|
931
|
+
* the plane of this vector and the target vector.
|
|
838
932
|
* @param target Second vector which defines the plane of rotation.
|
|
839
933
|
* @param result optional preallocated vector for result.
|
|
840
|
-
* @returns rotated vector, or undefined if the cross product of this and
|
|
934
|
+
* @returns rotated vector, or undefined if the cross product of this and
|
|
935
|
+
* the the target cannot be normalized (i.e. if the target and this are colinear)
|
|
841
936
|
*/
|
|
842
937
|
rotate90Towards(target, result) {
|
|
843
938
|
const normal = this.crossProduct(target).normalize();
|
|
844
939
|
return normal ? normal.crossProduct(this, result) : undefined;
|
|
845
940
|
}
|
|
846
941
|
/** Rotate this vector 90 degrees around an axis vector.
|
|
847
|
-
*
|
|
942
|
+
* * Note that simple cross is in the plane perpendicular to axis -- it loses the part
|
|
943
|
+
* of "this" that is along the axis. The unit and scale is supposed to fix that.
|
|
944
|
+
* This matches with Rodrigues' rotation formula because cos(theta) = 0 and sin(theta) = 1
|
|
945
|
+
* @returns the (new or optionally reused result) rotated vector, or undefined if the axis
|
|
946
|
+
* vector cannot be normalized.
|
|
848
947
|
*/
|
|
849
948
|
rotate90Around(axis, result) {
|
|
850
949
|
const unitNormal = axis.normalize();
|
|
@@ -852,7 +951,8 @@ export class Vector3d extends XYZ {
|
|
|
852
951
|
}
|
|
853
952
|
/**
|
|
854
953
|
* Return a vector computed at fractional position between this vector and vectorB
|
|
855
|
-
* @param fraction fractional position. 0 is at `this`. 1 is at `vectorB`.
|
|
954
|
+
* @param fraction fractional position. 0 is at `this`. 1 is at `vectorB`.
|
|
955
|
+
* True fractions are "between", negatives are "before this", beyond 1 is "beyond vectorB".
|
|
856
956
|
* @param vectorB second vector
|
|
857
957
|
* @param result optional preallocated result.
|
|
858
958
|
*/
|
|
@@ -923,7 +1023,8 @@ export class Vector3d extends XYZ {
|
|
|
923
1023
|
static createAdd2Scaled(vectorA, scaleA, vectorB, scaleB, result) {
|
|
924
1024
|
return Vector3d.create(vectorA.x * scaleA + vectorB.x * scaleB, vectorA.y * scaleA + vectorB.y * scaleB, vectorA.z * scaleA + vectorB.z * scaleB, result);
|
|
925
1025
|
}
|
|
926
|
-
/** Return the (strongly typed Vector3d) `thisVector3d + vectorA * scalarA + vectorB * scalarB`
|
|
1026
|
+
/** Return the (strongly typed Vector3d) `thisVector3d + vectorA * scalarA + vectorB * scalarB`
|
|
1027
|
+
* with all components presented as numbers */
|
|
927
1028
|
static createAdd2ScaledXYZ(ax, ay, az, scaleA, bx, by, bz, scaleB, result) {
|
|
928
1029
|
return Vector3d.create(ax * scaleA + bx * scaleB, ay * scaleA + by * scaleB, az * scaleA + bz * scaleB, result);
|
|
929
1030
|
}
|
|
@@ -958,7 +1059,8 @@ export class Vector3d extends XYZ {
|
|
|
958
1059
|
return this.crossProduct(vectorB, result).normalize(result);
|
|
959
1060
|
}
|
|
960
1061
|
/**
|
|
961
|
-
* Compute the cross product of this vector with `vectorB`. Normalize it, using given xyz as
|
|
1062
|
+
* Compute the cross product of this vector with `vectorB`. Normalize it, using given xyz as
|
|
1063
|
+
* default if length is zero.
|
|
962
1064
|
* @param vectorB second vector of cross product
|
|
963
1065
|
* @param x x value for default result
|
|
964
1066
|
* @param y y value for default result
|
|
@@ -1091,17 +1193,18 @@ export class Vector3d extends XYZ {
|
|
|
1091
1193
|
return this.x * (pointB.x - pointA.x)
|
|
1092
1194
|
+ this.y * (pointB.y - pointA.y);
|
|
1093
1195
|
}
|
|
1094
|
-
/** Dot product with vector from pointA to pointB, with pointB given as (weighted)
|
|
1095
|
-
* * pointB is a homogeneous point
|
|
1196
|
+
/** Dot product with vector from pointA to pointB, with pointB given as (weighted) wx,wy,wz,w
|
|
1197
|
+
* * We need to unweight pointB (which is a homogeneous point) to be able to participate in the
|
|
1198
|
+
* vector dot product
|
|
1096
1199
|
* * if the weight is near zero metric, the return is zero.
|
|
1097
1200
|
*/
|
|
1098
|
-
dotProductStartEndXYZW(pointA,
|
|
1201
|
+
dotProductStartEndXYZW(pointA, wx, wy, wz, w) {
|
|
1099
1202
|
if (Geometry.isSmallMetricDistance(w))
|
|
1100
1203
|
return 0.0;
|
|
1101
1204
|
const dw = 1.0 / w;
|
|
1102
|
-
return this.x * (dw *
|
|
1103
|
-
+ this.y * (dw *
|
|
1104
|
-
+ this.z * (dw *
|
|
1205
|
+
return this.x * (dw * wx - pointA.x)
|
|
1206
|
+
+ this.y * (dw * wy - pointA.y)
|
|
1207
|
+
+ this.z * (dw * wz - pointA.z);
|
|
1105
1208
|
}
|
|
1106
1209
|
/** Return the dot product of the instance and vectorB, using only the x and y parts. */
|
|
1107
1210
|
dotProductXY(vectorB) {
|
|
@@ -1143,46 +1246,93 @@ export class Vector3d extends XYZ {
|
|
|
1143
1246
|
return Vector3d.createCrossProduct(this.x, this.y, this.z, x, y, z, result);
|
|
1144
1247
|
}
|
|
1145
1248
|
/**
|
|
1146
|
-
|
|
1249
|
+
* Return the (radians as a simple number, not strongly typed Angle) angle from this vector to vectorB.
|
|
1250
|
+
* * The returned angle is always positive and no larger than 180 degrees (PI radians)
|
|
1251
|
+
* * The returned angle is "in the plane containing the two vectors"
|
|
1252
|
+
* * Use `planarRadiansTo` and `signedRadiansTo` to take have angle measured in specific plane.
|
|
1253
|
+
* @param vectorB target vector of rotation.
|
|
1254
|
+
*/
|
|
1255
|
+
radiansTo(vectorB) {
|
|
1256
|
+
// ||axb|| = ||a|| ||b|| |sin(t)| and a.b = ||a|| ||b|| cos(t) ==>
|
|
1257
|
+
// ||axb|| / a.b = sin(t)/cos(t) = tan(t) ==> t = arctan(||axb|| / a.b).
|
|
1258
|
+
return Math.atan2(this.crossProductMagnitude(vectorB), this.dotProduct(vectorB));
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Return the (strongly typed) angle from this vector to vectorB.
|
|
1147
1262
|
* * The returned angle is always positive and no larger than 180 degrees (PI radians)
|
|
1148
1263
|
* * The returned angle is "in the plane containing the two vectors"
|
|
1149
|
-
* * Use `planarAngleTo
|
|
1264
|
+
* * Use `planarAngleTo` and `signedAngleTo` to take have angle measured in specific plane.
|
|
1150
1265
|
* @param vectorB target vector of rotation.
|
|
1151
1266
|
*/
|
|
1152
1267
|
angleTo(vectorB) {
|
|
1153
|
-
return Angle.
|
|
1268
|
+
return Angle.createRadians(this.radiansTo(vectorB));
|
|
1154
1269
|
}
|
|
1155
1270
|
/**
|
|
1156
|
-
* Return the (
|
|
1271
|
+
* Return the (strongly typed) angle from this vector to the plane perpendicular to planeNormal.
|
|
1157
1272
|
* * The returned vector is signed
|
|
1158
|
-
* * The returned vector is (as degrees) always
|
|
1159
|
-
*
|
|
1273
|
+
* * The returned vector is (as degrees) always between -90 and 90 degrees.
|
|
1274
|
+
* * The function returns "PI/2 - angleTo(planeNormal)"
|
|
1275
|
+
* @param planeNormal a normal vector to the plane.
|
|
1160
1276
|
*/
|
|
1161
|
-
angleFromPerpendicular(
|
|
1162
|
-
return Angle.createAtan2(this.dotProduct(
|
|
1277
|
+
angleFromPerpendicular(planeNormal) {
|
|
1278
|
+
return Angle.createAtan2(this.dotProduct(planeNormal), this.crossProductMagnitude(planeNormal));
|
|
1163
1279
|
}
|
|
1164
1280
|
/**
|
|
1165
|
-
* Return the (Strongly typed) angle from this vector to vectorB,using only the xy parts.
|
|
1166
|
-
* * The returned angle can range from negative 180 degrees (negative PI radians) to positive 180
|
|
1167
|
-
* *
|
|
1281
|
+
* Return the (Strongly typed) angle from this vector to vectorB, using only the xy parts.
|
|
1282
|
+
* * The returned angle can range from negative 180 degrees (negative PI radians) to positive 180
|
|
1283
|
+
* * degrees (positive PI radians), not closed on the negative side.
|
|
1284
|
+
* * Use `planarAngleTo` and `signedAngleTo` to take have angle measured in other planes.
|
|
1168
1285
|
* @param vectorB target vector of rotation.
|
|
1169
1286
|
*/
|
|
1170
1287
|
angleToXY(vectorB) {
|
|
1171
1288
|
return Angle.createAtan2(this.crossProductXY(vectorB), this.dotProductXY(vectorB));
|
|
1172
1289
|
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Return the (simple number of radians, not Strongly typed Angle) angle from this vector to vectorB, measured
|
|
1292
|
+
* in the plane containing both, with vectorW indicating which side to view to control sign of the angle.
|
|
1293
|
+
* * The returned angle can range from negative PI to positive PI (not closed on negative side)
|
|
1294
|
+
* * The returned angle is "in the plane containing the two vectors"
|
|
1295
|
+
* * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
|
|
1296
|
+
* * vectorW does not have to be perpendicular to the plane.
|
|
1297
|
+
* @param vectorB target vector of rotation.
|
|
1298
|
+
* @param vectorW distinguishes between the sides of the plane.
|
|
1299
|
+
*/
|
|
1300
|
+
signedRadiansTo(vectorB, vectorW) {
|
|
1301
|
+
const p = this.crossProduct(vectorB);
|
|
1302
|
+
const theta = Math.atan2(p.magnitude(), this.dotProduct(vectorB));
|
|
1303
|
+
if (vectorW.dotProduct(p) < 0.0)
|
|
1304
|
+
return -theta;
|
|
1305
|
+
else
|
|
1306
|
+
return theta;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Return the (strongly typed Angle) angle from this vector to vectorB, measured in the plane containing both,
|
|
1310
|
+
* with vectorW indicating which side to view to control sign of the angle.
|
|
1311
|
+
* * The returned angle can range from negative 180 degrees (negative PI radians) to positive 180 degrees
|
|
1312
|
+
* * (positive PI radians), not closed on the negative side.
|
|
1313
|
+
* * The returned angle is "in the plane containing the two vectors"
|
|
1314
|
+
* * `vectorW` distinguishes between the sides of the plane, but does not have to be perpendicular.
|
|
1315
|
+
* * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
|
|
1316
|
+
* @param vectorB target vector of rotation.
|
|
1317
|
+
* @param vectorW distinguishes between the sides of the plane.
|
|
1318
|
+
*/
|
|
1319
|
+
signedAngleTo(vectorB, vectorW) {
|
|
1320
|
+
return Angle.createRadians(this.signedRadiansTo(vectorB, vectorW));
|
|
1321
|
+
}
|
|
1173
1322
|
/**
|
|
1174
1323
|
* Return the (radians as a simple number, not strongly typed Angle) radians from this vector to vectorB.
|
|
1175
1324
|
* * The returned angle can be positive or negative, with magnitude no larger than PI radians
|
|
1176
1325
|
* * Use signedRadiansTo` to take have angle measured in other planes.
|
|
1177
1326
|
* @param vectorB target vector of rotation.
|
|
1327
|
+
* @param planeNormal a normal vector to the plane.
|
|
1178
1328
|
*/
|
|
1179
|
-
planarRadiansTo(
|
|
1329
|
+
planarRadiansTo(vectorB, planeNormal) {
|
|
1180
1330
|
const square = planeNormal.dotProduct(planeNormal);
|
|
1181
1331
|
if (square === 0.0)
|
|
1182
1332
|
return 0.0;
|
|
1183
1333
|
const factor = 1.0 / square;
|
|
1184
1334
|
const projection0 = this.plusScaled(planeNormal, -this.dotProduct(planeNormal) * factor);
|
|
1185
|
-
const projection1 =
|
|
1335
|
+
const projection1 = vectorB.plusScaled(planeNormal, -vectorB.dotProduct(planeNormal) * factor);
|
|
1186
1336
|
return projection0.signedRadiansTo(projection1, planeNormal);
|
|
1187
1337
|
}
|
|
1188
1338
|
/**
|
|
@@ -1190,86 +1340,67 @@ export class Vector3d extends XYZ {
|
|
|
1190
1340
|
* * The returned angle can range from negative PI to positive PI (not closed on negative side)
|
|
1191
1341
|
* * Use signedRadiansTo` to take have angle measured in other planes.
|
|
1192
1342
|
* @param vectorB target vector of rotation.
|
|
1343
|
+
* @param planeNormal a normal vector to the plane.
|
|
1193
1344
|
*/
|
|
1194
|
-
planarAngleTo(
|
|
1195
|
-
return Angle.createRadians(this.planarRadiansTo(
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Return the (simple number of radians, not Strongly typed Angle) angle from this vector to vectorB, measured in the plane containing both, with vectorW indicating which side to view to control sign of the angle.
|
|
1199
|
-
* * The returned angle can range from negative PI to positive PI (not closed on negative side)
|
|
1200
|
-
* * The returned angle is "in the plane containing the two vectors"
|
|
1201
|
-
* * `vectorW` distinguishes between the sides of the plane, but does not have to be perpendicular.
|
|
1202
|
-
* * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
|
|
1203
|
-
* @param vectorB target vector of rotation.
|
|
1204
|
-
*/
|
|
1205
|
-
signedRadiansTo(vector1, vectorW) {
|
|
1206
|
-
const p = this.crossProduct(vector1);
|
|
1207
|
-
const theta = Math.atan2(p.magnitude(), this.dotProduct(vector1));
|
|
1208
|
-
if (vectorW.dotProduct(p) < 0.0)
|
|
1209
|
-
return -theta;
|
|
1210
|
-
else
|
|
1211
|
-
return theta;
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Return the (strongly typed Angle) angle from this vector to vectorB, measured in the plane containing both, with vectorW indicating which side to view to control sign of the angle.
|
|
1215
|
-
* * The returned angle can range from negative 180 degrees (negative PI radians) to positive 180 degrees (positive PI radians), not closed on the negative side.
|
|
1216
|
-
* * The returned angle is "in the plane containing the two vectors"
|
|
1217
|
-
* * `vectorW` distinguishes between the sides of the plane, but does not have to be perpendicular.
|
|
1218
|
-
* * The returned angle has the same sign as vectorW dot product (thisVector cross vectorB)
|
|
1219
|
-
* @param vectorB target vector of rotation.
|
|
1220
|
-
*/
|
|
1221
|
-
signedAngleTo(vector1, vectorW) { return Angle.createRadians(this.signedRadiansTo(vector1, vectorW)); }
|
|
1222
|
-
/** Return the smallest (strongly typed) angle from the (bidirectional) line containing `this` to the (bidirectional) line containing `vectorB` */
|
|
1223
|
-
smallerUnorientedAngleTo(vectorB) {
|
|
1224
|
-
return Angle.createRadians(this.smallerUnorientedRadiansTo(vectorB));
|
|
1345
|
+
planarAngleTo(vectorB, planeNormal) {
|
|
1346
|
+
return Angle.createRadians(this.planarRadiansTo(vectorB, planeNormal));
|
|
1225
1347
|
}
|
|
1226
|
-
/** Return the smallest angle (in radians) from the (bidirectional) line containing `this`
|
|
1348
|
+
/** Return the smallest angle (in radians) from the (bidirectional) line containing `this`
|
|
1349
|
+
* to the (bidirectional) line containing `vectorB` */
|
|
1227
1350
|
smallerUnorientedRadiansTo(vectorB) {
|
|
1228
1351
|
const c = this.dotProduct(vectorB);
|
|
1229
1352
|
const s = this.crossProductMagnitude(vectorB);
|
|
1230
1353
|
return Math.atan2(Math.abs(s), Math.abs(c));
|
|
1231
1354
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
*/
|
|
1355
|
+
/** Return the smallest (strongly typed) angle from the (bidirectional) line containing `this`
|
|
1356
|
+
* to the (bidirectional) line containing `vectorB` */
|
|
1357
|
+
smallerUnorientedAngleTo(vectorB) {
|
|
1358
|
+
return Angle.createRadians(this.smallerUnorientedRadiansTo(vectorB));
|
|
1359
|
+
}
|
|
1238
1360
|
/**
|
|
1239
1361
|
* Test if this vector is parallel to other.
|
|
1362
|
+
* * The input tolerances in `options`, if given, are considered to be squared for efficiency's sake,
|
|
1363
|
+
* so if you have a distance or angle tolerance t, you should pass in t * t.
|
|
1240
1364
|
* @param other second vector in comparison
|
|
1241
|
-
* @param oppositeIsParallel
|
|
1365
|
+
* @param oppositeIsParallel whether to consider diametrically opposed vectors as parallel
|
|
1242
1366
|
* @param returnValueIfAnInputIsZeroLength if either vector is near zero length, return this value.
|
|
1367
|
+
* @param options optional radian and distance tolerances.
|
|
1243
1368
|
*/
|
|
1244
|
-
isParallelTo(other, oppositeIsParallel = false, returnValueIfAnInputIsZeroLength = false) {
|
|
1369
|
+
isParallelTo(other, oppositeIsParallel = false, returnValueIfAnInputIsZeroLength = false, options) {
|
|
1370
|
+
var _a, _b;
|
|
1371
|
+
const radianSquaredTol = (_a = options === null || options === void 0 ? void 0 : options.radianSquaredTol) !== null && _a !== void 0 ? _a : Geometry.smallAngleRadiansSquared;
|
|
1372
|
+
const distanceSquaredTol = (_b = options === null || options === void 0 ? void 0 : options.distanceSquaredTol) !== null && _b !== void 0 ? _b : Geometry.smallMetricDistanceSquared;
|
|
1245
1373
|
const a2 = this.magnitudeSquared();
|
|
1246
1374
|
const b2 = other.magnitudeSquared();
|
|
1247
|
-
|
|
1248
|
-
if (a2 < Geometry.smallMetricDistanceSquared || b2 < Geometry.smallMetricDistanceSquared)
|
|
1375
|
+
if (a2 < distanceSquaredTol || b2 < distanceSquaredTol)
|
|
1249
1376
|
return returnValueIfAnInputIsZeroLength;
|
|
1250
1377
|
const dot = this.dotProduct(other);
|
|
1251
1378
|
if (dot < 0.0 && !oppositeIsParallel)
|
|
1252
|
-
return
|
|
1379
|
+
return false;
|
|
1253
1380
|
const cross2 = this.crossProductMagnitudeSquared(other);
|
|
1254
1381
|
/* a2,b2,cross2 are squared lengths of respective vectors */
|
|
1255
1382
|
/* cross2 = sin^2(theta) * a2 * b2 */
|
|
1256
1383
|
/* For small theta, sin^2(theta)~~theta^2 */
|
|
1257
|
-
return cross2 <=
|
|
1384
|
+
return cross2 <= radianSquaredTol * a2 * b2;
|
|
1258
1385
|
}
|
|
1259
1386
|
/**
|
|
1260
1387
|
* Test if this vector is perpendicular to other.
|
|
1388
|
+
* * The input tolerances in `options`, if given, are considered to be squared for efficiency's sake,
|
|
1389
|
+
* so if you have a distance or angle tolerance t, you should pass in t * t.
|
|
1261
1390
|
* @param other second vector in comparison
|
|
1262
1391
|
* @param returnValueIfAnInputIsZeroLength if either vector is near zero length, return this value.
|
|
1392
|
+
* @param options optional radian and distance tolerances.
|
|
1263
1393
|
*/
|
|
1264
|
-
isPerpendicularTo(other, returnValueIfAnInputIsZeroLength = false) {
|
|
1394
|
+
isPerpendicularTo(other, returnValueIfAnInputIsZeroLength = false, options) {
|
|
1395
|
+
var _a, _b;
|
|
1396
|
+
const radianSquaredTol = (_a = options === null || options === void 0 ? void 0 : options.radianSquaredTol) !== null && _a !== void 0 ? _a : Geometry.smallAngleRadiansSquared;
|
|
1397
|
+
const distanceSquaredTol = (_b = options === null || options === void 0 ? void 0 : options.distanceSquaredTol) !== null && _b !== void 0 ? _b : Geometry.smallMetricDistanceSquared;
|
|
1265
1398
|
const aa = this.magnitudeSquared();
|
|
1266
|
-
if (aa < Geometry.smallMetricDistanceSquared)
|
|
1267
|
-
return returnValueIfAnInputIsZeroLength;
|
|
1268
1399
|
const bb = other.magnitudeSquared();
|
|
1269
|
-
if (bb <
|
|
1400
|
+
if (aa < distanceSquaredTol || bb < distanceSquaredTol)
|
|
1270
1401
|
return returnValueIfAnInputIsZeroLength;
|
|
1271
1402
|
const ab = this.dotProduct(other);
|
|
1272
|
-
return ab * ab <=
|
|
1403
|
+
return ab * ab <= radianSquaredTol * aa * bb;
|
|
1273
1404
|
}
|
|
1274
1405
|
}
|
|
1275
1406
|
//# sourceMappingURL=Point3dVector3d.js.map
|