EgtGeomKernel 2.4k7 :

- aggiunta funzione per associare i punti a minima distanza di due polylines
- modifiche nelle trimesh rigate per usare nuova funzione polyline.
This commit is contained in:
SaraP
2022-12-01 11:26:52 +01:00
parent 7ee0e38cec
commit 56b49d4c9f
3 changed files with 92 additions and 66 deletions
+79
View File
@@ -1513,3 +1513,82 @@ SplitPolyLineAtPoint( const PolyLine& plPoly, const Point3d& ptP, double dToler,
plPoly2.AddUPoint( 0, ptP, false) ;
return true ;
}
//----------------------------------------------------------------------------
bool
AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIVECTOR& vPnt1, PNTIVECTOR& vPnt2, bool& bCommonInternalPoints)
{
// controllo che le polyline abbiano almeno un punto
int nPnt1 = PL1.GetPointNbr() ;
int nPnt2 = PL2.GetPointNbr() ;
if ( nPnt1 == 0 || nPnt2 == 0)
return false ;
bCommonInternalPoints = false ; // indica la presenza di punti interni in comune tra le due polylines
vPnt1.reserve( PL1.GetPointNbr()) ;
Point3d ptP1 ;
bool bF1 = PL1.GetFirstPoint( ptP1) ;
while ( bF1) {
vPnt1.emplace_back( ptP1, -1) ;
bF1 = PL1.GetNextPoint( ptP1) ;
}
int nTotP1 = int( vPnt1.size()) ;
vPnt2.reserve( PL2.GetPointNbr()) ;
Point3d ptP2 ;
bool bF2 = PL2.GetFirstPoint( ptP2) ;
while ( bF2) {
vPnt2.emplace_back( ptP2, -1) ;
bF2 = PL2.GetNextPoint( ptP2) ;
}
int nTotP2 = int( vPnt2.size()) ;
// calcoli per prima curva
int LastJ = 0 ;
vPnt1[0].second = 0 ;
for ( int i = 1 ; i < nTotP1 ; ++ i) {
double dSqDistMin = SqDist( vPnt1[i].first, vPnt2[LastJ].first) ;
double dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[LastJ].first) ;
int MinJ = LastJ ;
for ( int j = LastJ + 1 ; j < nTotP2 ; ++ j) {
double dSqDist = SqDist( vPnt1[i].first, vPnt2[j].first) ;
if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) {
dSqDistMin = dSqDist ;
dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[j].first) ;
MinJ = j ;
}
else if ( dSqDist > 16 * dSqDistMin)
break ;
}
if ( i < nTotP1 - 1 && dSqDistMin < EPS_SMALL)
bCommonInternalPoints = true ;
vPnt1[i].second = MinJ ;
LastJ = MinJ ;
}
// calcoli per seconda curva
int LastI = 0 ;
vPnt2[0].second = 0 ;
for ( int j = 1 ; j < nTotP2 ; ++ j) {
double dSqDistMin = SqDist( vPnt2[j].first, vPnt1[LastI].first) ;
double dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[LastI].first) ;
int MinI = LastI ;
for ( int i = LastI + 1 ; i < nTotP1 ; ++ i) {
double dSqDist = SqDist( vPnt2[j].first, vPnt1[i].first) ;
if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) {
dSqDistMin = dSqDist ;
dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[i].first) ;
MinI = i ;
}
else if ( dSqDist > 16 * dSqDistMin)
break ;
}
if ( j < nTotP2 - 1 && dSqDistMin < EPS_SMALL)
bCommonInternalPoints = true ;
vPnt2[j].second = MinI ;
LastI = MinI ;
}
return true ;
}