diff --git a/EGkGeoCollection.h b/EGkGeoCollection.h index 30d6c60..b480210 100644 --- a/EGkGeoCollection.h +++ b/EGkGeoCollection.h @@ -20,8 +20,9 @@ //---------------------------------------------------------------------------- // Raccolte di Point3d -typedef std::vector PNTVECTOR ; // vettore di punti -typedef std::list PNTLIST ; // lista di punti +typedef std::vector PNTVECTOR ; // vettore di punti +typedef std::list PNTLIST ; // lista di punti +typedef std::vector PNTMATRIX ; // matrice di punti //---------------------------------------------------------------------------- // Raccolte di coppie Point3d,dU diff --git a/EGkGeoConst.h b/EGkGeoConst.h index a2fb01f..78adb38 100644 --- a/EGkGeoConst.h +++ b/EGkGeoConst.h @@ -1,13 +1,13 @@ //---------------------------------------------------------------------------- -// EgalTech 2013-2013 +// EgalTech 2013-2019 //---------------------------------------------------------------------------- -// File : EgkGeoConst.h Data : 20.11.13 Versione : 1.3a1 +// File : EgkGeoConst.h Data : 23.11.19 Versione : 2.1k5 // Contenuto : Costanti generali per calcoli geometrici. // // // // Modifiche : 04.01.12 DS Creazione modulo. -// +// 23.11.19 DS Aggiunta costante EPS_TRIA_H. // //---------------------------------------------------------------------------- @@ -21,10 +21,12 @@ const double ONEINCH = 25.4 ; // epsilon per lunghezze, versori e parametri const double EPS_SMALL = 1e-3 ; +const double EPS_TRIA_H = 1e-6 ; const double EPS_ZERO = 1e-8 ; const double EPS_PARAM = 1e-8 ; const double SPAN_PARAM = 1.0 ; // intervallo di curva o superficie semplici const double SQ_EPS_SMALL = EPS_SMALL * EPS_SMALL ; +const double SQ_EPS_TRIA_H = EPS_TRIA_H * EPS_TRIA_H ; const double SQ_EPS_ZERO = EPS_ZERO * EPS_ZERO ; // infinito per lunghezze diff --git a/EGkTriangle3d.h b/EGkTriangle3d.h index c4dba47..5e76ded 100644 --- a/EGkTriangle3d.h +++ b/EGkTriangle3d.h @@ -51,22 +51,36 @@ class Triangle3d bool Validate( bool bOverwrite = false) { if ( AreSamePointApprox( m_ptP[0], m_ptP[1]) || AreSamePointApprox( m_ptP[0], m_ptP[2])) return false ; - Vector3d vtV = ( m_ptP[1] - m_ptP[0]) ^ ( m_ptP[2] - m_ptP[0]) ; - vtV.Normalize( EPS_ZERO) ; + Vector3d vtV1 = m_ptP[1] - m_ptP[0] ; + Vector3d vtV2 = m_ptP[2] - m_ptP[1] ; + Vector3d vtN = vtV1 ^ vtV2 ; + double dSqN = vtN.SqLen() ; + if ( dSqN < SQ_EPS_ZERO) + return false ; + if ( dSqN < SQ_EPS_TRIA_H * std::max( { vtV1.SqLen(), vtV2.SqLen(), ( vtV1 + vtV2).SqLen()})) + return false ; + vtN /= sqrt( dSqN) ; if ( m_vtN.IsSmall() || bOverwrite) { - m_vtN = vtV ; + m_vtN = vtN ; return true ; } - return AreSameVectorApprox( vtV, m_vtN) ; + return AreSameVectorApprox( vtN, m_vtN) ; } bool IsValid( void) const { if ( AreSamePointApprox( m_ptP[0], m_ptP[1]) || AreSamePointApprox( m_ptP[0], m_ptP[2])) return false ; if ( m_vtN.IsSmall()) return false ; - Vector3d vtV = ( m_ptP[1] - m_ptP[0]) ^ ( m_ptP[2] - m_ptP[0]) ; - vtV.Normalize( EPS_ZERO) ; - return AreSameVectorApprox( vtV, m_vtN) ; + Vector3d vtV1 = m_ptP[1] - m_ptP[0] ; + Vector3d vtV2 = m_ptP[2] - m_ptP[1] ; + Vector3d vtN = vtV1 ^ vtV2 ; + double dSqN = vtN.SqLen() ; + if ( dSqN < SQ_EPS_ZERO) + return false ; + if ( dSqN < SQ_EPS_TRIA_H * std::max( { vtV1.SqLen(), vtV2.SqLen(), ( vtV1 + vtV2).SqLen()})) + return false ; + vtN /= sqrt( dSqN) ; + return AreSameVectorApprox( vtN, m_vtN) ; } void Translate( const Vector3d& vtMove) { m_ptP[0].Translate( vtMove) ;