de34cfb7e8
- sistemate minuscole/maiuscole in #include.
81 lines
2.9 KiB
C++
81 lines
2.9 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : LinePntMinDistCurve.cpp Data : 27.11.14 Versione : 1.5k5
|
|
// Contenuto : Implementazione funzioni per calcolo rette di minima distanza da curve.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 25.11.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "CurveLine.h"
|
|
#include "/EgtDev/Include/EGkLinePntMinDistCurve.h"
|
|
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
ICurveLine*
|
|
GetLinePointMinDistCurve( const Point3d& ptP, const ICurve& cCrv, const Point3d& ptNear)
|
|
{
|
|
// calcolo i punti a minima distanza
|
|
DistPointCurve dstPtCurve( ptP, cCrv) ;
|
|
// ciclo su questi punti per trovare il più vicino al desiderato
|
|
bool bFound = false ;
|
|
double dMinSqDist = SQ_INFINITO ;
|
|
Point3d ptFoot ;
|
|
MinDistPCInfo mdInfo ;
|
|
for ( int i = 0 ; dstPtCurve.GetMinDistInfo( i, mdInfo) ; ++ i) {
|
|
// verifico punto
|
|
double dSqDist = SqDist( mdInfo.ptQ, ptNear) ;
|
|
if ( dSqDist < dMinSqDist) {
|
|
bFound = true ;
|
|
dMinSqDist = dSqDist ;
|
|
ptFoot = mdInfo.ptQ ;
|
|
}
|
|
}
|
|
// verifico eventuali tratti continui
|
|
for ( int i = 0 ; dstPtCurve.GetMinDistInfo( i, mdInfo) ; ++ i) {
|
|
if ( mdInfo.nFlag == MDPCI_START_CONT) {
|
|
MinDistPCInfo mdInfo2 ;
|
|
if ( dstPtCurve.GetMinDistInfo( i+1, mdInfo2) && mdInfo2.nFlag == MDPCI_END_CONT) {
|
|
// copio la curva e la limito al tratto continuo
|
|
PtrOwner<ICurve> pCrvLim( cCrv.Clone()) ;
|
|
if ( IsNull( pCrvLim) ||
|
|
! pCrvLim->TrimStartEndAtParam( mdInfo.dPar, mdInfo2.dPar))
|
|
break ;
|
|
// trovo il punto del tratto continuo a minima distanza dal punto near
|
|
Point3d ptTest ;
|
|
int nFlag ;
|
|
DistPointCurve dstPtCurve2( ptNear, *pCrvLim) ;
|
|
if ( dstPtCurve2.GetMinDistPoint( 0, ptTest, nFlag)) {
|
|
double dSqDist = SqDist( ptTest, ptNear) ;
|
|
if ( dSqDist < dMinSqDist) {
|
|
bFound = true ;
|
|
dMinSqDist = dSqDist ;
|
|
ptFoot = ptTest ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( ! bFound)
|
|
return nullptr ;
|
|
// creo la linea
|
|
PtrOwner<CurveLine> pCrvLine( CreateBasicCurveLine()) ;
|
|
if ( IsNull( pCrvLine))
|
|
return nullptr ;
|
|
// setto la linea
|
|
if ( ! pCrvLine->Set( ptP, ptFoot))
|
|
return nullptr ;
|
|
// la restituisco
|
|
return Release( pCrvLine) ;
|
|
}
|