@itwin/core-geometry 4.10.0-dev.2 → 4.10.0-dev.22
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 +31 -1
- package/lib/cjs/Geometry.d.ts +2 -2
- package/lib/cjs/Geometry.js +2 -2
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/clipping/ClipPrimitive.d.ts +7 -7
- package/lib/cjs/clipping/ClipPrimitive.d.ts.map +1 -1
- package/lib/cjs/clipping/ClipPrimitive.js +1 -1
- package/lib/cjs/clipping/ClipPrimitive.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts +21 -10
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +64 -37
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +27 -8
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js +44 -25
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/CurveFactory.d.ts +10 -12
- package/lib/cjs/curve/CurveFactory.d.ts.map +1 -1
- package/lib/cjs/curve/CurveFactory.js +16 -43
- package/lib/cjs/curve/CurveFactory.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +2 -2
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +1 -0
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +33 -59
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +22 -7
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +128 -68
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/cjs/curve/internalContexts/EllipticalArcApproximationContext.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/EllipticalArcApproximationContext.js +14 -11
- package/lib/cjs/curve/internalContexts/EllipticalArcApproximationContext.js.map +1 -1
- package/lib/cjs/geometry3d/Angle.d.ts +5 -5
- package/lib/cjs/geometry3d/Angle.js +5 -5
- package/lib/cjs/geometry3d/Angle.js.map +1 -1
- package/lib/cjs/geometry3d/AngleSweep.d.ts +101 -13
- package/lib/cjs/geometry3d/AngleSweep.d.ts.map +1 -1
- package/lib/cjs/geometry3d/AngleSweep.js +156 -57
- package/lib/cjs/geometry3d/AngleSweep.js.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.d.ts +9 -15
- package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.js +21 -15
- package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts +6 -5
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js +6 -5
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry3d/PolygonOps.js +2 -2
- package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
- package/lib/cjs/geometry3d/Transform.d.ts +4 -2
- package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Transform.js +4 -2
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/geometry4d/Map4d.d.ts +5 -5
- package/lib/cjs/geometry4d/Map4d.js +5 -5
- package/lib/cjs/geometry4d/Map4d.js.map +1 -1
- package/lib/cjs/geometry4d/Matrix4d.d.ts +4 -7
- package/lib/cjs/geometry4d/Matrix4d.d.ts.map +1 -1
- package/lib/cjs/geometry4d/Matrix4d.js +4 -7
- package/lib/cjs/geometry4d/Matrix4d.js.map +1 -1
- package/lib/cjs/numerics/Polynomials.d.ts +37 -36
- package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/Polynomials.js +90 -105
- package/lib/cjs/numerics/Polynomials.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.d.ts +3 -3
- package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.js +1 -1
- package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
- package/lib/esm/Geometry.d.ts +2 -2
- package/lib/esm/Geometry.js +2 -2
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/clipping/ClipPrimitive.d.ts +7 -7
- package/lib/esm/clipping/ClipPrimitive.d.ts.map +1 -1
- package/lib/esm/clipping/ClipPrimitive.js +1 -1
- package/lib/esm/clipping/ClipPrimitive.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts +21 -10
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +64 -37
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +27 -8
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js +44 -25
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/CurveFactory.d.ts +10 -12
- package/lib/esm/curve/CurveFactory.d.ts.map +1 -1
- package/lib/esm/curve/CurveFactory.js +16 -43
- package/lib/esm/curve/CurveFactory.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +2 -2
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +1 -0
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +33 -59
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +22 -7
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +128 -68
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/esm/curve/internalContexts/EllipticalArcApproximationContext.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/EllipticalArcApproximationContext.js +14 -11
- package/lib/esm/curve/internalContexts/EllipticalArcApproximationContext.js.map +1 -1
- package/lib/esm/geometry3d/Angle.d.ts +5 -5
- package/lib/esm/geometry3d/Angle.js +5 -5
- package/lib/esm/geometry3d/Angle.js.map +1 -1
- package/lib/esm/geometry3d/AngleSweep.d.ts +101 -13
- package/lib/esm/geometry3d/AngleSweep.d.ts.map +1 -1
- package/lib/esm/geometry3d/AngleSweep.js +156 -57
- package/lib/esm/geometry3d/AngleSweep.js.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.d.ts +9 -15
- package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.js +21 -15
- package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts +6 -5
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js +6 -5
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry3d/PolygonOps.js +2 -2
- package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
- package/lib/esm/geometry3d/Transform.d.ts +4 -2
- package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
- package/lib/esm/geometry3d/Transform.js +4 -2
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/geometry4d/Map4d.d.ts +5 -5
- package/lib/esm/geometry4d/Map4d.js +5 -5
- package/lib/esm/geometry4d/Map4d.js.map +1 -1
- package/lib/esm/geometry4d/Matrix4d.d.ts +4 -7
- package/lib/esm/geometry4d/Matrix4d.d.ts.map +1 -1
- package/lib/esm/geometry4d/Matrix4d.js +4 -7
- package/lib/esm/geometry4d/Matrix4d.js.map +1 -1
- package/lib/esm/numerics/Polynomials.d.ts +37 -36
- package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
- package/lib/esm/numerics/Polynomials.js +90 -105
- package/lib/esm/numerics/Polynomials.js.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.d.ts +3 -3
- package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.js +1 -1
- package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
- package/package.json +7 -19
|
@@ -820,7 +820,7 @@ export class AnalyticRoots {
|
|
|
820
820
|
// EDL April 5, 2020 replace classic GraphicsGems solver by RWDNickalls.
|
|
821
821
|
// Don't know if improveRoots is needed.
|
|
822
822
|
// Breaks in AnalyticRoots.test.ts checkQuartic suggest it indeed converts many e-16 errors to zero.
|
|
823
|
-
//
|
|
823
|
+
// e-13 cases are unaffected
|
|
824
824
|
this.improveRoots(c, 3, results, false);
|
|
825
825
|
}
|
|
826
826
|
else {
|
|
@@ -829,49 +829,46 @@ export class AnalyticRoots {
|
|
|
829
829
|
// this.appendCubicRootsUnsorted(c, results);
|
|
830
830
|
results.sort();
|
|
831
831
|
}
|
|
832
|
-
/** Compute roots of quartic
|
|
832
|
+
/** Compute roots of quartic `c[0] + c[1] * x + c[2] * x^2 + c[3] * x^3 + c[4] * x^4` */
|
|
833
833
|
static appendQuarticRoots(c, results) {
|
|
834
|
-
|
|
834
|
+
// for details, see core\geometry\internaldocs\quarticRoots.md
|
|
835
|
+
const coffs = new Float64Array(4);
|
|
835
836
|
let u;
|
|
836
837
|
let v;
|
|
837
|
-
// normal form: x^4 + Ax^3 + Bx^2 + Cx + D = 0
|
|
838
838
|
const coffScale = new Float64Array(1);
|
|
839
839
|
if (!this.safeDivide(coffScale, 1.0, c[4], 0.0, 0)) {
|
|
840
840
|
this.appendCubicRoots(c, results);
|
|
841
841
|
return;
|
|
842
842
|
}
|
|
843
|
+
// normal form: x^4 + Ax^3 + Bx^2 + Cx + D = 0
|
|
843
844
|
const A = c[3] * coffScale[0];
|
|
844
845
|
const B = c[2] * coffScale[0];
|
|
845
846
|
const C = c[1] * coffScale[0];
|
|
846
847
|
const D = c[0] * coffScale[0];
|
|
847
848
|
const origin = -0.25 * A;
|
|
848
|
-
|
|
849
|
-
x^4 + px^2 + qx + r = 0 */
|
|
849
|
+
// substitute x = y - A/4 to eliminate cubic term: y^4 + py^2 + qy + r = 0
|
|
850
850
|
const sq_A = A * A;
|
|
851
|
-
const p = -
|
|
851
|
+
const p = -0.375 * sq_A + B;
|
|
852
852
|
const q = 0.125 * sq_A * A - 0.5 * A * B + C;
|
|
853
|
-
const r = -
|
|
854
|
-
const
|
|
855
|
-
if (this.isZero(r)) {
|
|
856
|
-
// no absolute term: y(y^3 + py + q) = 0
|
|
853
|
+
const r = -0.01171875 * sq_A * sq_A + 0.0625 * sq_A * B - 0.25 * A * C + D;
|
|
854
|
+
const cubicSolutions = new GrowableFloat64Array();
|
|
855
|
+
if (this.isZero(r)) { // no absolute term: y(y^3 + py + q) = 0
|
|
857
856
|
coffs[0] = q;
|
|
858
857
|
coffs[1] = p;
|
|
859
858
|
coffs[2] = 0;
|
|
860
859
|
coffs[3] = 1;
|
|
861
860
|
this.appendCubicRoots(coffs, results);
|
|
862
|
-
results.push(0);
|
|
863
|
-
this.addConstant(origin, results);
|
|
861
|
+
results.push(0);
|
|
862
|
+
this.addConstant(origin, results); // apply origin
|
|
864
863
|
return;
|
|
865
864
|
}
|
|
866
|
-
else {
|
|
867
|
-
|
|
868
|
-
coffs[0] = 1.0 / 2 * r * p - 1.0 / 8 * q * q;
|
|
865
|
+
else { // solve the resolvent cubic
|
|
866
|
+
coffs[0] = 0.5 * r * p - 0.125 * q * q;
|
|
869
867
|
coffs[1] = -r;
|
|
870
|
-
coffs[2] = -
|
|
868
|
+
coffs[2] = -0.5 * p;
|
|
871
869
|
coffs[3] = 1;
|
|
872
|
-
this.appendCubicRoots(coffs,
|
|
873
|
-
const z = this.mostDistantFromMean(
|
|
874
|
-
// ... to build two quadric equations
|
|
870
|
+
this.appendCubicRoots(coffs, cubicSolutions);
|
|
871
|
+
const z = this.mostDistantFromMean(cubicSolutions);
|
|
875
872
|
u = z * z - r;
|
|
876
873
|
v = 2 * z - p;
|
|
877
874
|
if (this.isSmallRatio(u, r)) {
|
|
@@ -890,11 +887,9 @@ export class AnalyticRoots {
|
|
|
890
887
|
v = Math.sqrt(v);
|
|
891
888
|
}
|
|
892
889
|
else {
|
|
893
|
-
for (let i = 0; i < tempStack.length; i++) {
|
|
894
|
-
results.push(tempStack.atUncheckedIndex(i));
|
|
895
|
-
}
|
|
896
890
|
return;
|
|
897
891
|
}
|
|
892
|
+
// the two quadratic equations
|
|
898
893
|
coffs[0] = z - u;
|
|
899
894
|
coffs[1] = ((q < 0) ? (-v) : (v));
|
|
900
895
|
coffs[2] = 1;
|
|
@@ -904,8 +899,7 @@ export class AnalyticRoots {
|
|
|
904
899
|
coffs[2] = 1;
|
|
905
900
|
this.appendQuadraticRoots(coffs, results);
|
|
906
901
|
}
|
|
907
|
-
//
|
|
908
|
-
this.addConstant(origin, results);
|
|
902
|
+
this.addConstant(origin, results); // apply origin
|
|
909
903
|
results.sort();
|
|
910
904
|
this.improveRoots(c, 4, results, true);
|
|
911
905
|
return;
|
|
@@ -1009,19 +1003,17 @@ export class PowerPolynomial {
|
|
|
1009
1003
|
return this.degreeKnownEvaluate(coff, degree, x);
|
|
1010
1004
|
}
|
|
1011
1005
|
/**
|
|
1012
|
-
*
|
|
1013
|
-
* *
|
|
1014
|
-
* * Returns degree of result as determined by comparing trailing coefficients to zero
|
|
1006
|
+
* Accumulate `coffQ*scaleQ` into `coffP`.
|
|
1007
|
+
* * The length of `coffP` must be at least length of `coffQ`.
|
|
1008
|
+
* * Returns degree of result as determined by comparing trailing coefficients to zero.
|
|
1015
1009
|
*/
|
|
1016
1010
|
static accumulate(coffP, coffQ, scaleQ) {
|
|
1017
1011
|
let degreeP = coffP.length - 1;
|
|
1018
1012
|
const degreeQ = coffQ.length - 1;
|
|
1019
|
-
for (let i = 0; i <= degreeQ; i++)
|
|
1013
|
+
for (let i = 0; i <= degreeQ; i++)
|
|
1020
1014
|
coffP[i] += scaleQ * coffQ[i];
|
|
1021
|
-
|
|
1022
|
-
while (degreeP >= 0 && coffP[degreeP] === 0.0) {
|
|
1015
|
+
while (degreeP >= 0 && coffP[degreeP] === 0.0)
|
|
1023
1016
|
degreeP--;
|
|
1024
|
-
}
|
|
1025
1017
|
return degreeP;
|
|
1026
1018
|
}
|
|
1027
1019
|
/** Zero all coefficients */
|
|
@@ -1037,17 +1029,18 @@ export class PowerPolynomial {
|
|
|
1037
1029
|
*/
|
|
1038
1030
|
export class TrigPolynomial {
|
|
1039
1031
|
/**
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1032
|
+
* Solve a polynomial created from trigonometric condition using Trig.S, Trig.C, Trig.W.
|
|
1033
|
+
* * Polynomial is of degree 4:
|
|
1034
|
+
* `p(t) = coff[0] + coff[1] * t + coff[2] * t^2 + coff[3] * t^3 + coff[4] * t^4`
|
|
1035
|
+
* * Solution logic includes inferring angular roots corresponding zero leading coefficients
|
|
1036
|
+
* (roots at infinity).
|
|
1037
|
+
* @param coff coefficients.
|
|
1038
|
+
* @param nominalDegree degree of the polynomial under most complex root case. If there are
|
|
1039
|
+
* any zero coefficients up to this degree, a single root "at infinity" is recorded as its
|
|
1040
|
+
* corresponding angular parameter at negative pi/2.
|
|
1041
|
+
* @param referenceCoefficient a number which represents the size of coefficients at various
|
|
1042
|
+
* stages of computation. A small fraction of this will be used as a zero tolerance
|
|
1043
|
+
* @param radians roots are placed here.
|
|
1051
1044
|
* @return false if equation is all zeros. This usually means any angle is a solution.
|
|
1052
1045
|
*/
|
|
1053
1046
|
static solveAngles(coff, nominalDegree, referenceCoefficient, radians) {
|
|
@@ -1057,31 +1050,23 @@ export class TrigPolynomial {
|
|
|
1057
1050
|
const relTol = this._smallAngle;
|
|
1058
1051
|
for (let i = 0; i <= nominalDegree; i++) {
|
|
1059
1052
|
a = Math.abs(coff[i]);
|
|
1060
|
-
if (a > maxCoff)
|
|
1053
|
+
if (a > maxCoff)
|
|
1061
1054
|
maxCoff = a;
|
|
1062
|
-
}
|
|
1063
1055
|
}
|
|
1064
1056
|
const coffTol = relTol * maxCoff;
|
|
1065
1057
|
let degree = nominalDegree;
|
|
1066
|
-
while (degree > 0 && (Math.abs(coff[degree]) <= coffTol))
|
|
1058
|
+
while (degree > 0 && (Math.abs(coff[degree]) <= coffTol))
|
|
1067
1059
|
degree--;
|
|
1068
|
-
}
|
|
1069
|
-
// let status = false;
|
|
1070
1060
|
const roots = new GrowableFloat64Array();
|
|
1071
1061
|
if (degree === -1) {
|
|
1072
|
-
//
|
|
1073
|
-
// status = false;
|
|
1062
|
+
// do nothing
|
|
1074
1063
|
}
|
|
1075
1064
|
else {
|
|
1076
|
-
// status = true;
|
|
1077
1065
|
if (degree === 0) {
|
|
1078
|
-
// p(t) is a nonzero constant
|
|
1079
|
-
// No roots, but not degenerate.
|
|
1080
|
-
// status = true;
|
|
1066
|
+
// p(t) is a nonzero constant; no roots but not degenerate.
|
|
1081
1067
|
}
|
|
1082
1068
|
else if (degree === 1) {
|
|
1083
|
-
// p(t) = coff[
|
|
1084
|
-
roots.push(-coff[0] / coff[1]);
|
|
1069
|
+
roots.push(-coff[0] / coff[1]); // p(t) = coff[0] + coff[1] * t
|
|
1085
1070
|
}
|
|
1086
1071
|
else if (degree === 2) {
|
|
1087
1072
|
AnalyticRoots.appendQuadraticRoots(coff, roots);
|
|
@@ -1093,70 +1078,67 @@ export class TrigPolynomial {
|
|
|
1093
1078
|
AnalyticRoots.appendQuarticRoots(coff, roots);
|
|
1094
1079
|
}
|
|
1095
1080
|
else {
|
|
1096
|
-
// TODO:
|
|
1097
|
-
// status = false;
|
|
1081
|
+
// TODO: WORK WITH BEZIER SOLVER
|
|
1098
1082
|
}
|
|
1099
1083
|
if (roots.length > 0) {
|
|
1100
|
-
// Each solution t represents an angle with
|
|
1101
|
-
//
|
|
1102
|
-
// Division by W has no effect on Atan2 calculations, so we just compute S(t),C(t)
|
|
1084
|
+
// Each solution t represents an angle with Math.Cos(theta) = C(t)/W(t) and sin(theta) = S(t)/W(t)
|
|
1085
|
+
// Division by W has no effect on atan2 calculations, so we just compute S(t),C(t)
|
|
1103
1086
|
for (let i = 0; i < roots.length; i++) {
|
|
1104
1087
|
const ss = PowerPolynomial.evaluate(this.S, roots.atUncheckedIndex(i));
|
|
1105
1088
|
const cc = PowerPolynomial.evaluate(this.C, roots.atUncheckedIndex(i));
|
|
1106
1089
|
radians.push(Math.atan2(ss, cc));
|
|
1107
1090
|
}
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1110
|
-
|
|
1111
|
-
if (degree < nominalDegree) {
|
|
1091
|
+
// each leading zero at the front of the coefficient array corresponds to a root at -PI/2.
|
|
1092
|
+
// only make one entry because we don't report multiplicity.
|
|
1093
|
+
if (degree < nominalDegree)
|
|
1112
1094
|
radians.push(-0.5 * Math.PI);
|
|
1113
|
-
}
|
|
1114
1095
|
}
|
|
1115
1096
|
}
|
|
1116
1097
|
return radians.length > 0;
|
|
1117
1098
|
}
|
|
1118
1099
|
/**
|
|
1119
1100
|
* Compute intersections of unit circle `x^2 + y^2 = 1` with general quadric
|
|
1120
|
-
* `axx * x^2 + axy * x * y + ayy * y^2 + ax * x + ay * y +
|
|
1101
|
+
* `axx * x^2 + axy * x * y + ayy * y^2 + ax * x + ay * y + a = 0`
|
|
1121
1102
|
* Solutions are returned as angles. Sine and Cosine of the angles are the x, y results.
|
|
1122
|
-
* @param axx
|
|
1123
|
-
* @param axy
|
|
1124
|
-
* @param ayy
|
|
1125
|
-
* @param ax
|
|
1126
|
-
* @param ay
|
|
1127
|
-
* @param
|
|
1128
|
-
* @param radians
|
|
1103
|
+
* @param axx coefficient of x^2
|
|
1104
|
+
* @param axy coefficient of xy
|
|
1105
|
+
* @param ayy coefficient of y^2
|
|
1106
|
+
* @param ax coefficient of x
|
|
1107
|
+
* @param ay coefficient of y
|
|
1108
|
+
* @param a constant coefficient
|
|
1109
|
+
* @param radians solution angles
|
|
1129
1110
|
*/
|
|
1130
|
-
static solveUnitCircleImplicitQuadricIntersection(axx, axy, ayy, ax, ay,
|
|
1131
|
-
const
|
|
1132
|
-
PowerPolynomial.zero(
|
|
1111
|
+
static solveUnitCircleImplicitQuadricIntersection(axx, axy, ayy, ax, ay, a, radians) {
|
|
1112
|
+
const coffs = new Float64Array(5);
|
|
1113
|
+
PowerPolynomial.zero(coffs);
|
|
1133
1114
|
let degree;
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
PowerPolynomial.accumulate(
|
|
1137
|
-
PowerPolynomial.accumulate(
|
|
1138
|
-
PowerPolynomial.accumulate(
|
|
1139
|
-
PowerPolynomial.accumulate(
|
|
1140
|
-
PowerPolynomial.accumulate(
|
|
1115
|
+
// see core\geometry\internaldocs\unitCircleEllipseIntersection.md for derivation of these coefficients
|
|
1116
|
+
if (Geometry.hypotenuseXYZ(axx, axy, ayy) > TrigPolynomial._coefficientRelTol * Geometry.hypotenuseXYZ(ax, ay, a)) {
|
|
1117
|
+
PowerPolynomial.accumulate(coffs, this.CW, ax);
|
|
1118
|
+
PowerPolynomial.accumulate(coffs, this.SW, ay);
|
|
1119
|
+
PowerPolynomial.accumulate(coffs, this.WW, a);
|
|
1120
|
+
PowerPolynomial.accumulate(coffs, this.SS, ayy);
|
|
1121
|
+
PowerPolynomial.accumulate(coffs, this.CC, axx);
|
|
1122
|
+
PowerPolynomial.accumulate(coffs, this.SC, axy);
|
|
1141
1123
|
degree = 4;
|
|
1142
1124
|
}
|
|
1143
1125
|
else {
|
|
1144
|
-
PowerPolynomial.accumulate(
|
|
1145
|
-
PowerPolynomial.accumulate(
|
|
1146
|
-
PowerPolynomial.accumulate(
|
|
1126
|
+
PowerPolynomial.accumulate(coffs, this.C, ax);
|
|
1127
|
+
PowerPolynomial.accumulate(coffs, this.S, ay);
|
|
1128
|
+
PowerPolynomial.accumulate(coffs, this.W, a);
|
|
1147
1129
|
degree = 2;
|
|
1148
1130
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
const b = this.solveAngles(Coffs, degree, maxCoff, radians);
|
|
1131
|
+
const maxCoff = Math.max(Math.abs(axx), Math.abs(ayy), Math.abs(axy), Math.abs(ax), Math.abs(ay), Math.abs(a));
|
|
1132
|
+
const b = this.solveAngles(coffs, degree, maxCoff, radians);
|
|
1152
1133
|
/*
|
|
1153
1134
|
for (const theta of angles) {
|
|
1154
1135
|
const c = theta.cos();
|
|
1155
1136
|
const s = theta.sin();
|
|
1156
1137
|
GeometryCoreTestIO.consoleLog({
|
|
1157
1138
|
angle: theta, co: c, si: s,
|
|
1158
|
-
f: axx * c * c + axy * c * s + ayy * s * s + ax * c + ay * s +
|
|
1159
|
-
|
|
1139
|
+
f: axx * c * c + axy * c * s + ayy * s * s + ax * c + ay * s + a,
|
|
1140
|
+
});
|
|
1141
|
+
} */
|
|
1160
1142
|
return b;
|
|
1161
1143
|
}
|
|
1162
1144
|
/**
|
|
@@ -1174,6 +1156,7 @@ export class TrigPolynomial {
|
|
|
1174
1156
|
*/
|
|
1175
1157
|
static solveUnitCircleEllipseIntersection(cx, cy, ux, uy, vx, vy, ellipseRadians, circleRadians) {
|
|
1176
1158
|
circleRadians.length = 0;
|
|
1159
|
+
// see core\geometry\internaldocs\unitCircleEllipseIntersection.md for derivation of these coefficients:
|
|
1177
1160
|
const acc = ux * ux + uy * uy;
|
|
1178
1161
|
const acs = 2.0 * (ux * vx + uy * vy);
|
|
1179
1162
|
const ass = vx * vx + vy * vy;
|
|
@@ -1191,7 +1174,7 @@ export class TrigPolynomial {
|
|
|
1191
1174
|
return status;
|
|
1192
1175
|
}
|
|
1193
1176
|
/**
|
|
1194
|
-
* Compute intersections of unit circle `x^2 + y^2 = w^2` with the ellipse
|
|
1177
|
+
* Compute intersections of unit circle `x^2 + y^2 = w^2` (in homogeneous coordinates) with the ellipse
|
|
1195
1178
|
* `F(t) = (cx + ux cos(t) + vx sin(t), cy + uy cos(t) + vy sin(t)) / (cw + uw cos(t) + vw sin(t))`.
|
|
1196
1179
|
* @param cx center x
|
|
1197
1180
|
* @param cy center y
|
|
@@ -1207,13 +1190,14 @@ export class TrigPolynomial {
|
|
|
1207
1190
|
*/
|
|
1208
1191
|
static solveUnitCircleHomogeneousEllipseIntersection(cx, cy, cw, ux, uy, uw, vx, vy, vw, ellipseRadians, circleRadians) {
|
|
1209
1192
|
circleRadians.length = 0;
|
|
1193
|
+
// see core\geometry\internaldocs\unitCircleEllipseIntersection.md for derivation of these coefficients:
|
|
1210
1194
|
const acc = ux * ux + uy * uy - uw * uw;
|
|
1211
1195
|
const acs = 2.0 * (ux * vx + uy * vy - uw * vw);
|
|
1212
1196
|
const ass = vx * vx + vy * vy - vw * vw;
|
|
1213
1197
|
const ac = 2.0 * (ux * cx + uy * cy - uw * cw);
|
|
1214
|
-
const
|
|
1198
|
+
const as = 2.0 * (vx * cx + vy * cy - vw * cw);
|
|
1215
1199
|
const a = cx * cx + cy * cy - cw * cw;
|
|
1216
|
-
const status = this.solveUnitCircleImplicitQuadricIntersection(acc, acs, ass, ac,
|
|
1200
|
+
const status = this.solveUnitCircleImplicitQuadricIntersection(acc, acs, ass, ac, as, a, ellipseRadians);
|
|
1217
1201
|
for (const radians of ellipseRadians) {
|
|
1218
1202
|
const cc = Math.cos(radians);
|
|
1219
1203
|
const ss = Math.sin(radians);
|
|
@@ -1226,25 +1210,26 @@ export class TrigPolynomial {
|
|
|
1226
1210
|
}
|
|
1227
1211
|
// tolerance for small angle decision.
|
|
1228
1212
|
TrigPolynomial._smallAngle = 1.0e-11;
|
|
1229
|
-
|
|
1213
|
+
// see core\geometry\internaldocs\unitCircleEllipseIntersection.md for derivation of these coefficients.
|
|
1214
|
+
/** Standard Basis coefficients for the numerator of the y-coordinate y(t) = S(t)/W(t) in the rational semicircle parameterization. */
|
|
1230
1215
|
TrigPolynomial.S = Float64Array.from([0.0, 2.0, -2.0]);
|
|
1231
|
-
/** Standard Basis coefficients for rational
|
|
1216
|
+
/** Standard Basis coefficients for the numerator of the x-coordinate x(t) = C(t)/W(t) in the rational semicircle parameterization. */
|
|
1232
1217
|
TrigPolynomial.C = Float64Array.from([1.0, -2.0]);
|
|
1233
|
-
/** Standard Basis coefficients for rational
|
|
1218
|
+
/** Standard Basis coefficients for the denominator of x(t) and y(t) in the rational semicircle parameterization. */
|
|
1234
1219
|
TrigPolynomial.W = Float64Array.from([1.0, -2.0, 2.0]);
|
|
1235
|
-
/** Standard Basis coefficients for
|
|
1220
|
+
/** Standard Basis coefficients for C(t) * W(t). */
|
|
1236
1221
|
TrigPolynomial.CW = Float64Array.from([1.0, -4.0, 6.0, -4.0]);
|
|
1237
|
-
/** Standard Basis coefficients for
|
|
1222
|
+
/** Standard Basis coefficients for S(t) * W(t). */
|
|
1238
1223
|
TrigPolynomial.SW = Float64Array.from([0.0, 2.0, -6.0, 8.0, -4.0]);
|
|
1239
|
-
/** Standard Basis coefficients for
|
|
1224
|
+
/** Standard Basis coefficients for S(t) * C(t). */
|
|
1240
1225
|
TrigPolynomial.SC = Float64Array.from([0.0, 2.0, -6.0, 4.0]);
|
|
1241
|
-
/** Standard Basis coefficients for
|
|
1226
|
+
/** Standard Basis coefficients for S(t) * S(t). */
|
|
1242
1227
|
TrigPolynomial.SS = Float64Array.from([0.0, 0.0, 4.0, -8.0, 4.0]);
|
|
1243
|
-
/** Standard Basis coefficients for
|
|
1228
|
+
/** Standard Basis coefficients for C(t) * C(t). */
|
|
1244
1229
|
TrigPolynomial.CC = Float64Array.from([1.0, -4.0, 4.0]);
|
|
1245
|
-
/** Standard Basis coefficients for
|
|
1230
|
+
/** Standard Basis coefficients for W(t) * W(t). */
|
|
1246
1231
|
TrigPolynomial.WW = Float64Array.from([1.0, -4.0, 8.0, -8.0, 4.0]);
|
|
1247
|
-
/** Standard Basis coefficients for (
|
|
1232
|
+
/** Standard Basis coefficients for C(t) * C(t) - S(t) * S(t). */
|
|
1248
1233
|
TrigPolynomial.CCminusSS = Float64Array.from([1.0, -4.0, 0.0, 8.0, -4.0]);
|
|
1249
1234
|
TrigPolynomial._coefficientRelTol = 1.0e-12;
|
|
1250
1235
|
/**
|