1f0f6af96f
- aggiunte prime interfacce per EgtGraphics ; - aggiunta interfaccia IObjGraphics per oggetti IGeoObj.
233 lines
8.8 KiB
C++
233 lines
8.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2013
|
|
//----------------------------------------------------------------------------
|
|
// File : EGkPoint3d.h Data : 20.11.13 Versione : 1.3a1
|
|
// Contenuto : Dichiarazione della classe Punto 3d.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 30.12.12 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "/EgtDev/Include/EGkVector3d.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
|
|
|
|
//-------------------------- Forward Definition -------------------------------
|
|
class Frame3d ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class EGK_EXPORT Point3d
|
|
{
|
|
public :
|
|
Point3d( double dX, double dY, double dZ) : x( dX), y( dY), z( dZ) {}
|
|
Point3d( double dX, double dY) : x( dX), y( dY), z( 0) {}
|
|
Point3d( void) : x( 0), y( 0), z( 0) {}
|
|
void Set( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;}
|
|
const Point3d& operator =( const Point3d& ptSrc)
|
|
{ if ( &ptSrc != this) {
|
|
x = ptSrc.x , y = ptSrc.y , z = ptSrc.z ; }
|
|
return *this ; }
|
|
|
|
public :
|
|
bool IsSmall( void) const
|
|
{ return ( ( x * x + y * y + z * z) < ( EPS_SMALL * EPS_SMALL)) ; }
|
|
bool IsZero( void) const
|
|
{ return ( ( x * x + y * y + z * z) < ( EPS_ZERO * EPS_ZERO)) ; }
|
|
const Point3d& operator +=( const Vector3d& vtV)
|
|
{ this->x += vtV.x ; this->y += vtV.y ; this->z += vtV.z ; return *this ; }
|
|
const Point3d& operator -=( const Vector3d& vtV)
|
|
{ this->x -= vtV.x ; this->y -= vtV.y ; this->z -= vtV.z ; return *this ; }
|
|
// questa somma è valida solo se equivalente ad una combinazione baricentrica
|
|
const Point3d& operator +=( const Point3d& ptP)
|
|
{ this->x += ptP.x ; this->y += ptP.y ; this->z += ptP.z ; return *this ; }
|
|
const Point3d& operator *=( double dMul)
|
|
{ this->x *= dMul ; this->y *= dMul ; this->z *= dMul ; return *this ; }
|
|
const Point3d& operator /=( double dDiv)
|
|
{ double dMul = 1 / dDiv ; this->x *= dMul ; this->y *= dMul ; this->z *= dMul ; return *this ; }
|
|
void Translate( const Vector3d& vtMove) ;
|
|
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) ;
|
|
bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) ;
|
|
bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) ;
|
|
bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) ;
|
|
bool ToGlob( const Frame3d& frRef) ;
|
|
bool ToLoc( const Frame3d& frRef) ;
|
|
bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
|
|
{ return ( ToGlob( frOri) && ToLoc( frDest)) ; }
|
|
|
|
public :
|
|
double x ;
|
|
double y ;
|
|
double z ;
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Punti notevoli
|
|
//----------------------------------------------------------------------------
|
|
const Point3d ORIG( 0, 0, 0) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Somma di due punti
|
|
// (valida solo se equivalente ad una combinazione baricentrica).
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator+( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
return Point3d( ptP1.x + ptP2.x, ptP1.y + ptP2.y, ptP1.z + ptP2.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Somma di un punto e un vettore
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator+( const Point3d& ptP1, const Vector3d& vtV2)
|
|
{
|
|
return Point3d( ptP1.x + vtV2.x, ptP1.y + vtV2.y, ptP1.z + vtV2.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Opposto di un punto
|
|
//----------------------------------------------------------------------------
|
|
inline Vector3d
|
|
operator-( const Point3d& ptP)
|
|
{
|
|
return Vector3d( - ptP.x, - ptP.y, - ptP.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Differenza di due punti, genera un vettore
|
|
//----------------------------------------------------------------------------
|
|
inline Vector3d
|
|
operator-( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
return Vector3d( ptP1.x - ptP2.x, ptP1.y - ptP2.y, ptP1.z - ptP2.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Sottrazione di un punto e un vettore
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator-( const Point3d& ptP1, const Vector3d& vtV2)
|
|
{
|
|
return Point3d( ptP1.x - vtV2.x, ptP1.y - vtV2.y, ptP1.z - vtV2.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Prodotto con uno scalare
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator*( const Point3d& ptP, double dMul)
|
|
{
|
|
return Point3d( ptP.x * dMul, ptP.y * dMul, ptP.z * dMul) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator*( double dMul, const Point3d& ptP)
|
|
{
|
|
return Point3d( ptP.x * dMul, ptP.y * dMul, ptP.z * dMul) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Divisione per uno scalare
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
operator/( const Point3d& ptP, double dDiv)
|
|
{
|
|
double dMul ;
|
|
|
|
dMul = 1 / dDiv ;
|
|
return ( Point3d( ptP.x * dMul, ptP.y * dMul, ptP.z * dMul)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Somma mediata di due punti (baricentrica)
|
|
//----------------------------------------------------------------------------
|
|
inline Point3d
|
|
Media( const Point3d& ptP1, const Point3d& ptP2, double dCoeff)
|
|
{
|
|
return Point3d( ( 1 - dCoeff) * ptP1.x + dCoeff * ptP2.x,
|
|
( 1 - dCoeff) * ptP1.y + dCoeff * ptP2.y,
|
|
( 1 - dCoeff) * ptP1.z + dCoeff * ptP2.z) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Quadrato della distanza tra due punti
|
|
//----------------------------------------------------------------------------
|
|
inline double
|
|
SqDist( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
double dX = ptP1.x - ptP2.x ;
|
|
double dY = ptP1.y - ptP2.y ;
|
|
double dZ = ptP1.z - ptP2.z ;
|
|
|
|
return ( dX * dX + dY * dY + dZ * dZ) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Distanza tra due punti
|
|
//----------------------------------------------------------------------------
|
|
inline double
|
|
Dist( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
double dX = ptP1.x - ptP2.x ;
|
|
double dY = ptP1.y - ptP2.y ;
|
|
double dZ = ptP1.z - ptP2.z ;
|
|
|
|
if ( fabs( dY) < EPS_ZERO && fabs( dZ) < EPS_ZERO)
|
|
return fabs( dX) ;
|
|
if ( fabs( dZ) < EPS_ZERO && fabs( dX) < EPS_ZERO)
|
|
return fabs( dY) ;
|
|
if ( fabs( dX) < EPS_ZERO && fabs( dY) < EPS_ZERO)
|
|
return fabs( dZ) ;
|
|
|
|
return sqrt( dX * dX + dY * dY + dZ * dZ) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Direzione e distanza tra due punti
|
|
//----------------------------------------------------------------------------
|
|
inline bool
|
|
DirDist( const Point3d& ptP1, const Point3d& ptP2, Vector3d& vtDir, double& dDist)
|
|
{
|
|
dDist = Dist( ptP1, ptP2) ;
|
|
|
|
// se distanza significativa
|
|
if ( dDist > EPS_SMALL) {
|
|
vtDir = ( ptP2 - ptP1) / dDist ;
|
|
return true ;
|
|
}
|
|
|
|
// punti praticamente coincidenti
|
|
vtDir.Set( 0, 0, 0) ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Verifica che due punti sono quasi coincidenti (Small error -> Near)
|
|
//----------------------------------------------------------------------------
|
|
inline bool
|
|
AreSamePointNear( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
return ( SqDist( ptP1, ptP2) < ( EPS_SMALL * EPS_SMALL)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Verifica che due punti sono esattamente coincidenti (Zero error -> Exact)
|
|
//----------------------------------------------------------------------------
|
|
inline bool
|
|
AreSamePointExact( const Point3d& ptP1, const Point3d& ptP2)
|
|
{
|
|
return ( SqDist( ptP1, ptP2) < ( EPS_ZERO * EPS_ZERO)) ;
|
|
}
|