From 23bb013dec14c44f528dd0c7739a0c909b07d249 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 16 Oct 2017 08:01:19 +0000 Subject: [PATCH] Include : - aggiunti prototipi per Polygon3d, per IntersPlanePlane e per Inters3Planes - aggiornati Plane3d e IntersLinePlane. --- EGkIntersLinePlane.h | 4 +- EGkIntersPlanePlane.h | 37 +++++++++++++++++ EGkPlane3d.h | 95 +++++++++++++++++++++++++------------------ EGkPolygon3d.h | 63 ++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 41 deletions(-) create mode 100644 EGkIntersPlanePlane.h create mode 100644 EGkPolygon3d.h diff --git a/EGkIntersLinePlane.h b/EGkIntersLinePlane.h index ecae8e0..34e3013 100644 --- a/EGkIntersLinePlane.h +++ b/EGkIntersLinePlane.h @@ -25,9 +25,9 @@ //----------------------------------------------------------------------------- EGK_EXPORT int IntersLinePlane( const Point3d& ptL1, const Point3d& ptL2, const Plane3d& plPlane, - Point3d& ptInt) ; + Point3d& ptInt, bool bFinite = true) ; EGK_EXPORT int IntersLinePlane( const Point3d& ptL, const Vector3d& vtL, double dLen, const Plane3d& plPlane, - Point3d& ptInt) ; + Point3d& ptInt, bool bFinite = true) ; //----------------------------------------------------------------------------- // Tipo di intersezione linea-piano diff --git a/EGkIntersPlanePlane.h b/EGkIntersPlanePlane.h new file mode 100644 index 0000000..95b4f24 --- /dev/null +++ b/EGkIntersPlanePlane.h @@ -0,0 +1,37 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : EGkIntersPlanePlane.h Data : 15.10.17 Versione : 1.8j3 +// Contenuto : Dichiarazione della classe intersezione piano/piano. +// +// +// +// Modifiche : 15.10.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkPlane3d.h" + +//----------------------- Macro per import/export ---------------------------- +#undef EGK_EXPORT +#if defined( I_AM_EGK) // da definirsi solo nella DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//----------------------------------------------------------------------------- +EGK_EXPORT int IntersPlanePlane( const Plane3d& plPlane1, const Plane3d& plPlane2, + Point3d& ptInt, Vector3d& vtDir) ; +EGK_EXPORT int Inters3Planes( const Plane3d& plPlane1, const Plane3d& plPlane2, const Plane3d& plPlane3, + Point3d& ptInt) ; + +//----------------------------------------------------------------------------- +// Tipo di intersezione piano-piano +const int IPPT_NO = 0 ; // non c'è intersezione (piani paralleli) +const int IPPT_OVERLAPS = 1 ; // piani coincidenti +const int IPPT_YES = 2 ; // intersezione + \ No newline at end of file diff --git a/EGkPlane3d.h b/EGkPlane3d.h index 219ad36..4faf932 100644 --- a/EGkPlane3d.h +++ b/EGkPlane3d.h @@ -19,98 +19,115 @@ class Plane3d { public : - Vector3d vtN ; - double dDist ; + Plane3d( void) : m_vtN( V_NULL), m_dDist( 0) {} + bool Set( double dDist, const Vector3d& vtN) + { m_vtN = vtN ; + if ( ! m_vtN.Normalize()) { + m_vtN = V_NULL ; + return false ; + } + m_dDist = dDist ; + return true ; + } + bool Set( const Point3d& ptP, const Vector3d& vtN) + { m_vtN = vtN ; + if ( ! m_vtN.Normalize()) { + m_vtN = V_NULL ; + return false ; + } + m_dDist = ( ptP - ORIG) * m_vtN ; + return true ; + } + void Reset( void) + { m_vtN = V_NULL ; + m_dDist = 0 ; + } + const Vector3d& GetVersN( void) const + { return m_vtN ; } + double GetDist( void) const + { return m_dDist ; } public : void Translate( const Vector3d& vtMove) - { Point3d ptP = ORIG + dDist * vtN ; + { Point3d ptP = ORIG + m_dDist * m_vtN ; ptP.Translate( vtMove) ; - dDist = ( ptP - ORIG) * vtN ; } + m_dDist = ( ptP - ORIG) * m_vtN ; } bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) { double dAngRad = dAngDeg * DEGTORAD ; return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) - { Point3d ptP = ORIG + dDist * vtN ; - if ( ! ptP.Rotate( ptAx, vtAx, dCosAng, dSinAng) || ! vtN.Rotate( vtAx, dCosAng, dSinAng)) + { Point3d ptP = ORIG + m_dDist * m_vtN ; + if ( ! ptP.Rotate( ptAx, vtAx, dCosAng, dSinAng) || ! m_vtN.Rotate( vtAx, dCosAng, dSinAng)) return false ; - dDist = ( ptP - ORIG) * vtN ; + m_dDist = ( ptP - ORIG) * m_vtN ; return true ; } bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) - { Point3d ptP = ORIG + dDist * vtN ; + { Point3d ptP = ORIG + m_dDist * m_vtN ; Frame3d frOCS ; - if ( ! frOCS.Set( ptP, vtN) || ! frOCS.PseudoScale( frRef, dCoeffX, dCoeffY, dCoeffZ)) + if ( ! frOCS.Set( ptP, m_vtN) || ! frOCS.PseudoScale( frRef, dCoeffX, dCoeffY, dCoeffZ)) return false ; - vtN = frOCS.VersZ() ; - dDist = ( frOCS.Orig() - ORIG) * vtN ; + m_vtN = frOCS.VersZ() ; + m_dDist = ( frOCS.Orig() - ORIG) * m_vtN ; return true ; } bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) - { Point3d ptP = ORIG + dDist * vtN ; - if ( ! ptP.Mirror( ptOn, vtNorm) || ! vtN.Mirror( vtNorm)) + { Point3d ptP = ORIG + m_dDist * m_vtN ; + if ( ! ptP.Mirror( ptOn, vtNorm) || ! m_vtN.Mirror( vtNorm)) return false ; - dDist = ( ptP - ORIG) * vtN ; + m_dDist = ( ptP - ORIG) * m_vtN ; return true ; } bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) - { Point3d ptP = ORIG + dDist * vtN ; + { Point3d ptP = ORIG + m_dDist * m_vtN ; Frame3d frOCS ; - if ( ! frOCS.Set( ptP, vtN) || ! frOCS.PseudoShear( ptOn, vtNorm, vtDir, dCoeff)) + if ( ! frOCS.Set( ptP, m_vtN) || ! frOCS.PseudoShear( ptOn, vtNorm, vtDir, dCoeff)) return false ; - vtN = frOCS.VersZ() ; - dDist = ( frOCS.Orig() - ORIG) * vtN ; + m_vtN = frOCS.VersZ() ; + m_dDist = ( frOCS.Orig() - ORIG) * m_vtN ; return true ; } bool ToGlob( const Frame3d& frRef) - { Point3d ptP = ORIG + dDist * vtN ; - if ( ! ptP.ToGlob( frRef) || ! vtN.ToGlob( frRef)) + { Point3d ptP = ORIG + m_dDist * m_vtN ; + if ( ! ptP.ToGlob( frRef) || ! m_vtN.ToGlob( frRef)) return false ; - dDist = ( ptP - ORIG) * vtN ; + m_dDist = ( ptP - ORIG) * m_vtN ; return true ; } bool ToLoc( const Frame3d& frRef) - { Point3d ptP = ORIG + dDist * vtN ; - if ( ! ptP.ToLoc( frRef) || ! vtN.ToLoc( frRef)) + { Point3d ptP = ORIG + m_dDist * m_vtN ; + if ( ! ptP.ToLoc( frRef) || ! m_vtN.ToLoc( frRef)) return false ; - dDist = ( ptP - ORIG) * vtN ; + m_dDist = ( ptP - ORIG) * m_vtN ; return true ; } bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) { if ( AreSameFrame( frOri, frDest)) return true ; return ( ToGlob( frOri) && ToLoc( frDest)) ; } + private : + Vector3d m_vtN ; + double m_dDist ; } ; -//----------------------------------------------------------------------------- -inline bool -SetPlane( const Point3d& ptP, const Vector3d& vtN, Plane3d& plPlane) -{ - plPlane.vtN = vtN ; - if ( ! plPlane.vtN.Normalize()) - return false ; - plPlane.dDist = ( ptP - ORIG) * plPlane.vtN ; - return true ; -} - //----------------------------------------------------------------------------- inline double DistPointPlane( const Point3d& ptP, const Plane3d& plPlane) { - return ((( ptP - ORIG) * plPlane.vtN) - plPlane.dDist) ; + return ((( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) ; } //----------------------------------------------------------------------------- inline bool PointInPlaneEpsilon( const Point3d& ptP, const Plane3d& plPlane, double dToler) { - return ( fabs( (( ptP - ORIG) * plPlane.vtN) - plPlane.dDist) < dToler) ; + return ( fabs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < dToler) ; } //----------------------------------------------------------------------------- inline bool PointInPlaneApprox( const Point3d& ptP, const Plane3d& plPlane) { - return ( fabs( (( ptP - ORIG) * plPlane.vtN) - plPlane.dDist) < EPS_SMALL) ; + return ( fabs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < EPS_SMALL) ; } //----------------------------------------------------------------------------- inline bool PointInPlaneExact( const Point3d& ptP, const Plane3d& plPlane) { - return ( fabs( (( ptP - ORIG) * plPlane.vtN) - plPlane.dDist) < EPS_ZERO) ; + return ( fabs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < EPS_ZERO) ; } diff --git a/EGkPolygon3d.h b/EGkPolygon3d.h new file mode 100644 index 0000000..759f56d --- /dev/null +++ b/EGkPolygon3d.h @@ -0,0 +1,63 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : Polygon3d.h Data : 30.08.15 Versione : 1.6h5 +// Contenuto : Dichiarazione della classe Polygon3d (poligono nello spazio). +// +// +// +// Modifiche : 30.08.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkPlane3d.h" +#include "/EgtDev/Include/EGkPolyLine.h" +#include "/EgtDev/Include/EGkGeoCollection.h" + +//----------------------- Macro per import/export ---------------------------- +#undef EGK_EXPORT +#if defined( I_AM_EGK) // da definirsi solo nella DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//---------------------------------------------------------------------------- +class Polygon3d +{ + public : + EGK_EXPORT bool FromRectangle( double dDimX, double dDimY) ; + EGK_EXPORT bool FromPolyLine( const PolyLine& PL) ; + EGK_EXPORT bool FromPlaneTrimmedWithBox( const Plane3d& plPlane, const Point3d& ptMin, const Point3d& ptMax) ; + EGK_EXPORT bool FromPlaneTrimmedWithBox( const Point3d& ptOn, const Vector3d& vtN, + const Point3d& ptMin, const Point3d& ptMax) ; + EGK_EXPORT bool Trim( const Plane3d& plPlane, bool bInVsOut, bool bOnEq) ; + EGK_EXPORT bool Trim( const Polygon3d& plyOther, bool bInVsOut, bool bOnEq) ; + EGK_EXPORT bool IsValid( void) const + { return ! m_Plane.GetVersN().IsSmall() ; } + EGK_EXPORT Vector3d GetVersN( void) + { return m_Plane.GetVersN() ; } + EGK_EXPORT int GetSideCount( void) const + { return ( IsValid() ? int( m_vVert.size()) : 0) ; } + EGK_EXPORT PolyLine GetPolyLine( void) const ; + + public : + EGK_EXPORT void Translate( const Vector3d& vtMove) ; + EGK_EXPORT bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + EGK_EXPORT bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ; + EGK_EXPORT bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) ; + EGK_EXPORT bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) ; + EGK_EXPORT bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) ; + EGK_EXPORT bool ToGlob( const Frame3d& frRef) ; + EGK_EXPORT bool ToLoc( const Frame3d& frRef) ; + EGK_EXPORT bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) ; + + private : + Plane3d m_Plane ; // piano in cui giace il poligono + PNTVECTOR m_vVert ; // elenco ordinato dei vertici del poligono (CCW da Z+ piano) +} ;