diff --git a/FilletChamfer.cpp b/FilletChamfer.cpp index 8ea7721..b754037 100644 --- a/FilletChamfer.cpp +++ b/FilletChamfer.cpp @@ -18,6 +18,7 @@ #include "/EgtDev/Include/EGkFilletChamfer.h" #include "/EgtDev/Include/EGkDistPointCurve.h" #include "/EgtDev/Include/EGkIntersCurves.h" +#include "/EgtDev/Include/EgkOffsetCurve.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; @@ -40,13 +41,21 @@ CalcForFillet( const ICurve& cCrv1, const Point3d& ptNear1, if ( ! dPC1.GetSideAtMinDistPoint( 0, vtNorm, nSide1)) return false ; double dOffs1 = ( nSide1 == MDS_RIGHT ? dRadius : - dRadius) ; - // calcolo l'offset nel piano locale e dal lato opportuno di una copia della curva 1 + // calcolo gli offset nel piano locale e dal lato opportuno di una copia della curva 1 PtrOwner pCopy1( cCrv1.Clone()) ; if ( IsNull( pCopy1)) return false ; pCopy1->ToLoc( frIntr) ; pCopy1->SetExtrusion( Z_AX) ; - if ( ! pCopy1->SimpleOffset( dOffs1, ICurve::OFF_FILLET)) + OffsetCurve OffsCrv1 ; + OffsCrv1.Make( pCopy1, dOffs1, ICurve::OFF_FILLET) ; + ICURVEPOVECTOR vOffs1 ; + ICurve* pCrv = OffsCrv1.GetLongerCurve() ; + while ( pCrv != nullptr) { + vOffs1.emplace_back( pCrv) ; + pCrv = OffsCrv1.GetLongerCurve() ; + } + if ( vOffs1.empty()) return false ; // determino il lato di offset della curva 2 @@ -54,23 +63,50 @@ CalcForFillet( const ICurve& cCrv1, const Point3d& ptNear1, if ( ! dPC2.GetSideAtMinDistPoint( 0, vtNorm, nSide2)) return false ; double dOffs2 = ( nSide2 == MDS_RIGHT ? dRadius : - dRadius) ; - // calcolo l'offset nel piano locale e dal lato opportuno di una copia della curva 2 + // calcolo gli offset nel piano locale e dal lato opportuno di una copia della curva 2 PtrOwner pCopy2( cCrv2.Clone()) ; if ( IsNull( pCopy2)) return false ; pCopy2->ToLoc( frIntr) ; pCopy2->SetExtrusion( Z_AX) ; - if ( ! pCopy2->SimpleOffset( dOffs2, ICurve::OFF_FILLET)) + OffsetCurve OffsCrv2 ; + OffsCrv2.Make( pCopy2, dOffs2, ICurve::OFF_FILLET) ; + ICURVEPOVECTOR vOffs2 ; + pCrv = OffsCrv2.GetLongerCurve() ; + while ( pCrv != nullptr) { + vOffs2.emplace_back( pCrv) ; + pCrv = OffsCrv2.GetLongerCurve() ; + } + if ( vOffs2.empty()) return false ; - // calcolo l'intersezione tra le due curve - Point3d ptInt1, ptInt2 ; + // calcolo le intersezioni tra tutte le curve di offset e seleziono quella più vicina ai punti passati + Point3d ptInt1 = P_INVALID, ptInt2 = P_INVALID ; Point3d ptNearI = Media( ptNear1, ptNear2) ; ptNearI.ToLoc( frIntr) ; - IntersCurveCurve intCC( *pCopy1, *pCopy2) ; - if ( ! intCC.GetIntersPointNearTo( 0, ptNearI, ptInt1) || - ! intCC.GetIntersPointNearTo( 1, ptNearI, ptInt2)) - return false ; + double dMinDist = INFINITO ; + for ( int i = 0 ; i < int( vOffs1.size()) ; i++) { + for ( int j = 0 ; j < int( vOffs2.size()) ; j ++) { + IntersCurveCurve intCC( *vOffs1[i], *vOffs2[j]) ; + if ( intCC.GetIntersCount() == 0) + continue ; + Point3d ptInt1Curr, ptInt2Curr ; + if ( ! intCC.GetIntersPointNearTo( 0, ptNearI, ptInt1Curr) || + ! intCC.GetIntersPointNearTo( 1, ptNearI, ptInt2Curr)) + return false ; + Point3d ptCenCurr = Media( ptInt1Curr, ptInt2Curr) ; + double dDist = Dist( ptNearI, ptCenCurr) ; + if ( dDist < dMinDist - EPS_SMALL) { + dMinDist = dDist ; + ptInt1 = ptInt1Curr ; + ptInt2 = ptInt2Curr ; + } + } + } + // se non sono state trovate intersezioni esco + if ( ! ptInt1.IsValid() || ! ptInt2.IsValid()) + return false ; + ptInt1.ToGlob( frIntr) ; ptInt2.ToGlob( frIntr) ; ptCen = Media( ptInt1, ptInt2) ; @@ -105,7 +141,7 @@ CreateFillet( const ICurve& cCrv1, const Point3d& ptNear1, const ICurve& cCrv2, const Point3d& ptNear2, const Vector3d& vtNorm, double dRadius, double& dPar1, double& dPar2) { - // verifico validità parametri ricevuti + // verifico validità parametri ricevuti if ( &cCrv1 == nullptr || &ptNear1 == nullptr || &cCrv2 == nullptr || &ptNear2 == nullptr || &vtNorm == nullptr || &dPar1 == nullptr || &dPar2 == nullptr) @@ -119,7 +155,7 @@ CreateFillet( const ICurve& cCrv1, const Point3d& ptNear1, ptCen, ptTg1, ptTg2, nSide1, nSide2, dSinA, dTgPar1, dTgPar2)) return nullptr ; - // se tangenti parallele al contatto con fillet, ricalcolo con raggio più piccolo + // se tangenti parallele al contatto con fillet, ricalcolo con raggio più piccolo bool bParallel = ( abs( dSinA) < EPS_SMALL) ; if ( bParallel) { Point3d ptQQQ, ptQQ1, ptQQ2 ; @@ -165,7 +201,7 @@ CreateChamfer( const ICurve& cCrv1, const Point3d& ptNear1, const ICurve& cCrv2, const Point3d& ptNear2, const Vector3d& vtNorm, double dDist, double& dPar1, double& dPar2) { - // verifico validità parametri ricevuti + // verifico validità parametri ricevuti if ( &cCrv1 == nullptr || &ptNear1 == nullptr || &cCrv2 == nullptr || &ptNear2 == nullptr || &vtNorm == nullptr || &dPar1 == nullptr || &dPar2 == nullptr)