7cc55217f8
- correzione prototipi.
182 lines
7.5 KiB
C++
182 lines
7.5 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : EGkPlane3d.h Data : 25.02.15 Versione : 1.6b7
|
|
// Contenuto : Dichiarazione classe piano Plane3d.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 08.04.14 DS Creazione modulo.
|
|
// 25.02.15 DS Agg. PointInPlane*.
|
|
// 05.09.25 RE Agg. funzioni di confronto tra due piani
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "/EgtDev/Include/EGkFrame3d.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class Plane3d
|
|
{
|
|
public :
|
|
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 ;
|
|
}
|
|
bool Set( const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3)
|
|
{ if ( AreSamePointApprox( ptP1, ptP2) ||
|
|
AreSamePointApprox( ptP2, ptP3) ||
|
|
AreSamePointApprox( ptP3, ptP1)) {
|
|
m_vtN = V_NULL ;
|
|
return false ;
|
|
}
|
|
Vector3d vtN = ( ptP2 - ptP1) ^ ( ptP3 - ptP2) ;
|
|
return Set( ptP1, vtN) ;
|
|
}
|
|
void Reset( void)
|
|
{ m_vtN = V_NULL ;
|
|
m_dDist = 0 ;
|
|
}
|
|
bool IsValid( void) const
|
|
{ return ! m_vtN.IsSmall() ; }
|
|
const Vector3d& GetVersN( void) const
|
|
{ return m_vtN ; }
|
|
double GetDist( void) const
|
|
{ return m_dDist ; }
|
|
Point3d GetPoint( void) const
|
|
{ return ( ORIG + m_dDist * m_vtN) ; }
|
|
void Translate( const Vector3d& vtMove)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
ptP.Translate( vtMove) ;
|
|
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 + m_dDist * m_vtN ;
|
|
if ( ! ptP.Rotate( ptAx, vtAx, dCosAng, dSinAng) || ! m_vtN.Rotate( vtAx, dCosAng, dSinAng))
|
|
return false ;
|
|
m_dDist = ( ptP - ORIG) * m_vtN ;
|
|
return true ; }
|
|
bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
Frame3d frOCS ;
|
|
if ( ! frOCS.Set( ptP, m_vtN) || ! frOCS.PseudoScale( frRef, dCoeffX, dCoeffY, dCoeffZ))
|
|
return false ;
|
|
m_vtN = frOCS.VersZ() ;
|
|
m_dDist = ( frOCS.Orig() - ORIG) * m_vtN ;
|
|
return true ; }
|
|
bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
if ( ! ptP.Mirror( ptOn, vtNorm) || ! m_vtN.Mirror( vtNorm))
|
|
return false ;
|
|
m_dDist = ( ptP - ORIG) * m_vtN ;
|
|
return true ; }
|
|
bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
Frame3d frOCS ;
|
|
if ( ! frOCS.Set( ptP, m_vtN) || ! frOCS.PseudoShear( ptOn, vtNorm, vtDir, dCoeff))
|
|
return false ;
|
|
m_vtN = frOCS.VersZ() ;
|
|
m_dDist = ( frOCS.Orig() - ORIG) * m_vtN ;
|
|
return true ; }
|
|
bool ToGlob( const Frame3d& frRef)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
if ( ! ptP.ToGlob( frRef) || ! m_vtN.ToGlob( frRef))
|
|
return false ;
|
|
m_dDist = ( ptP - ORIG) * m_vtN ;
|
|
return true ; }
|
|
bool ToLoc( const Frame3d& frRef)
|
|
{ Point3d ptP = ORIG + m_dDist * m_vtN ;
|
|
if ( ! ptP.ToLoc( frRef) || ! m_vtN.ToLoc( frRef))
|
|
return false ;
|
|
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)) ; }
|
|
void Offset( double dDist)
|
|
{ m_dDist += dDist ; }
|
|
void Invert( void)
|
|
{ m_dDist = - m_dDist ; m_vtN = - m_vtN ; }
|
|
private :
|
|
Vector3d m_vtN ;
|
|
double m_dDist ;
|
|
} ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline double
|
|
DistPointPlane( const Point3d& ptP, const Plane3d& plPlane)
|
|
{
|
|
return ((( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline Point3d
|
|
ProjectPointOnPlane( const Point3d& ptP, const Plane3d& plPlane)
|
|
{
|
|
return ( ptP - DistPointPlane( ptP, plPlane) * plPlane.GetVersN()) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
PointInPlaneEpsilon( const Point3d& ptP, const Plane3d& plPlane, double dToler)
|
|
{
|
|
return ( abs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < dToler) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
PointInPlaneApprox( const Point3d& ptP, const Plane3d& plPlane)
|
|
{
|
|
return ( abs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < EPS_SMALL) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
PointInPlaneExact( const Point3d& ptP, const Plane3d& plPlane)
|
|
{
|
|
return ( abs( (( ptP - ORIG) * plPlane.GetVersN()) - plPlane.GetDist()) < EPS_ZERO) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
AreSamePlaneEpsilon( const Plane3d& plPlaneA, const Plane3d& plPlaneB, double dToler)
|
|
{
|
|
return ( AreSameVectorEpsilon( plPlaneA.GetVersN(), plPlaneB.GetVersN(), dToler) &&
|
|
PointInPlaneEpsilon( plPlaneA.GetPoint(), plPlaneB, dToler)) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
AreSamePlaneApprox( const Plane3d& plPlaneA, const Plane3d& plPlaneB)
|
|
{
|
|
return ( AreSameVectorApprox( plPlaneA.GetVersN(), plPlaneB.GetVersN()) &&
|
|
PointInPlaneApprox( plPlaneA.GetPoint(), plPlaneB)) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
inline bool
|
|
AreSamePlaneExact( const Plane3d& plPlaneA, const Plane3d& plPlaneB)
|
|
{
|
|
return ( AreSameVectorExact( plPlaneA.GetVersN(), plPlaneB.GetVersN()) &&
|
|
PointInPlaneExact( plPlaneA.GetPoint(), plPlaneB)) ;
|
|
}
|