tolerance in CrossPointBarycentric

This commit is contained in:
Joachim Schoeberl 2024-11-29 13:00:32 +01:00
parent 516c089c42
commit a4c6655fa7
3 changed files with 6 additions and 3 deletions

View File

@ -128,7 +128,7 @@ Point2d CrossPoint (const Line2d & l1, const Line2d & l2)
int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double & lam1, double & lam2)
double & lam1, double & lam2, double eps)
{
// p = l1.1 + lam1 (l1.2-l1.1) = l2.1 + lam2 (l2.2-l2.1)
double a11 = l1.p2.X() - l1.p1.X();
@ -140,8 +140,11 @@ int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double b2 = l2.p1.Y() - l1.p1.Y();
double det = a11*a22 - a12 * a21;
/*
if (det == 0)
return 1;
*/
if (fabs (det) < eps * (fabs(a11*a22)+fabs(a12*a21))) return 1;
lam1 = (a22 * b1 - a12 * b2) / det;
lam2 = (a11 * b2 - a21 * b1) / det;

View File

@ -365,7 +365,7 @@ namespace netgen
friend DLL_HEADER Point2d CrossPoint (const Line2d & l1, const Line2d & l2);
/// returns 1 iff parallel
friend int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double & lam1, double & lam2);
double & lam1, double & lam2, double eps);
///
friend int Parallel (const Line2d & l1, const Line2d & l2, double peps);

View File

@ -1369,7 +1369,7 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
Line2d l2 (sp1, sp2);
double lam1, lam2;
int err = CrossPointBarycentric (l1, l2, lam1, lam2);
int err = CrossPointBarycentric (l1, l2, lam1, lam2, eps);
bool in1 = (lam1 > eps) && (lam1 < 1-eps);
bool on1 = (lam1 > -eps) && (lam1 < 1 + eps);
bool in2 = (lam2 > eps) && (lam2 < 1-eps);