@itwin/core-geometry 4.10.0-dev.25 → 4.10.0-dev.27
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/core-geometry.d.ts +1 -1
- package/lib/cjs/core-geometry.d.ts.map +1 -1
- package/lib/cjs/core-geometry.js +1 -1
- package/lib/cjs/core-geometry.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +2 -1
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveFactory.d.ts +1 -1
- package/lib/cjs/curve/CurveFactory.d.ts.map +1 -1
- package/lib/cjs/curve/CurveFactory.js +3 -3
- package/lib/cjs/curve/CurveFactory.js.map +1 -1
- package/lib/cjs/curve/LineSegment3d.js +2 -2
- package/lib/cjs/curve/LineSegment3d.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +3 -2
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +7 -6
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +3 -2
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/cjs/geometry3d/BilinearPatch.js +4 -4
- package/lib/cjs/geometry3d/BilinearPatch.js.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.js +2 -2
- package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
- package/lib/cjs/numerics/Newton.d.ts +3 -0
- package/lib/cjs/numerics/Newton.d.ts.map +1 -1
- package/lib/cjs/numerics/Newton.js +2 -5
- package/lib/cjs/numerics/Newton.js.map +1 -1
- package/lib/cjs/numerics/Polynomials.d.ts +22 -178
- package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/Polynomials.js +62 -360
- package/lib/cjs/numerics/Polynomials.js.map +1 -1
- package/lib/cjs/numerics/SmallSystem.d.ts +164 -0
- package/lib/cjs/numerics/SmallSystem.d.ts.map +1 -0
- package/lib/cjs/numerics/SmallSystem.js +321 -0
- package/lib/cjs/numerics/SmallSystem.js.map +1 -0
- package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts +1 -1
- package/lib/cjs/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -1
- package/lib/cjs/polyface/multiclip/OffsetMeshContext.js +7 -7
- package/lib/cjs/polyface/multiclip/OffsetMeshContext.js.map +1 -1
- package/lib/cjs/topology/Graph.d.ts.map +1 -1
- package/lib/cjs/topology/Graph.js +2 -2
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/InsertAndRetriangulateContext.js +2 -2
- package/lib/cjs/topology/InsertAndRetriangulateContext.js.map +1 -1
- package/lib/cjs/topology/Merging.d.ts +1 -1
- package/lib/cjs/topology/Merging.d.ts.map +1 -1
- package/lib/cjs/topology/Merging.js +2 -2
- package/lib/cjs/topology/Merging.js.map +1 -1
- package/lib/esm/core-geometry.d.ts +1 -1
- package/lib/esm/core-geometry.d.ts.map +1 -1
- package/lib/esm/core-geometry.js +1 -1
- package/lib/esm/core-geometry.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +2 -1
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveFactory.d.ts +1 -1
- package/lib/esm/curve/CurveFactory.d.ts.map +1 -1
- package/lib/esm/curve/CurveFactory.js +1 -1
- package/lib/esm/curve/CurveFactory.js.map +1 -1
- package/lib/esm/curve/LineSegment3d.js +1 -1
- package/lib/esm/curve/LineSegment3d.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +2 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +2 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +2 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/esm/geometry3d/BilinearPatch.js +1 -1
- package/lib/esm/geometry3d/BilinearPatch.js.map +1 -1
- package/lib/esm/geometry3d/Ray3d.js +1 -1
- package/lib/esm/geometry3d/Ray3d.js.map +1 -1
- package/lib/esm/numerics/Newton.d.ts +3 -0
- package/lib/esm/numerics/Newton.d.ts.map +1 -1
- package/lib/esm/numerics/Newton.js +1 -4
- package/lib/esm/numerics/Newton.js.map +1 -1
- package/lib/esm/numerics/Polynomials.d.ts +22 -178
- package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
- package/lib/esm/numerics/Polynomials.js +62 -359
- package/lib/esm/numerics/Polynomials.js.map +1 -1
- package/lib/esm/numerics/SmallSystem.d.ts +164 -0
- package/lib/esm/numerics/SmallSystem.d.ts.map +1 -0
- package/lib/esm/numerics/SmallSystem.js +317 -0
- package/lib/esm/numerics/SmallSystem.js.map +1 -0
- package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts +1 -1
- package/lib/esm/polyface/multiclip/OffsetMeshContext.d.ts.map +1 -1
- package/lib/esm/polyface/multiclip/OffsetMeshContext.js +4 -4
- package/lib/esm/polyface/multiclip/OffsetMeshContext.js.map +1 -1
- package/lib/esm/topology/Graph.d.ts.map +1 -1
- package/lib/esm/topology/Graph.js +1 -1
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/InsertAndRetriangulateContext.js +1 -1
- package/lib/esm/topology/InsertAndRetriangulateContext.js.map +1 -1
- package/lib/esm/topology/Merging.d.ts +1 -1
- package/lib/esm/topology/Merging.d.ts.map +1 -1
- package/lib/esm/topology/Merging.js +1 -1
- package/lib/esm/topology/Merging.js.map +1 -1
- package/package.json +3 -3
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ImplicitLineXY = exports.SineCosinePolynomial = exports.BilinearPolynomial = exports.
|
|
7
|
+
exports.ImplicitLineXY = exports.SineCosinePolynomial = exports.BilinearPolynomial = exports.TrigPolynomial = exports.PowerPolynomial = exports.AnalyticRoots = exports.SphereImplicit = exports.TorusImplicit = exports.Degree4PowerPolynomial = exports.Degree3PowerPolynomial = exports.Degree2PowerPolynomial = void 0;
|
|
8
8
|
/** @packageDocumentation
|
|
9
9
|
* @module Numerics
|
|
10
10
|
*/
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
11
12
|
const Geometry_1 = require("../Geometry");
|
|
12
13
|
const Angle_1 = require("../geometry3d/Angle");
|
|
13
14
|
const AngleSweep_1 = require("../geometry3d/AngleSweep");
|
|
@@ -16,9 +17,7 @@ const LongitudeLatitudeAltitude_1 = require("../geometry3d/LongitudeLatitudeAlti
|
|
|
16
17
|
const Point2dVector2d_1 = require("../geometry3d/Point2dVector2d");
|
|
17
18
|
const Point3dVector3d_1 = require("../geometry3d/Point3dVector3d");
|
|
18
19
|
const Range_1 = require("../geometry3d/Range");
|
|
19
|
-
// cspell:
|
|
20
|
-
// cspell:word CCminusSS
|
|
21
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
20
|
+
// cspell:words Cardano internaldocs
|
|
22
21
|
/**
|
|
23
22
|
* degree 2 (quadratic) polynomial in for y = c0 + c1*x + c2*x^2
|
|
24
23
|
* @internal
|
|
@@ -684,8 +683,8 @@ class AnalyticRoots {
|
|
|
684
683
|
return;
|
|
685
684
|
}
|
|
686
685
|
else if (D > 0) {
|
|
687
|
-
const
|
|
688
|
-
this.append2Solutions(
|
|
686
|
+
const sqrtD = Math.sqrt(D);
|
|
687
|
+
this.append2Solutions(sqrtD - p, -sqrtD - p, values);
|
|
689
688
|
return;
|
|
690
689
|
}
|
|
691
690
|
return;
|
|
@@ -751,7 +750,7 @@ class AnalyticRoots {
|
|
|
751
750
|
*/
|
|
752
751
|
/*
|
|
753
752
|
private static _appendCubicRootsUnsorted(c: Float64Array | number[], results: GrowableFloat64Array) {
|
|
754
|
-
let
|
|
753
|
+
let AA: number;
|
|
755
754
|
let p: number;
|
|
756
755
|
let q: number;
|
|
757
756
|
|
|
@@ -772,9 +771,9 @@ class AnalyticRoots {
|
|
|
772
771
|
// f' = 3y^2 + p
|
|
773
772
|
// local min/max at Y = +-sqrt (-p)
|
|
774
773
|
// f(+Y) = -p sqrt(-p) + 3p sqrt (-p) + 2q = 2 p sqrt (-p) + 2q
|
|
775
|
-
|
|
776
|
-
p = (3.0 * B -
|
|
777
|
-
q = 1.0 / 2 * (2.0 / 27 * A *
|
|
774
|
+
AA = A * A;
|
|
775
|
+
p = (3.0 * B - AA) / 9.0;
|
|
776
|
+
q = 1.0 / 2 * (2.0 / 27 * A * AA - 1.0 / 3 * A * B + C);
|
|
778
777
|
|
|
779
778
|
// Use Cardano formula
|
|
780
779
|
const cb_p: number = p * p * p;
|
|
@@ -812,9 +811,9 @@ class AnalyticRoots {
|
|
|
812
811
|
|
|
813
812
|
return;
|
|
814
813
|
} else { // One real solution
|
|
815
|
-
const
|
|
816
|
-
const u = this.cbrt(
|
|
817
|
-
const v = -(this.cbrt(
|
|
814
|
+
const sqrtD = Math.sqrt(D);
|
|
815
|
+
const u = this.cbrt(sqrtD - q);
|
|
816
|
+
const v = -(this.cbrt(sqrtD + q));
|
|
818
817
|
results.push(origin + u + v);
|
|
819
818
|
this.improveRoots(c, 3, results, false);
|
|
820
819
|
return;
|
|
@@ -855,10 +854,10 @@ class AnalyticRoots {
|
|
|
855
854
|
const D = c[0] * coffScale[0];
|
|
856
855
|
const origin = -0.25 * A;
|
|
857
856
|
// substitute x = y - A/4 to eliminate cubic term: y^4 + py^2 + qy + r = 0
|
|
858
|
-
const
|
|
859
|
-
const p = -0.375 *
|
|
860
|
-
const q = 0.125 *
|
|
861
|
-
const r = -0.01171875 *
|
|
857
|
+
const AA = A * A;
|
|
858
|
+
const p = -0.375 * AA + B;
|
|
859
|
+
const q = 0.125 * AA * A - 0.5 * A * B + C;
|
|
860
|
+
const r = -0.01171875 * AA * AA + 0.0625 * AA * B - 0.25 * A * C + D;
|
|
862
861
|
const cubicSolutions = new GrowableFloat64Array_1.GrowableFloat64Array();
|
|
863
862
|
if (this.isZero(r)) { // no absolute term: y(y^3 + py + q) = 0
|
|
864
863
|
coffs[0] = q;
|
|
@@ -1039,17 +1038,16 @@ exports.PowerPolynomial = PowerPolynomial;
|
|
|
1039
1038
|
*/
|
|
1040
1039
|
class TrigPolynomial {
|
|
1041
1040
|
/**
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
* *
|
|
1046
|
-
* (
|
|
1047
|
-
*
|
|
1048
|
-
* @param
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
* stages of computation. A small fraction of this will be used as a zero tolerance
|
|
1041
|
+
* Find the roots of a univariate polynomial created from substituting the rational parameterization of the unit
|
|
1042
|
+
* circle into a trigonometric polynomial. Roots are returned as radian angles.
|
|
1043
|
+
* * Currently implemented for polynomials of degree <= 4.
|
|
1044
|
+
* * For example, the ellipse-ellipse intersection problem reduces to finding the roots of a quartic polynomial:
|
|
1045
|
+
* `p(t) = coff[0] + coff[1] t + coff[2] t^2 + coff[3] t^3 + coff[4] t^4`.
|
|
1046
|
+
* * Particular care is given to report a root at t = +/-infinity, which corresponds to the returned angle -pi/2.
|
|
1047
|
+
* @param coff coefficients in the power basis
|
|
1048
|
+
* @param nominalDegree degree of the polynomial under the most complex root case.
|
|
1049
|
+
* @param referenceCoefficient a number which represents the size of coefficients at various stages of computation.
|
|
1050
|
+
* A small fraction of this number will be used as a zero tolerance.
|
|
1053
1051
|
* @param radians roots are placed here.
|
|
1054
1052
|
* @return false if equation is all zeros. This usually means any angle is a solution.
|
|
1055
1053
|
*/
|
|
@@ -1089,34 +1087,35 @@ class TrigPolynomial {
|
|
|
1089
1087
|
}
|
|
1090
1088
|
else {
|
|
1091
1089
|
// TODO: WORK WITH BEZIER SOLVER
|
|
1090
|
+
(0, core_bentley_1.assert)(false, "Unimplemented degree in trig solver");
|
|
1092
1091
|
}
|
|
1093
1092
|
if (roots.length > 0) {
|
|
1094
|
-
//
|
|
1095
|
-
//
|
|
1093
|
+
// each solution t represents an angle with Math.Cos(theta) = C(t)/W(t) and sin(theta) = S(t)/W(t)
|
|
1094
|
+
// division by W has no effect on atan2 calculations, so we just compute S(t),C(t)
|
|
1096
1095
|
for (let i = 0; i < roots.length; i++) {
|
|
1097
1096
|
const ss = PowerPolynomial.evaluate(this.S, roots.atUncheckedIndex(i));
|
|
1098
1097
|
const cc = PowerPolynomial.evaluate(this.C, roots.atUncheckedIndex(i));
|
|
1099
1098
|
radians.push(Math.atan2(ss, cc));
|
|
1100
1099
|
}
|
|
1101
|
-
// each leading zero at the front of the coefficient array corresponds to a root at -PI/2.
|
|
1102
|
-
// only make one entry because we don't report multiplicity.
|
|
1103
|
-
if (degree < nominalDegree)
|
|
1104
|
-
radians.push(-0.5 * Math.PI);
|
|
1105
1100
|
}
|
|
1101
|
+
// If the tail of the coff array is zero, we solved a polynomial of lesser degree above, and
|
|
1102
|
+
// we report the skipped "root at infinity" as the corresponding angle -pi/2 (without multiplicity).
|
|
1103
|
+
// See core\geometry\internaldocs\unitCircleEllipseIntersection.md for details.
|
|
1104
|
+
if (degree < nominalDegree)
|
|
1105
|
+
radians.push(-0.5 * Math.PI);
|
|
1106
1106
|
}
|
|
1107
1107
|
return radians.length > 0;
|
|
1108
1108
|
}
|
|
1109
1109
|
/**
|
|
1110
|
-
* Compute intersections of unit circle `x^2 + y^2 = 1` with general quadric
|
|
1111
|
-
* `axx
|
|
1112
|
-
* Solutions are returned as angles. Sine and Cosine of the angles are the x, y results.
|
|
1110
|
+
* Compute intersections of the unit circle `x^2 + y^2 = 1` with the general quadric (conic)
|
|
1111
|
+
* `axx x^2 + axy xy + ayy y^2 + ax x + ay y + a = 0`.
|
|
1113
1112
|
* @param axx coefficient of x^2
|
|
1114
1113
|
* @param axy coefficient of xy
|
|
1115
1114
|
* @param ayy coefficient of y^2
|
|
1116
1115
|
* @param ax coefficient of x
|
|
1117
1116
|
* @param ay coefficient of y
|
|
1118
1117
|
* @param a constant coefficient
|
|
1119
|
-
* @param radians solution angles
|
|
1118
|
+
* @param radians up to 4 solution angles t in the quadric parameterization: x = cos(t), y = sin(t)
|
|
1120
1119
|
*/
|
|
1121
1120
|
static solveUnitCircleImplicitQuadricIntersection(axx, axy, ayy, ax, ay, a, radians) {
|
|
1122
1121
|
const coffs = new Float64Array(5);
|
|
@@ -1171,9 +1170,9 @@ class TrigPolynomial {
|
|
|
1171
1170
|
const acs = 2.0 * (ux * vx + uy * vy);
|
|
1172
1171
|
const ass = vx * vx + vy * vy;
|
|
1173
1172
|
const ac = 2.0 * (ux * cx + uy * cy);
|
|
1174
|
-
const
|
|
1173
|
+
const as = 2.0 * (vx * cx + vy * cy);
|
|
1175
1174
|
const a = cx * cx + cy * cy - 1.0;
|
|
1176
|
-
const status = this.solveUnitCircleImplicitQuadricIntersection(acc, acs, ass, ac,
|
|
1175
|
+
const status = this.solveUnitCircleImplicitQuadricIntersection(acc, acs, ass, ac, as, a, ellipseRadians);
|
|
1177
1176
|
for (const radians of ellipseRadians) {
|
|
1178
1177
|
const cc = Math.cos(radians);
|
|
1179
1178
|
const ss = Math.sin(radians);
|
|
@@ -1241,307 +1240,42 @@ TrigPolynomial.CC = Float64Array.from([1.0, -4.0, 4.0]);
|
|
|
1241
1240
|
/** Standard Basis coefficients for W(t) * W(t). */
|
|
1242
1241
|
TrigPolynomial.WW = Float64Array.from([1.0, -4.0, 8.0, -8.0, 4.0]);
|
|
1243
1242
|
/** Standard Basis coefficients for C(t) * C(t) - S(t) * S(t). */
|
|
1244
|
-
TrigPolynomial.
|
|
1243
|
+
TrigPolynomial.CCMinusSS = Float64Array.from([1.0, -4.0, 0.0, 8.0, -4.0]); // eslint-disable-line @typescript-eslint/naming-convention
|
|
1245
1244
|
TrigPolynomial._coefficientRelTol = 1.0e-12;
|
|
1246
1245
|
/**
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1246
|
+
* * bilinear expression
|
|
1247
|
+
* * `f(u,v) = a + b * u * c * v + d * u * v`
|
|
1248
|
+
* @internal
|
|
1249
1249
|
*/
|
|
1250
|
-
class
|
|
1251
|
-
/**
|
|
1252
|
-
* Return true if lines (a0,a1) to (b0, b1) have a simple intersection.
|
|
1253
|
-
* Return the fractional (not xy) coordinates in result.x, result.y
|
|
1254
|
-
* @param a0 start point of line a
|
|
1255
|
-
* @param a1 end point of line a
|
|
1256
|
-
* @param b0 start point of line b
|
|
1257
|
-
* @param b1 end point of line b
|
|
1258
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1259
|
-
*/
|
|
1260
|
-
static lineSegment2dXYTransverseIntersectionUnbounded(a0, a1, b0, b1, result) {
|
|
1261
|
-
const ux = a1.x - a0.x;
|
|
1262
|
-
const uy = a1.y - a0.y;
|
|
1263
|
-
const vx = b1.x - b0.x;
|
|
1264
|
-
const vy = b1.y - b0.y;
|
|
1265
|
-
const cx = b0.x - a0.x;
|
|
1266
|
-
const cy = b0.y - a0.y;
|
|
1267
|
-
const uv = Geometry_1.Geometry.crossProductXYXY(ux, uy, vx, vy);
|
|
1268
|
-
const cv = Geometry_1.Geometry.crossProductXYXY(cx, cy, vx, vy);
|
|
1269
|
-
const cu = Geometry_1.Geometry.crossProductXYXY(ux, uy, cx, cy);
|
|
1270
|
-
const s = Geometry_1.Geometry.conditionalDivideFraction(cv, uv);
|
|
1271
|
-
const t = Geometry_1.Geometry.conditionalDivideFraction(cu, uv);
|
|
1272
|
-
if (s !== undefined && t !== undefined) {
|
|
1273
|
-
result.set(s, -t);
|
|
1274
|
-
return true;
|
|
1275
|
-
}
|
|
1276
|
-
result.set(0, 0);
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* * (ax0,ay0) to (ax0+ux,ay0+uy) are line A.
|
|
1281
|
-
* * (bx0,by0) to (bx0+vx,by0+vy) are lineB.
|
|
1282
|
-
* * Return true if the lines have a simple intersection.
|
|
1283
|
-
* * Return the fractional (not xy) coordinates in result.x, result.y
|
|
1284
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1285
|
-
*/
|
|
1286
|
-
static lineSegmentXYUVTransverseIntersectionUnbounded(ax0, ay0, ux, uy, bx0, by0, vx, vy, result) {
|
|
1287
|
-
const cx = bx0 - ax0;
|
|
1288
|
-
const cy = by0 - ay0;
|
|
1289
|
-
const uv = Geometry_1.Geometry.crossProductXYXY(ux, uy, vx, vy);
|
|
1290
|
-
const cv = Geometry_1.Geometry.crossProductXYXY(cx, cy, vx, vy);
|
|
1291
|
-
const cu = Geometry_1.Geometry.crossProductXYXY(ux, uy, cx, cy);
|
|
1292
|
-
const s = Geometry_1.Geometry.conditionalDivideFraction(cv, uv);
|
|
1293
|
-
const t = Geometry_1.Geometry.conditionalDivideFraction(cu, uv);
|
|
1294
|
-
if (s !== undefined && t !== undefined) {
|
|
1295
|
-
result.set(s, -t);
|
|
1296
|
-
return true;
|
|
1297
|
-
}
|
|
1298
|
-
result.set(0, 0);
|
|
1299
|
-
return false;
|
|
1300
|
-
}
|
|
1301
|
-
/**
|
|
1302
|
-
* Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts
|
|
1303
|
-
* Return the fractional (not xy) coordinates in result.x, result.y
|
|
1304
|
-
* @param a0 start point of line a
|
|
1305
|
-
* @param a1 end point of line a
|
|
1306
|
-
* @param b0 start point of line b
|
|
1307
|
-
* @param b1 end point of line b
|
|
1308
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1309
|
-
*/
|
|
1310
|
-
static lineSegment3dXYTransverseIntersectionUnbounded(a0, a1, b0, b1, result) {
|
|
1311
|
-
const ux = a1.x - a0.x;
|
|
1312
|
-
const uy = a1.y - a0.y;
|
|
1313
|
-
const vx = b1.x - b0.x;
|
|
1314
|
-
const vy = b1.y - b0.y;
|
|
1315
|
-
const cx = b0.x - a0.x;
|
|
1316
|
-
const cy = b0.y - a0.y;
|
|
1317
|
-
const uv = Geometry_1.Geometry.crossProductXYXY(ux, uy, vx, vy);
|
|
1318
|
-
const cv = Geometry_1.Geometry.crossProductXYXY(cx, cy, vx, vy);
|
|
1319
|
-
const cu = Geometry_1.Geometry.crossProductXYXY(ux, uy, cx, cy);
|
|
1320
|
-
const s = Geometry_1.Geometry.conditionalDivideFraction(cv, uv);
|
|
1321
|
-
const t = Geometry_1.Geometry.conditionalDivideFraction(cu, uv);
|
|
1322
|
-
if (s !== undefined && t !== undefined) {
|
|
1323
|
-
result.set(s, -t);
|
|
1324
|
-
return true;
|
|
1325
|
-
}
|
|
1326
|
-
result.set(0, 0);
|
|
1327
|
-
return false;
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* Return true if lines (a0,a1) to (b0, b1) have a simple intersection using only xy parts of WEIGHTED 4D Points
|
|
1331
|
-
* Return the fractional (not xy) coordinates in result.x, result.y
|
|
1332
|
-
* @param hA0 homogeneous start point of line a
|
|
1333
|
-
* @param hA1 homogeneous end point of line a
|
|
1334
|
-
* @param hB0 homogeneous start point of line b
|
|
1335
|
-
* @param hB1 homogeneous end point of line b
|
|
1336
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1337
|
-
*/
|
|
1338
|
-
static lineSegment3dHXYTransverseIntersectionUnbounded(hA0, hA1, hB0, hB1, result) {
|
|
1339
|
-
// Considering only x,y,w parts....
|
|
1340
|
-
// Point Q along B is (in full homogeneous) `(1-lambda) B0 + lambda 1`
|
|
1341
|
-
// PointQ is colinear with A0,A1 when the determinant det (A0,A1,Q) is zero. (Each column takes xyw parts)
|
|
1342
|
-
const alpha0 = Geometry_1.Geometry.tripleProduct(hA0.x, hA1.x, hB0.x, hA0.y, hA1.y, hB0.y, hA0.w, hA1.w, hB0.w);
|
|
1343
|
-
const alpha1 = Geometry_1.Geometry.tripleProduct(hA0.x, hA1.x, hB1.x, hA0.y, hA1.y, hB1.y, hA0.w, hA1.w, hB1.w);
|
|
1344
|
-
const fractionB = Geometry_1.Geometry.conditionalDivideFraction(-alpha0, alpha1 - alpha0);
|
|
1345
|
-
if (fractionB !== undefined) {
|
|
1346
|
-
const beta0 = Geometry_1.Geometry.tripleProduct(hB0.x, hB1.x, hA0.x, hB0.y, hB1.y, hA0.y, hB0.w, hB1.w, hA0.w);
|
|
1347
|
-
const beta1 = Geometry_1.Geometry.tripleProduct(hB0.x, hB1.x, hA1.x, hB0.y, hB1.y, hA1.y, hB0.w, hB1.w, hA1.w);
|
|
1348
|
-
const fractionA = Geometry_1.Geometry.conditionalDivideFraction(-beta0, beta1 - beta0);
|
|
1349
|
-
if (fractionA !== undefined)
|
|
1350
|
-
return Point2dVector2d_1.Vector2d.create(fractionA, fractionB, result);
|
|
1351
|
-
}
|
|
1352
|
-
return undefined;
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Return the line fraction at which the (homogeneous) line is closest to a space point as viewed in xy only.
|
|
1356
|
-
* @param hA0 homogeneous start point of line a
|
|
1357
|
-
* @param hA1 homogeneous end point of line a
|
|
1358
|
-
* @param spacePoint homogeneous point in space
|
|
1359
|
-
*/
|
|
1360
|
-
static lineSegment3dHXYClosestPointUnbounded(hA0, hA1, spacePoint) {
|
|
1361
|
-
// Considering only x,y,w parts....
|
|
1362
|
-
// weighted difference of (A1 w0 - A0 w1) is (cartesian) tangent vector along the line as viewed.
|
|
1363
|
-
// The perpendicular (pure vector) W = (-y,x) flip is the direction of projection
|
|
1364
|
-
// Point Q along A is (in full homogeneous) `(1-lambda) A0 + lambda 1 A1`
|
|
1365
|
-
// PointQ is colinear with spacePoint and and W when the xyw homogeneous determinant | Q W spacePoint | is zero.
|
|
1366
|
-
const tx = hA1.x * hA0.w - hA0.x * hA1.w;
|
|
1367
|
-
const ty = hA1.y * hA0.w - hA0.y * hA1.w;
|
|
1368
|
-
const det0 = Geometry_1.Geometry.tripleProduct(hA0.x, -ty, spacePoint.x, hA0.y, tx, spacePoint.y, hA0.w, 0, spacePoint.w);
|
|
1369
|
-
const det1 = Geometry_1.Geometry.tripleProduct(hA1.x, -ty, spacePoint.x, hA1.y, tx, spacePoint.y, hA1.w, 0, spacePoint.w);
|
|
1370
|
-
return Geometry_1.Geometry.conditionalDivideFraction(-det0, det1 - det0);
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* Return the line fraction at which the line is closest to a space point as viewed in xy only.
|
|
1374
|
-
* @param pointA0 start point
|
|
1375
|
-
* @param pointA1 end point
|
|
1376
|
-
* @param spacePoint point in space
|
|
1377
|
-
*/
|
|
1378
|
-
static lineSegment3dXYClosestPointUnbounded(pointA0, pointA1, spacePoint) {
|
|
1379
|
-
// Considering only x,y parts....
|
|
1380
|
-
const ux = pointA1.x - pointA0.x;
|
|
1381
|
-
const uy = pointA1.y - pointA0.y;
|
|
1382
|
-
const uu = ux * ux + uy * uy;
|
|
1383
|
-
const vx = spacePoint.x - pointA0.x;
|
|
1384
|
-
const vy = spacePoint.y - pointA0.y;
|
|
1385
|
-
const uv = ux * vx + uy * vy;
|
|
1386
|
-
return Geometry_1.Geometry.conditionalDivideFraction(uv, uu);
|
|
1387
|
-
}
|
|
1388
|
-
/**
|
|
1389
|
-
* Return the line fraction at which the line is closest to a space point
|
|
1390
|
-
* @param pointA0 start point
|
|
1391
|
-
* @param pointA1 end point
|
|
1392
|
-
* @param spacePoint point in space
|
|
1393
|
-
*/
|
|
1394
|
-
static lineSegment3dClosestPointUnbounded(pointA0, pointA1, spacePoint) {
|
|
1395
|
-
const ux = pointA1.x - pointA0.x;
|
|
1396
|
-
const uy = pointA1.y - pointA0.y;
|
|
1397
|
-
const uz = pointA1.z - pointA0.z;
|
|
1398
|
-
const uu = ux * ux + uy * uy + uz * uz;
|
|
1399
|
-
const vx = spacePoint.x - pointA0.x;
|
|
1400
|
-
const vy = spacePoint.y - pointA0.y;
|
|
1401
|
-
const vz = spacePoint.z - pointA0.z;
|
|
1402
|
-
const uv = ux * vx + uy * vy + uz * vz;
|
|
1403
|
-
return Geometry_1.Geometry.conditionalDivideFraction(uv, uu);
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* Return true if lines (a0,a1) to (b0, b1) have closest approach (go by each other) in 3d
|
|
1407
|
-
* Return the fractional (not xy) coordinates in result.x, result.y
|
|
1408
|
-
* @param a0 start point of line a
|
|
1409
|
-
* @param a1 end point of line a
|
|
1410
|
-
* @param b0 start point of line b
|
|
1411
|
-
* @param b1 end point of line b
|
|
1412
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1413
|
-
*/
|
|
1414
|
-
static lineSegment3dClosestApproachUnbounded(a0, a1, b0, b1, result) {
|
|
1415
|
-
return this.ray3dXYZUVWClosestApproachUnbounded(a0.x, a0.y, a0.z, a1.x - a0.x, a1.y - a0.y, a1.z - a0.z, b0.x, b0.y, b0.z, b1.x - b0.x, b1.y - b0.y, b1.z - b0.z, result);
|
|
1416
|
-
}
|
|
1417
|
-
/**
|
|
1418
|
-
* Return true if the given rays have closest approach (go by each other) in 3d
|
|
1419
|
-
* Return the fractional (not xy) coordinates as x and y parts of a Point2d.
|
|
1420
|
-
* @param ax x-coordinate of the origin of the first ray
|
|
1421
|
-
* @param ay y-coordinate of the origin of the first ray
|
|
1422
|
-
* @param az z-coordinate of the origin of the first ray
|
|
1423
|
-
* @param au x-coordinate of the direction vector of the first ray
|
|
1424
|
-
* @param av y-coordinate of the direction vector of the first ray
|
|
1425
|
-
* @param aw z-coordinate of the direction vector of the first ray
|
|
1426
|
-
* @param bx x-coordinate of the origin of the second ray
|
|
1427
|
-
* @param by y-coordinate of the origin of the second ray
|
|
1428
|
-
* @param bz z-coordinate of the origin of the second ray
|
|
1429
|
-
* @param bu x-coordinate of the direction vector of the second ray
|
|
1430
|
-
* @param bv y-coordinate of the direction vector of the second ray
|
|
1431
|
-
* @param bw z-coordinate of the direction vector of the second ray
|
|
1432
|
-
* @param result point to receive fractional coordinates of intersection. result.x is fraction on line a. result.y is fraction on line b.
|
|
1433
|
-
*/
|
|
1434
|
-
static ray3dXYZUVWClosestApproachUnbounded(ax, ay, az, au, av, aw, bx, by, bz, bu, bv, bw, result) {
|
|
1435
|
-
const cx = bx - ax;
|
|
1436
|
-
const cy = by - ay;
|
|
1437
|
-
const cz = bz - az;
|
|
1438
|
-
const uu = Geometry_1.Geometry.hypotenuseSquaredXYZ(au, av, aw);
|
|
1439
|
-
const vv = Geometry_1.Geometry.hypotenuseSquaredXYZ(bu, bv, bw);
|
|
1440
|
-
const uv = Geometry_1.Geometry.dotProductXYZXYZ(au, av, aw, bu, bv, bw);
|
|
1441
|
-
const cu = Geometry_1.Geometry.dotProductXYZXYZ(cx, cy, cz, au, av, aw);
|
|
1442
|
-
const cv = Geometry_1.Geometry.dotProductXYZXYZ(cx, cy, cz, bu, bv, bw);
|
|
1443
|
-
return SmallSystem.linearSystem2d(uu, -uv, uv, -vv, cu, cv, result);
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* Solve the pair of linear equations
|
|
1447
|
-
* * `ux * x + vx * y = cx`
|
|
1448
|
-
* * `uy * x + vy * y = cy`
|
|
1449
|
-
* @param ux xx coefficient
|
|
1450
|
-
* @param vx xy coefficient
|
|
1451
|
-
* @param uy yx coefficient
|
|
1452
|
-
* @param vy yy coefficient
|
|
1453
|
-
* @param cx x right hand side
|
|
1454
|
-
* @param cy y right hand side
|
|
1455
|
-
* @param result (x,y) solution (MUST be preallocated by caller)
|
|
1456
|
-
*/
|
|
1457
|
-
static linearSystem2d(ux, vx, // first row of matrix
|
|
1458
|
-
uy, vy, // second row of matrix
|
|
1459
|
-
cx, cy, // right side
|
|
1460
|
-
result) {
|
|
1461
|
-
const uv = Geometry_1.Geometry.crossProductXYXY(ux, uy, vx, vy);
|
|
1462
|
-
const cv = Geometry_1.Geometry.crossProductXYXY(cx, cy, vx, vy);
|
|
1463
|
-
const cu = Geometry_1.Geometry.crossProductXYXY(ux, uy, cx, cy);
|
|
1464
|
-
const s = Geometry_1.Geometry.conditionalDivideFraction(cv, uv);
|
|
1465
|
-
const t = Geometry_1.Geometry.conditionalDivideFraction(cu, uv);
|
|
1466
|
-
if (s !== undefined && t !== undefined) {
|
|
1467
|
-
result.set(s, t);
|
|
1468
|
-
return true;
|
|
1469
|
-
}
|
|
1470
|
-
result.set(0, 0);
|
|
1471
|
-
return false;
|
|
1472
|
-
}
|
|
1250
|
+
class BilinearPolynomial {
|
|
1473
1251
|
/**
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1478
|
-
* @param
|
|
1479
|
-
* @param axy row 0, column 1 coefficient
|
|
1480
|
-
* @param axz row 0, column 1 coefficient
|
|
1481
|
-
* @param ayx row 1, column 0 coefficient
|
|
1482
|
-
* @param ayy row 1, column 1 coefficient
|
|
1483
|
-
* @param ayz row 1, column 2 coefficient
|
|
1484
|
-
* @param azx row 2, column 0 coefficient
|
|
1485
|
-
* @param azy row 2, column 1 coefficient
|
|
1486
|
-
* @param azz row 2, column 2 coefficient
|
|
1487
|
-
* @param cx right hand side row 0 coefficient
|
|
1488
|
-
* @param cy right hand side row 1 coefficient
|
|
1489
|
-
* @param cz right hand side row 2 coefficient
|
|
1490
|
-
* @param result optional result.
|
|
1491
|
-
* @returns solution vector (u,v,w) or `undefined` if system is singular.
|
|
1252
|
+
*
|
|
1253
|
+
* @param a constant coefficient
|
|
1254
|
+
* @param b `u` coefficient
|
|
1255
|
+
* @param c `v` coefficient
|
|
1256
|
+
* @param d `u*v` coefficient
|
|
1492
1257
|
*/
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
// determinants of various combinations of columns ...
|
|
1499
|
-
const detXYZ = Geometry_1.Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, axz, ayz, azz);
|
|
1500
|
-
const detCYZ = Geometry_1.Geometry.tripleProduct(cx, cy, cz, axy, ayy, azy, axz, ayz, azz);
|
|
1501
|
-
const detXCZ = Geometry_1.Geometry.tripleProduct(axx, ayx, azx, cx, cy, cz, axz, ayz, azz);
|
|
1502
|
-
const detXYC = Geometry_1.Geometry.tripleProduct(axx, ayx, azx, axy, ayy, azy, cx, cy, cz);
|
|
1503
|
-
const s = Geometry_1.Geometry.conditionalDivideFraction(detCYZ, detXYZ);
|
|
1504
|
-
const t = Geometry_1.Geometry.conditionalDivideFraction(detXCZ, detXYZ);
|
|
1505
|
-
const u = Geometry_1.Geometry.conditionalDivideFraction(detXYC, detXYZ);
|
|
1506
|
-
if (s !== undefined && t !== undefined && u !== undefined) {
|
|
1507
|
-
return Point3dVector3d_1.Vector3d.create(s, t, u, result);
|
|
1508
|
-
}
|
|
1509
|
-
return undefined;
|
|
1258
|
+
constructor(a, b, c, d) {
|
|
1259
|
+
this.a = a;
|
|
1260
|
+
this.b = b;
|
|
1261
|
+
this.c = c;
|
|
1262
|
+
this.d = d;
|
|
1510
1263
|
}
|
|
1511
1264
|
/**
|
|
1512
|
-
*
|
|
1513
|
-
* @param xyzA point on the first plane
|
|
1514
|
-
* @param normalA normal of the first plane
|
|
1515
|
-
* @param xyzB point on the second plane
|
|
1516
|
-
* @param normalB normal of the second plane
|
|
1517
|
-
* @param xyzC point on the third plane
|
|
1518
|
-
* @param normalC normal of the third plane
|
|
1519
|
-
* @param result optional result
|
|
1520
|
-
* @returns intersection point of the three planes (as a Vector3d), or undefined if at least two planes are parallel.
|
|
1265
|
+
* Evaluate the bilinear expression at u,v
|
|
1521
1266
|
*/
|
|
1522
|
-
|
|
1523
|
-
return this.
|
|
1267
|
+
evaluate(u, v) {
|
|
1268
|
+
return this.a + this.b * u + v * (this.c + this.d * u);
|
|
1524
1269
|
}
|
|
1525
|
-
/**
|
|
1526
|
-
* * in rowB, replace `rowB[j] += a * rowB[pivot] * rowA[j] / rowA[pivot]` for `j>pivot`
|
|
1527
|
-
* @param rowA row that does not change
|
|
1528
|
-
* @param pivotIndex index of pivot (divisor) in rowA.
|
|
1529
|
-
* @param rowB row where elimination occurs.
|
|
1270
|
+
/** Create a bilinear polynomial z=f(u,v) given z values at 00, 10, 01, 11.
|
|
1530
1271
|
*/
|
|
1531
|
-
static
|
|
1532
|
-
|
|
1533
|
-
let q = Geometry_1.Geometry.conditionalDivideFraction(rowB[pivotIndex], rowA[pivotIndex]);
|
|
1534
|
-
if (q === undefined)
|
|
1535
|
-
return false;
|
|
1536
|
-
q *= a;
|
|
1537
|
-
for (let j = pivotIndex + 1; j < n; j++)
|
|
1538
|
-
rowB[j] += q * rowA[j];
|
|
1539
|
-
return true;
|
|
1272
|
+
static createUnitSquareValues(f00, f10, f01, f11) {
|
|
1273
|
+
return new BilinearPolynomial(f00, f10, f10, f11 - f10 - f01);
|
|
1540
1274
|
}
|
|
1541
1275
|
/**
|
|
1542
1276
|
* Solve a pair of bilinear equations
|
|
1543
1277
|
* * First equation: `a0 + b0 * u + c0 * v + d0 * u * v = 0`
|
|
1544
|
-
* * Second equation: `
|
|
1278
|
+
* * Second equation: `a1 + b1 * u + c1 * v + d1 * u * v = 0`
|
|
1545
1279
|
*/
|
|
1546
1280
|
static solveBilinearPair(a0, b0, c0, d0, a1, b1, c1, d1) {
|
|
1547
1281
|
// constant linear, and quadratic coefficients for c0 + c1 * u + c2 * u*u = 0
|
|
@@ -1562,38 +1296,6 @@ class SmallSystem {
|
|
|
1562
1296
|
}
|
|
1563
1297
|
return uv;
|
|
1564
1298
|
}
|
|
1565
|
-
}
|
|
1566
|
-
exports.SmallSystem = SmallSystem;
|
|
1567
|
-
/**
|
|
1568
|
-
* * bilinear expression
|
|
1569
|
-
* * `f(u,v) = a + b * u * c * v + d * u * v`
|
|
1570
|
-
* @internal
|
|
1571
|
-
*/
|
|
1572
|
-
class BilinearPolynomial {
|
|
1573
|
-
/**
|
|
1574
|
-
*
|
|
1575
|
-
* @param a constant coefficient
|
|
1576
|
-
* @param b `u` coefficient
|
|
1577
|
-
* @param c `v` coefficient
|
|
1578
|
-
* @param d `u*v` coefficient
|
|
1579
|
-
*/
|
|
1580
|
-
constructor(a, b, c, d) {
|
|
1581
|
-
this.a = a;
|
|
1582
|
-
this.b = b;
|
|
1583
|
-
this.c = c;
|
|
1584
|
-
this.d = d;
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Evaluate the bilinear expression at u,v
|
|
1588
|
-
*/
|
|
1589
|
-
evaluate(u, v) {
|
|
1590
|
-
return this.a + this.b * u + v * (this.c + this.d * u);
|
|
1591
|
-
}
|
|
1592
|
-
/** Create a bilinear polynomial z=f(u,v) given z values at 00, 10, 01, 11.
|
|
1593
|
-
*/
|
|
1594
|
-
static createUnitSquareValues(f00, f10, f01, f11) {
|
|
1595
|
-
return new BilinearPolynomial(f00, f10, f10, f11 - f10 - f01);
|
|
1596
|
-
}
|
|
1597
1299
|
/**
|
|
1598
1300
|
* Solve the simultaneous equations
|
|
1599
1301
|
* * `p(u,v) = pValue`
|
|
@@ -1604,7 +1306,7 @@ class BilinearPolynomial {
|
|
|
1604
1306
|
* @param qValue
|
|
1605
1307
|
*/
|
|
1606
1308
|
static solvePair(p, pValue, q, qValue) {
|
|
1607
|
-
return
|
|
1309
|
+
return BilinearPolynomial.solveBilinearPair(p.a - pValue, p.b, p.c, p.d, q.a - qValue, q.b, q.c, q.d);
|
|
1608
1310
|
}
|
|
1609
1311
|
}
|
|
1610
1312
|
exports.BilinearPolynomial = BilinearPolynomial;
|