@itwin/core-geometry 4.0.0-dev.70 → 4.0.0-dev.73
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/CHANGELOG.md +36 -3
- package/lib/cjs/curve/Query/PlanarSubdivision.d.ts +7 -1
- package/lib/cjs/curve/Query/PlanarSubdivision.d.ts.map +1 -1
- package/lib/cjs/curve/Query/PlanarSubdivision.js +14 -12
- package/lib/cjs/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/cjs/curve/RegionOps.d.ts +2 -2
- package/lib/cjs/curve/RegionOps.js +2 -2
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/geometry3d/BarycentricTriangle.d.ts +134 -90
- package/lib/cjs/geometry3d/BarycentricTriangle.d.ts.map +1 -1
- package/lib/cjs/geometry3d/BarycentricTriangle.js +192 -129
- package/lib/cjs/geometry3d/BarycentricTriangle.js.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.d.ts +38 -34
- package/lib/cjs/geometry3d/Ray3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.js +48 -45
- package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
- package/lib/esm/curve/Query/PlanarSubdivision.d.ts +7 -1
- package/lib/esm/curve/Query/PlanarSubdivision.d.ts.map +1 -1
- package/lib/esm/curve/Query/PlanarSubdivision.js +14 -12
- package/lib/esm/curve/Query/PlanarSubdivision.js.map +1 -1
- package/lib/esm/curve/RegionOps.d.ts +2 -2
- package/lib/esm/curve/RegionOps.js +2 -2
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/geometry3d/BarycentricTriangle.d.ts +134 -90
- package/lib/esm/geometry3d/BarycentricTriangle.d.ts.map +1 -1
- package/lib/esm/geometry3d/BarycentricTriangle.js +192 -129
- package/lib/esm/geometry3d/BarycentricTriangle.js.map +1 -1
- package/lib/esm/geometry3d/Ray3d.d.ts +38 -34
- package/lib/esm/geometry3d/Ray3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Ray3d.js +48 -45
- package/lib/esm/geometry3d/Ray3d.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarycentricTriangle.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/BarycentricTriangle.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"BarycentricTriangle.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/BarycentricTriangle.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,sBAAsB;IACjC,gDAAgD;IACzC,KAAK,EAAE,OAAO,CAAC;IACtB,4FAA4F;IACrF,KAAK,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAC3B,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IACnE,gBAAgB,EAAE,MAAM,CAAC;IAChC;;;;;OAKG;IACI,gBAAgB,EAAE,MAAM,CAAC;IAEhC,OAAO;IAOP,4DAA4D;IACrD,UAAU;IAOjB;;;OAGG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,sBAAsB;IAO7E;;;OAGG;IACI,gBAAgB,CAAC,KAAK,EAAE,sBAAsB;IAOrD,sCAAsC;IACtC,IAAW,OAAO,IAAI,OAAO,CAE5B;IACD;;;;OAIG;IACH,IAAW,YAAY,IAAI,OAAO,CAEjC;IACD;;;;OAIG;IACH,IAAW,QAAQ,IAAI,eAAe,CAoBrC;CACF;AAED;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,qDAAqD;IAC9C,MAAM,EAAE,OAAO,EAAE,CAAC;IACzB,kEAAkE;IAClE,S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|
@@ -12,17 +12,23 @@ import { Point3d, Vector3d } from "./Point3dVector3d";
|
|
|
12
12
|
import { Ray3d } from "./Ray3d";
|
|
13
13
|
/**
|
|
14
14
|
* Carries data about a location in the plane of a triangle.
|
|
15
|
-
* * Each instance carries both world and barycentric coordinates for the point, and provides query
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* * Each instance carries both world and barycentric coordinates for the point, and provides query
|
|
16
|
+
* services on the latter.
|
|
17
|
+
* * No tolerance is used when querying barycentric coordinates (e.g., `isInsideOrOn`, `classify`). Use
|
|
18
|
+
* [[BarycentricTriangle.snapLocationToEdge]] to adjust the barycentric coordinates to a triangle edge
|
|
19
|
+
* if they lie within a distance or parametric tolerance.
|
|
18
20
|
*
|
|
19
|
-
* Properties of the barycentric coordinates (b0, b1, b2) of a point p in the plane of a triangle
|
|
20
|
-
*
|
|
21
|
-
* *
|
|
22
|
-
* *
|
|
23
|
-
* *
|
|
24
|
-
*
|
|
25
|
-
* *
|
|
21
|
+
* Properties of the barycentric coordinates `(b0, b1, b2)` of a point `p` in the plane of a triangle
|
|
22
|
+
* `T` with vertices `v0, v1, v2`:
|
|
23
|
+
* * `1 = b0 + b1 + b2`
|
|
24
|
+
* * `p = b0 * v0 + b1 * v1 + b2 * v2`
|
|
25
|
+
* * If T is spanned by the vectors `U = v1 - v0` and `V = v2 - v0`, then the vector `P = p - v0` can
|
|
26
|
+
* be written `P = b1 * U + b2 * V`.
|
|
27
|
+
* * The coordinates are all nonnegative if and only if `p` is inside or on `T`.
|
|
28
|
+
* * Exactly one coordinate is zero if and only if `p` lies on an (infinitely extended) edge of `T`.
|
|
29
|
+
* * Exactly two coordinates are zero if and only if `p` coincides with a vertex of `T`.
|
|
30
|
+
* * Note that if `p` can be written as a linear combination of the vertices of `T` using scales that do
|
|
31
|
+
* NOT sum to 1, then `p` is not coplanar with `T`
|
|
26
32
|
* @public
|
|
27
33
|
*/
|
|
28
34
|
export class TriangleLocationDetail {
|
|
@@ -33,7 +39,7 @@ export class TriangleLocationDetail {
|
|
|
33
39
|
this.closestEdgeIndex = 0;
|
|
34
40
|
this.closestEdgeParam = 0.0;
|
|
35
41
|
}
|
|
36
|
-
/** Invalidate this detail. */
|
|
42
|
+
/** Invalidate this detail (set all attributes to zero) . */
|
|
37
43
|
invalidate() {
|
|
38
44
|
this.world.setZero();
|
|
39
45
|
this.local.setZero();
|
|
@@ -41,7 +47,8 @@ export class TriangleLocationDetail {
|
|
|
41
47
|
this.closestEdgeIndex = 0;
|
|
42
48
|
this.closestEdgeParam = 0.0;
|
|
43
49
|
}
|
|
44
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Create an invalid detail.
|
|
45
52
|
* @param result optional pre-allocated object to fill and return
|
|
46
53
|
*/
|
|
47
54
|
static create(result) {
|
|
@@ -51,7 +58,8 @@ export class TriangleLocationDetail {
|
|
|
51
58
|
result.invalidate();
|
|
52
59
|
return result;
|
|
53
60
|
}
|
|
54
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Set the instance contents from the `other` detail.
|
|
55
63
|
* @param other detail to clone
|
|
56
64
|
*/
|
|
57
65
|
copyContentsFrom(other) {
|
|
@@ -65,13 +73,16 @@ export class TriangleLocationDetail {
|
|
|
65
73
|
get isValid() {
|
|
66
74
|
return !this.local.isZero;
|
|
67
75
|
}
|
|
68
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Queries the barycentric coordinates to determine whether this instance specifies a location inside or
|
|
78
|
+
* on the triangle.
|
|
69
79
|
* @see classify
|
|
70
80
|
*/
|
|
71
81
|
get isInsideOrOn() {
|
|
72
82
|
return this.isValid && this.local.x >= 0.0 && this.local.y >= 0.0 && this.local.z >= 0.0;
|
|
73
83
|
}
|
|
74
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Queries this detail to classify the location of this instance with respect to the triangle.
|
|
75
86
|
* @returns location code
|
|
76
87
|
* @see isInsideOrOn
|
|
77
88
|
*/
|
|
@@ -92,7 +103,9 @@ export class TriangleLocationDetail {
|
|
|
92
103
|
return PolygonLocation.OnPolygonEdgeInterior;
|
|
93
104
|
return PolygonLocation.InsidePolygonProjectsToEdgeInterior;
|
|
94
105
|
}
|
|
95
|
-
return (this.closestEdgeParam === 0.0) ?
|
|
106
|
+
return (this.closestEdgeParam === 0.0) ?
|
|
107
|
+
PolygonLocation.OutsidePolygonProjectsToVertex :
|
|
108
|
+
PolygonLocation.OutsidePolygonProjectsToEdgeInterior;
|
|
96
109
|
}
|
|
97
110
|
}
|
|
98
111
|
/**
|
|
@@ -100,7 +113,8 @@ export class TriangleLocationDetail {
|
|
|
100
113
|
* @public
|
|
101
114
|
*/
|
|
102
115
|
export class BarycentricTriangle {
|
|
103
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Constructor.
|
|
104
118
|
* * Point references are CAPTURED
|
|
105
119
|
*/
|
|
106
120
|
constructor(point0, point1, point2) {
|
|
@@ -114,7 +128,26 @@ export class BarycentricTriangle {
|
|
|
114
128
|
this.edgeLength2.push(point0.distanceSquared(point1));
|
|
115
129
|
}
|
|
116
130
|
/**
|
|
117
|
-
*
|
|
131
|
+
* Copy contents of (not pointers to) the given points. A vertex is zeroed if its corresponding input point
|
|
132
|
+
* is undefined.
|
|
133
|
+
*/
|
|
134
|
+
set(point0, point1, point2) {
|
|
135
|
+
this.points[0].setFromPoint3d(point0);
|
|
136
|
+
this.points[1].setFromPoint3d(point1);
|
|
137
|
+
this.points[2].setFromPoint3d(point2);
|
|
138
|
+
this.edgeLength2[0] = this.points[1].distanceSquared(this.points[2]);
|
|
139
|
+
this.edgeLength2[1] = this.points[0].distanceSquared(this.points[2]);
|
|
140
|
+
this.edgeLength2[2] = this.points[0].distanceSquared(this.points[1]);
|
|
141
|
+
}
|
|
142
|
+
/** Copy all values from `other` */
|
|
143
|
+
setFrom(other) {
|
|
144
|
+
for (let i = 0; i < 3; ++i) {
|
|
145
|
+
this.points[i].setFromPoint3d(other.points[i]);
|
|
146
|
+
this.edgeLength2[i] = other.edgeLength2[i];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create a `BarycentricTriangle` with coordinates given by enumerated x,y,z of the 3 points.
|
|
118
151
|
* @param result optional pre-allocated triangle.
|
|
119
152
|
*/
|
|
120
153
|
static createXYZXYZXYZ(x0, y0, z0, x1, y1, z1, x2, y2, z2, result) {
|
|
@@ -125,7 +158,7 @@ export class BarycentricTriangle {
|
|
|
125
158
|
result.points[2].set(x2, y2, z2);
|
|
126
159
|
return result;
|
|
127
160
|
}
|
|
128
|
-
/**
|
|
161
|
+
/** Create a triangle with coordinates cloned from given points. */
|
|
129
162
|
static create(point0, point1, point2, result) {
|
|
130
163
|
if (!result)
|
|
131
164
|
return new this(point0.clone(), point1.clone(), point2.clone());
|
|
@@ -136,46 +169,76 @@ export class BarycentricTriangle {
|
|
|
136
169
|
clone(result) {
|
|
137
170
|
return BarycentricTriangle.create(this.points[0], this.points[1], this.points[2], result);
|
|
138
171
|
}
|
|
139
|
-
/** Return area divided by sum of squared lengths. */
|
|
140
|
-
get aspectRatio() {
|
|
141
|
-
return Geometry.safeDivideFraction(this.area, this.edgeLengthSquared(0) + this.edgeLengthSquared(1) + this.edgeLengthSquared(2), 0);
|
|
142
|
-
}
|
|
143
172
|
/** Return the area of the triangle. */
|
|
144
173
|
get area() {
|
|
174
|
+
// The magnitude of the cross product A × B is the area of the parallelogram spanned by A and B.
|
|
145
175
|
return 0.5 * this.points[0].crossProductToPointsMagnitude(this.points[1], this.points[2]);
|
|
146
176
|
}
|
|
147
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Compute squared length of the triangle edge opposite the vertex with the given index.
|
|
179
|
+
* @see [[edgeStartVertexIndexToOppositeVertexIndex]]
|
|
180
|
+
*/
|
|
181
|
+
edgeLengthSquared(oppositeVertexIndex) {
|
|
182
|
+
return this.edgeLength2[Geometry.cyclic3dAxis(oppositeVertexIndex)];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Compute length of the triangle edge opposite the vertex with the given index.
|
|
186
|
+
* @see [[edgeStartVertexIndexToOppositeVertexIndex]]
|
|
187
|
+
*/
|
|
188
|
+
edgeLength(oppositeVertexIndex) {
|
|
189
|
+
return Math.sqrt(this.edgeLengthSquared(oppositeVertexIndex));
|
|
190
|
+
}
|
|
191
|
+
/** Return area divided by sum of squared lengths. */
|
|
192
|
+
get aspectRatio() {
|
|
193
|
+
return Geometry.safeDivideFraction(this.area, this.edgeLengthSquared(0) + this.edgeLengthSquared(1) + this.edgeLengthSquared(2), 0);
|
|
194
|
+
}
|
|
195
|
+
/** Return the perimeter of the triangle. */
|
|
148
196
|
get perimeter() {
|
|
149
197
|
return this.edgeLength(0) + this.edgeLength(1) + this.edgeLength(2);
|
|
150
198
|
}
|
|
151
|
-
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
199
|
+
/**
|
|
200
|
+
* Return the unit normal of the triangle.
|
|
201
|
+
* @param result optional pre-allocated vector to fill and return.
|
|
202
|
+
* @returns unit normal, or undefined if cross product length is too small.
|
|
203
|
+
*/
|
|
204
|
+
normal(result) {
|
|
205
|
+
const cross = this.points[0].crossProductToPoints(this.points[1], this.points[2], result);
|
|
206
|
+
if (cross.tryNormalizeInPlace())
|
|
207
|
+
return cross;
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Sum the triangle points with given scales.
|
|
212
|
+
* * If the scales sum to 1, they are barycentric coordinates, and hence the result point is in the plane of
|
|
213
|
+
* the triangle. If all coordinates are non-negative then the result point is inside the triangle.
|
|
214
|
+
* * If the scales do not sum to 1, the point is inside the triangle scaled (by the scale sum) from the origin.
|
|
154
215
|
* @param b0 scale to apply to vertex 0
|
|
155
216
|
* @param b1 scale to apply to vertex 1
|
|
156
217
|
* @param b2 scale to apply to vertex 2
|
|
157
218
|
* @param result optional pre-allocated point to fill and return
|
|
158
219
|
* @return linear combination of the vertices of this triangle
|
|
159
|
-
* @see pointToFraction
|
|
220
|
+
* @see [[pointToFraction]]
|
|
160
221
|
*/
|
|
161
222
|
fractionToPoint(b0, b1, b2, result) {
|
|
223
|
+
// p = b0 * v0 + b1 * v1 + b2 * v2
|
|
162
224
|
return Point3d.createAdd3Scaled(this.points[0], b0, this.points[1], b1, this.points[2], b2, result);
|
|
163
225
|
}
|
|
164
|
-
/**
|
|
226
|
+
/**
|
|
227
|
+
* Compute the projection of the given `point` onto the plane of this triangle.
|
|
165
228
|
* @param point point p to project
|
|
166
229
|
* @param result optional pre-allocated object to fill and return
|
|
167
|
-
* @returns details d of the projection point P =
|
|
230
|
+
* @returns details d of the projection point `P = d.world`:
|
|
168
231
|
* * `d.isValid` returns true if and only if `this.normal()` is defined.
|
|
169
232
|
* * `d.classify` can be used to determine where P lies with respect to the triangle.
|
|
170
|
-
* * `d.a` is the signed projection distance: P = p + a *
|
|
171
|
-
* @see fractionToPoint
|
|
233
|
+
* * `d.a` is the signed projection distance: `P = p + a * this.normal()`.
|
|
234
|
+
* @see [[fractionToPoint]]
|
|
172
235
|
*/
|
|
173
236
|
pointToFraction(point, result) {
|
|
174
237
|
const normal = BarycentricTriangle._workVector0 = this.normal(BarycentricTriangle._workVector0);
|
|
175
238
|
if (undefined === normal)
|
|
176
239
|
return TriangleLocationDetail.create(result);
|
|
177
240
|
const ray = BarycentricTriangle._workRay = Ray3d.create(point, normal, BarycentricTriangle._workRay);
|
|
178
|
-
return this.intersectRay3d(ray, result); // is free to use workVector0
|
|
241
|
+
return this.intersectRay3d(ray, result); // intersectRay3d is free to use workVector0
|
|
179
242
|
}
|
|
180
243
|
/** Convert from opposite-vertex to start-vertex edge indexing. */
|
|
181
244
|
static edgeOppositeVertexIndexToStartVertexIndex(edgeIndex) {
|
|
@@ -185,7 +248,8 @@ export class BarycentricTriangle {
|
|
|
185
248
|
static edgeStartVertexIndexToOppositeVertexIndex(startVertexIndex) {
|
|
186
249
|
return Geometry.cyclic3dAxis(startVertexIndex - 1);
|
|
187
250
|
}
|
|
188
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Examine a point's barycentric coordinates to determine if it lies inside the triangle but not on an edge/vertex.
|
|
189
253
|
* * No parametric tolerance is used.
|
|
190
254
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
191
255
|
* @returns whether the point with barycentric coordinates is strictly inside the triangle.
|
|
@@ -193,7 +257,8 @@ export class BarycentricTriangle {
|
|
|
193
257
|
static isInsideTriangle(b0, b1, b2) {
|
|
194
258
|
return b0 > 0 && b1 > 0 && b2 > 0;
|
|
195
259
|
}
|
|
196
|
-
/**
|
|
260
|
+
/**
|
|
261
|
+
* Examine a point's barycentric coordinates to determine if it lies inside the triangle or on an edge/vertex.
|
|
197
262
|
* * No parametric tolerance is used.
|
|
198
263
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
199
264
|
* @returns whether the point with barycentric coordinates is inside or on the triangle.
|
|
@@ -201,12 +266,15 @@ export class BarycentricTriangle {
|
|
|
201
266
|
static isInsideOrOnTriangle(b0, b1, b2) {
|
|
202
267
|
return b0 >= 0 && b1 >= 0 && b2 >= 0;
|
|
203
268
|
}
|
|
204
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Examine a point's barycentric coordinates to determine if it lies outside an edge of the triangle.
|
|
205
271
|
* * No parametric tolerance is used.
|
|
206
272
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
207
|
-
* @returns index
|
|
273
|
+
* @returns edge index i (opposite vertex i) for which b_i < 0 and b_j >= 0, and b_k >= 0. Otherwise, returns -1.
|
|
208
274
|
*/
|
|
209
275
|
static isInRegionBeyondEdge(b0, b1, b2) {
|
|
276
|
+
// Note: the 3 regions (specified by the following if statements) are defined by extending the triangle
|
|
277
|
+
// edges to infinity and not by perpendicular lines to the edges (which gives smaller regions)
|
|
210
278
|
if (b0 < 0 && b1 >= 0 && b2 >= 0)
|
|
211
279
|
return 0;
|
|
212
280
|
if (b0 >= 0 && b1 < 0 && b2 >= 0)
|
|
@@ -215,12 +283,15 @@ export class BarycentricTriangle {
|
|
|
215
283
|
return 2;
|
|
216
284
|
return -1;
|
|
217
285
|
}
|
|
218
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Examine a point's barycentric coordinates to determine if it lies outside a vertex of the triangle.
|
|
219
288
|
* * No parametric tolerance is used.
|
|
220
289
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
221
|
-
* @returns index of vertex i for which
|
|
290
|
+
* @returns index of vertex i for which b_j < 0 and b_k < 0. Otherwise, returns -1.
|
|
222
291
|
*/
|
|
223
292
|
static isInRegionBeyondVertex(b0, b1, b2) {
|
|
293
|
+
// Note: the 3 regions (specified by the following if statements) are defined by extending the triangle
|
|
294
|
+
// edges to infinity and not by perpendicular lines to the edges (which gives larger regions)
|
|
224
295
|
if (b1 < 0 && b2 < 0)
|
|
225
296
|
return 0;
|
|
226
297
|
if (b0 < 0 && b2 < 0)
|
|
@@ -229,10 +300,11 @@ export class BarycentricTriangle {
|
|
|
229
300
|
return 2;
|
|
230
301
|
return -1;
|
|
231
302
|
}
|
|
232
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* Examine a point's barycentric coordinates to determine if it lies on a vertex of the triangle.
|
|
233
305
|
* * No parametric tolerance is used.
|
|
234
306
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
235
|
-
* @returns index of vertex i for which b_i = 1 and b_j = b_k = 0,
|
|
307
|
+
* @returns index of vertex i for which b_i = 1 and b_j = b_k = 0. Otherwise, returns -1.
|
|
236
308
|
*/
|
|
237
309
|
static isOnVertex(b0, b1, b2) {
|
|
238
310
|
if (b0 === 1 && b1 === 0 && b2 === 0)
|
|
@@ -243,10 +315,11 @@ export class BarycentricTriangle {
|
|
|
243
315
|
return 2;
|
|
244
316
|
return -1;
|
|
245
317
|
}
|
|
246
|
-
/**
|
|
318
|
+
/**
|
|
319
|
+
* Examine a point's barycentric coordinates to determine if it lies on a bounded edge of the triangle.
|
|
247
320
|
* * No parametric tolerance is used.
|
|
248
321
|
* * It is assumed b0 + b1 + b2 = 1.
|
|
249
|
-
* @returns index
|
|
322
|
+
* @returns edge index i (opposite vertex i) for which b_i = 0, b_j > 0, and b_k > 0. Otherwise, returns -1.
|
|
250
323
|
*/
|
|
251
324
|
static isOnBoundedEdge(b0, b1, b2) {
|
|
252
325
|
if (b0 === 0 && b1 > 0 && b2 > 0)
|
|
@@ -270,35 +343,70 @@ export class BarycentricTriangle {
|
|
|
270
343
|
i = 2;
|
|
271
344
|
return i;
|
|
272
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Compute the squared distance between two points given by their barycentric coordinates.
|
|
348
|
+
* * It is assumed that a0 + a1 + a2 = b0 + b1 + b2 = 1.
|
|
349
|
+
*/
|
|
350
|
+
distanceSquared(a0, a1, a2, b0, b1, b2) {
|
|
351
|
+
// The barycentric displacement vector distance formula
|
|
352
|
+
// More details can be found at https://web.evanchen.cc/handouts/bary/bary-full.pdf
|
|
353
|
+
return -this.edgeLengthSquared(0) * (b1 - a1) * (b2 - a2)
|
|
354
|
+
- this.edgeLengthSquared(1) * (b2 - a2) * (b0 - a0)
|
|
355
|
+
- this.edgeLengthSquared(2) * (b0 - a0) * (b1 - a1);
|
|
356
|
+
}
|
|
273
357
|
/** Return the index of the closest triangle vertex to the point given by its barycentric coordinates. */
|
|
274
358
|
closestVertexIndex(b0, b1, b2) {
|
|
275
359
|
return BarycentricTriangle.indexOfMinimum((i) => {
|
|
276
360
|
const a = BarycentricTriangle._workPoint = Point3d.createZero(BarycentricTriangle._workPoint);
|
|
277
|
-
a.setAt(i, 1.0);
|
|
278
|
-
return this.distanceSquared(a.x, a.y, a.z, b0, b1, b2);
|
|
361
|
+
a.setAt(i, 1.0); // "a" is (1,0,0) or (0,1,0) or (0,0,1) so "a" represents vertex i
|
|
362
|
+
return this.distanceSquared(a.x, a.y, a.z, b0, b1, b2); // distance between the point and vertex i
|
|
279
363
|
});
|
|
280
364
|
}
|
|
281
|
-
/** Compute
|
|
365
|
+
/** Compute dot product of the edge vectors based at the vertex with the given index. */
|
|
366
|
+
dotProductOfEdgeVectorsAtVertex(baseVertexIndex) {
|
|
367
|
+
const i = Geometry.cyclic3dAxis(baseVertexIndex);
|
|
368
|
+
const j = Geometry.cyclic3dAxis(i + 1);
|
|
369
|
+
const k = Geometry.cyclic3dAxis(j + 1);
|
|
370
|
+
return Geometry.dotProductXYZXYZ(this.points[j].x - this.points[i].x, this.points[j].y - this.points[i].y, this.points[j].z - this.points[i].z, this.points[k].x - this.points[i].x, this.points[k].y - this.points[i].y, this.points[k].z - this.points[i].z);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Compute the projection of barycentric point p onto the (unbounded) edge e_k(v_i,v_j) of the triangle T(v_i,v_j,v_k).
|
|
282
374
|
* @param k vertex v_k is opposite the edge e_k
|
|
283
375
|
* @param b barycentric coordinates of point to project
|
|
284
|
-
* @returns parameter
|
|
285
|
-
* * the projection point is q = v_i +
|
|
286
|
-
* * the barycentric coords of the projection are q_ijk = (1 -
|
|
376
|
+
* @returns parameter f along e_k, such that:
|
|
377
|
+
* * the projection point is q = v_i + f * (v_j - v_i)
|
|
378
|
+
* * the barycentric coords of the projection are q_ijk = (1 - f, f, 0)
|
|
287
379
|
*/
|
|
288
380
|
computeProjectionToEdge(k, b) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
381
|
+
/**
|
|
382
|
+
* We know p = (b_i*v_i) + (b_j*v_j) + (b_k*v_k) and 1 = b_i + b_j + b_k.
|
|
383
|
+
* Let U = v_j - v_i and V = v_k - v_i and P = p - v_i.
|
|
384
|
+
* First we prove P = b_jU + b_kV.
|
|
385
|
+
* P = (b_i * v_i) + (b_j * v_j) + (b_k * v_k) - v_i
|
|
386
|
+
* = (b_i * v_i) + (b_j * (v_j-v_i)) + (b_j * v_i) + (b_k * (v_k-v_i)) + (b_k * v_i) - v_i
|
|
387
|
+
* = (b_i * v_i) + (b_j * U) + (b_j * v_i) + (b_k * V) + (b_k * v_i) - v_i
|
|
388
|
+
* = (b_j * U) + (b_k * V) + ((b_i + b_j + b_k) * v_i) - v_i
|
|
389
|
+
* = (b_j * U) + (b_k * V) + v_i - v_i
|
|
390
|
+
* = (b_j * U) + (b_k * V)
|
|
391
|
+
* So we know p - v_i = b_jU + b_kV and q - v_i = fU
|
|
392
|
+
* Therefore, 0 = (p - q).(v_j - v_i)
|
|
393
|
+
* = ((p-v_i) - (q-v_i)).(v_j - v_i)
|
|
394
|
+
* = (b_jU + b_kV - fU).U
|
|
395
|
+
* = b_jU.U + b_kU.V - fU.U
|
|
396
|
+
* Thus f = b_j + b_k(U.V/U.U)
|
|
397
|
+
*/
|
|
292
398
|
k = Geometry.cyclic3dAxis(k);
|
|
293
399
|
const i = Geometry.cyclic3dAxis(k + 1);
|
|
294
400
|
const j = Geometry.cyclic3dAxis(i + 1);
|
|
295
401
|
return b[j] + b[k] * this.dotProductOfEdgeVectorsAtVertex(i) / this.edgeLengthSquared(k);
|
|
296
402
|
}
|
|
297
|
-
/**
|
|
403
|
+
/**
|
|
404
|
+
* Compute the projection of a barycentric point p to the triangle T(v_0,v_1,v_2).
|
|
298
405
|
* @param b0 barycentric coordinate of p corresponding to v_0
|
|
299
406
|
* @param b1 barycentric coordinate of p corresponding to v_1
|
|
300
407
|
* @param b2 barycentric coordinate of p corresponding to v_2
|
|
301
|
-
* @returns closest edge start vertex index i and projection parameter
|
|
408
|
+
* @returns closest edge start vertex index i and projection parameter f such that the projection
|
|
409
|
+
* q = v_i + f * (v_j - v_i).
|
|
302
410
|
*/
|
|
303
411
|
closestPoint(b0, b1, b2) {
|
|
304
412
|
const b = [b0, b1, b2];
|
|
@@ -307,7 +415,7 @@ export class BarycentricTriangle {
|
|
|
307
415
|
if (BarycentricTriangle.isInsideTriangle(b0, b1, b2)) { // projects to any edge
|
|
308
416
|
edgeIndex = BarycentricTriangle.indexOfMinimum((i) => {
|
|
309
417
|
// We want smallest projection distance d_i of p to e_i.
|
|
310
|
-
// Since
|
|
418
|
+
// Since b_i=d_i|e_i|/2A we can compare quantities b_i/|e_i|.
|
|
311
419
|
return b[i] * b[i] / this.edgeLengthSquared(i); // avoid sqrt
|
|
312
420
|
});
|
|
313
421
|
edgeParam = this.computeProjectionToEdge(edgeIndex, b);
|
|
@@ -348,20 +456,24 @@ export class BarycentricTriangle {
|
|
|
348
456
|
closestEdgeParam: edgeParam,
|
|
349
457
|
};
|
|
350
458
|
}
|
|
351
|
-
/**
|
|
459
|
+
/**
|
|
460
|
+
* Compute the intersection of a line (parameterized as a ray) with the plane of this triangle.
|
|
352
461
|
* @param ray infinite line to intersect, as a ray
|
|
353
462
|
* @param result optional pre-allocated object to fill and return
|
|
354
|
-
* @returns details d of the line-plane intersection `d.
|
|
355
|
-
* * `d.
|
|
463
|
+
* @returns details d of the line-plane intersection point `d.world`:
|
|
464
|
+
* * `d.a` is the intersection parameter along the ray.
|
|
465
|
+
* * The line intersects the plane of the triangle if and only if `d.isValid` returns true.
|
|
466
|
+
* * The ray intersects the plane of the triangle if and only if `d.isValid` returns true and `d.a` >= 0.
|
|
467
|
+
* * The ray intersects the triangle if and only if `d.isValid` returns true, `d.a` >= 0, and `d.isInsideOrOn`
|
|
468
|
+
* returns true.
|
|
356
469
|
* * `d.classify` can be used to determine where the intersection lies with respect to the triangle.
|
|
357
|
-
*
|
|
358
|
-
* @see pointToFraction
|
|
470
|
+
* @see [[pointToFraction]]
|
|
359
471
|
*/
|
|
360
472
|
intersectRay3d(ray, result) {
|
|
361
473
|
result = TriangleLocationDetail.create(result);
|
|
362
474
|
// Let r0 = ray.origin, d = ray.direction. Write intersection point p two ways for unknown scalars s,b0,b1,b2:
|
|
363
|
-
// r0 + s*d = p = b0*
|
|
364
|
-
// Subtract
|
|
475
|
+
// r0 + s*d = p = b0*v0 + b1*v1 + b2*v2
|
|
476
|
+
// Subtract v0 from both ends, let u=v1-v0, v=v2-v0, c=r0-v0, and enforce b0+b1+b2=1:
|
|
365
477
|
// b1*u + b2*v - s*d = c
|
|
366
478
|
// This is a linear system Mx=c where M has columns u,v,d and solution x=(b1,b2,-s).
|
|
367
479
|
const r0 = ray.origin;
|
|
@@ -381,22 +493,25 @@ export class BarycentricTriangle {
|
|
|
381
493
|
result.closestEdgeParam = proj.closestEdgeParam;
|
|
382
494
|
return result;
|
|
383
495
|
}
|
|
384
|
-
/**
|
|
496
|
+
/**
|
|
497
|
+
* Compute the intersection of a line (parameterized as a line segment) with the plane of this triangle.
|
|
385
498
|
* @param point0 start point of segment on line to intersect
|
|
386
499
|
* @param point1 end point of segment on line to intersect
|
|
387
500
|
* @param result optional pre-allocated object to fill and return
|
|
388
|
-
* @returns details d of the line-plane intersection `d.
|
|
501
|
+
* @returns details d of the line-plane intersection point `d.world`:
|
|
389
502
|
* * `d.isValid` returns true if and only if the line intersects the plane.
|
|
390
503
|
* * `d.classify` can be used to determine where the intersection lies with respect to the triangle.
|
|
391
504
|
* * `d.a` is the intersection parameter. If `d.a` is in [0,1], the segment intersects the plane of the triangle.
|
|
392
|
-
* @see intersectRay3d
|
|
505
|
+
* @see [[intersectRay3d]]
|
|
393
506
|
*/
|
|
394
507
|
intersectSegment(point0, point1, result) {
|
|
395
508
|
BarycentricTriangle._workRay = Ray3d.createStartEnd(point0, point1, BarycentricTriangle._workRay);
|
|
396
509
|
return this.intersectRay3d(BarycentricTriangle._workRay, result);
|
|
397
510
|
}
|
|
398
|
-
/**
|
|
399
|
-
*
|
|
511
|
+
/**
|
|
512
|
+
* Adjust the location to the closest edge of the triangle if within either given tolerance.
|
|
513
|
+
* @param location details of a point in the plane of the triangle (note that `location.local` and
|
|
514
|
+
* `location.world` possibly updated to lie on the triangle closest edge)
|
|
400
515
|
* @param distanceTolerance absolute distance tolerance (or zero to ignore)
|
|
401
516
|
* @param parameterTolerance barycentric coordinate fractional tolerance (or zero to ignore)
|
|
402
517
|
* @return whether the location was adjusted
|
|
@@ -447,26 +562,11 @@ export class BarycentricTriangle {
|
|
|
447
562
|
}
|
|
448
563
|
return false;
|
|
449
564
|
}
|
|
450
|
-
/** Copy all values from `other`
|
|
451
|
-
*/
|
|
452
|
-
setFrom(other) {
|
|
453
|
-
for (let i = 0; i < 3; ++i) {
|
|
454
|
-
this.points[i].setFromPoint3d(other.points[i]);
|
|
455
|
-
this.edgeLength2[i] = other.edgeLength2[i];
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
/** Copy contents of (not pointers to) the given points. A vertex is zeroed if its corresponding input point is undefined. */
|
|
459
|
-
set(point0, point1, point2) {
|
|
460
|
-
this.points[0].setFromPoint3d(point0);
|
|
461
|
-
this.points[1].setFromPoint3d(point1);
|
|
462
|
-
this.points[2].setFromPoint3d(point2);
|
|
463
|
-
this.edgeLength2[0] = this.points[1].distanceSquared(this.points[2]);
|
|
464
|
-
this.edgeLength2[1] = this.points[0].distanceSquared(this.points[2]);
|
|
465
|
-
this.edgeLength2[2] = this.points[0].distanceSquared(this.points[1]);
|
|
466
|
-
}
|
|
467
565
|
/**
|
|
468
|
-
*
|
|
469
|
-
* *
|
|
566
|
+
* Return the dot product of the scaled normals of the two triangles.
|
|
567
|
+
* * The sign of the return value is useful for determining the triangles' relative orientation:
|
|
568
|
+
* positive (negative) means the normals point into the same (opposite) half-space determined by
|
|
569
|
+
* one of the triangles' planes; zero means the triangles are perpendicular.
|
|
470
570
|
*/
|
|
471
571
|
dotProductOfCrossProductsFromOrigin(other) {
|
|
472
572
|
BarycentricTriangle._workVector0 = this.points[0].crossProductToPoints(this.points[1], this.points[2], BarycentricTriangle._workVector0);
|
|
@@ -475,8 +575,7 @@ export class BarycentricTriangle {
|
|
|
475
575
|
}
|
|
476
576
|
/** Return the centroid of the 3 points. */
|
|
477
577
|
centroid(result) {
|
|
478
|
-
//
|
|
479
|
-
// Do the scale as true division (rather than multiply by precomputed 1/3). This might protect one bit of result.
|
|
578
|
+
// Do the scale as true division (rather than multiply by precomputed 1/3). This might protect one bit of result.
|
|
480
579
|
return Point3d.create((this.points[0].x + this.points[1].x + this.points[2].x) / 3.0, (this.points[0].y + this.points[1].y + this.points[2].y) / 3.0, (this.points[0].z + this.points[1].z + this.points[2].z) / 3.0, result);
|
|
481
580
|
}
|
|
482
581
|
/** Return the incenter of the triangle. */
|
|
@@ -498,47 +597,11 @@ export class BarycentricTriangle {
|
|
|
498
597
|
const scale = Geometry.safeDivideFraction(1.0, x + y + z, 0.0);
|
|
499
598
|
return this.fractionToPoint(scale * x, scale * y, scale * z, result);
|
|
500
599
|
}
|
|
501
|
-
/**
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const cross = this.points[0].crossProductToPoints(this.points[1], this.points[2], result);
|
|
507
|
-
if (cross.tryNormalizeInPlace())
|
|
508
|
-
return cross;
|
|
509
|
-
return undefined;
|
|
510
|
-
}
|
|
511
|
-
/** test for point-by-point `isAlmostEqual` relationship. */
|
|
512
|
-
isAlmostEqual(other) {
|
|
513
|
-
return this.points[0].isAlmostEqual(other.points[0])
|
|
514
|
-
&& this.points[1].isAlmostEqual(other.points[1])
|
|
515
|
-
&& this.points[2].isAlmostEqual(other.points[2]);
|
|
516
|
-
}
|
|
517
|
-
/** Compute length of the triangle edge opposite the vertex with the given index.
|
|
518
|
-
* @see edgeStartVertexIndexToOppositeVertexIndex
|
|
519
|
-
*/
|
|
520
|
-
edgeLength(oppositeVertexIndex) {
|
|
521
|
-
return Math.sqrt(this.edgeLengthSquared(oppositeVertexIndex));
|
|
522
|
-
}
|
|
523
|
-
/** Compute squared length of the triangle edge opposite the vertex with the given index.
|
|
524
|
-
* @see edgeStartVertexIndexToOppositeVertexIndex
|
|
525
|
-
*/
|
|
526
|
-
edgeLengthSquared(oppositeVertexIndex) {
|
|
527
|
-
return this.edgeLength2[Geometry.cyclic3dAxis(oppositeVertexIndex)];
|
|
528
|
-
}
|
|
529
|
-
/** Compute dot product of the edge vectors based at the vertex with the given index. */
|
|
530
|
-
dotProductOfEdgeVectorsAtVertex(baseVertexIndex) {
|
|
531
|
-
const i = Geometry.cyclic3dAxis(baseVertexIndex);
|
|
532
|
-
const j = Geometry.cyclic3dAxis(i + 1);
|
|
533
|
-
const k = Geometry.cyclic3dAxis(j + 1);
|
|
534
|
-
return Geometry.dotProductXYZXYZ(this.points[j].x - this.points[i].x, this.points[j].y - this.points[i].y, this.points[j].z - this.points[i].z, this.points[k].x - this.points[i].x, this.points[k].y - this.points[i].y, this.points[k].z - this.points[i].z);
|
|
535
|
-
}
|
|
536
|
-
/** Compute the squared distance between two points given by their barycentric coordinates.
|
|
537
|
-
* * It is assumed that a0 + a1 + a2 = b0 + b1 + b2 = 1.
|
|
538
|
-
*/
|
|
539
|
-
distanceSquared(a0, a1, a2, b0, b1, b2) {
|
|
540
|
-
// the barycentric displacement vector distance formula
|
|
541
|
-
return -this.edgeLengthSquared(0) * (b1 - a1) * (b2 - a2) - this.edgeLengthSquared(1) * (b2 - a2) * (b0 - a0) - this.edgeLengthSquared(2) * (b0 - a0) * (b1 - a1);
|
|
600
|
+
/** Test for point-by-point `isAlmostEqual` relationship. */
|
|
601
|
+
isAlmostEqual(other, tol) {
|
|
602
|
+
return this.points[0].isAlmostEqual(other.points[0], tol)
|
|
603
|
+
&& this.points[1].isAlmostEqual(other.points[1], tol)
|
|
604
|
+
&& this.points[2].isAlmostEqual(other.points[2], tol);
|
|
542
605
|
}
|
|
543
606
|
}
|
|
544
607
|
//# sourceMappingURL=BarycentricTriangle.js.map
|