From 3d060f2bb2075dcd643ec5057a3dc0b5903225ea Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 20 Nov 2013 17:42:47 +0000 Subject: [PATCH] Include : primo salvataggio. --- EGkFrame3d.h | 95 +++++++++++++++++++++++++++ EGkGeoConst.h | 40 +++++++++++ EGkPoint3d.h | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++ EGkVector3d.h | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ EgtTrace.h | 23 +++++++ 5 files changed, 511 insertions(+) create mode 100644 EGkFrame3d.h create mode 100644 EGkGeoConst.h create mode 100644 EGkPoint3d.h create mode 100644 EGkVector3d.h create mode 100644 EgtTrace.h diff --git a/EGkFrame3d.h b/EGkFrame3d.h new file mode 100644 index 0000000..bc15fcc --- /dev/null +++ b/EGkFrame3d.h @@ -0,0 +1,95 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgkFrame3d.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe Reference Frame 3d. +// +// +// +// Modifiche : 04.01.12 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGKPoint3d.h" + +//----------------------- Macro per import/export ---------------------------- +#undef EGK_EXPORT +#ifdef I_AM_EGK // da definirsi solo nei moduli della DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//---------------------------------------------------------------------------- +class EGK_EXPORT Frame3d +{ + public : + enum Type { ERR = 0, TOP = 1, BOTTOM = 2, FRONT = 3, + BACK = 4, LEFT = 5, RIGHT = 6, GEN = 7} ; + public : + Frame3d( void) ; + bool Set( const Point3d& ptOrig, const Vector3d& vtDirX, + const Vector3d& vtDirY, const Vector3d& vtDirZ) ; + bool Set( const Point3d& ptOrig, const Point3d& ptOnX, const Point3d& ptNearY) ; + bool Set( const Point3d& ptOrig, Type nType) ; + bool Reset( void) ; + void Translate( const Vector3d& vtMove) ; + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngRad) ; + // Scale non possibile (non previsti fattori di scala) + // Mirror non possibile (cambia il senso destrorso in sinistrorso) + bool ToGlob( const Frame3d& frRef) ; + bool ToLoc( const Frame3d& frRef) ; + inline const Frame3d operator*=( const Frame3d& frRef) { this->ToGlob( frRef) ; return *this ;} + inline const Frame3d operator/=( const Frame3d& frRef) { this->ToLoc( frRef) ; return *this ;} + inline int GetType( void) const { return m_nType ;} + inline int GetZType( void) const { return m_nZType ;} + inline const Point3d& Orig( void) const { return m_ptOrig ;} + inline const Vector3d& VersX( void) const { return m_vtVersX ;} + inline const Vector3d& VersY( void) const { return m_vtVersY ;} + inline const Vector3d& VersZ( void) const { return m_vtVersZ ;} + + private : + void CalculateType( void) ; + + private : + Type m_nType ; + Type m_nZType ; + Point3d m_ptOrig ; + Vector3d m_vtVersX ; + Vector3d m_vtVersY ; + Vector3d m_vtVersZ ; + +} ; + +//---------------------------------------------------------------------------- +// Prodotto di due frame (porta il primo dal secondo nel globale) +//---------------------------------------------------------------------------- +inline const Frame3d +operator*( const Frame3d& frRef1, const Frame3d& frRef2) +{ + Frame3d frRefR ; + + + frRefR = frRef1 ; + frRefR.ToGlob( frRef2) ; + + return frRefR ; +} + +//---------------------------------------------------------------------------- +// Divisione di due frame (porta il primo dal globale nel secondo) +//---------------------------------------------------------------------------- +inline const Frame3d +operator/( const Frame3d& frRef1, const Frame3d& frRef2) +{ + Frame3d frRefR ; + + + frRefR = frRef1 ; + frRefR.ToLoc( frRef2) ; + + return frRefR ; +} diff --git a/EGkGeoConst.h b/EGkGeoConst.h new file mode 100644 index 0000000..de291e1 --- /dev/null +++ b/EGkGeoConst.h @@ -0,0 +1,40 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgkGeoConst.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Costanti generali per calcoli geometrici. +// +// +// +// Modifiche : 04.01.12 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +//----------------- Costanti generali ---------------------------------------- +// unità di lunghezza di riferimento : millimetro +#define ONEMM 1 +#define ONEINCH 25.4 + +// epsilon per lunghezze e versori +#define EPS_SMALL (1e-3) +#define EPS_ZERO (1e-7) + +// infinito per lunghezze +#define INFINITO (1e10) + +// epsilon per gli angoli (in gradi) +#define EPS_ANG_SMALL (1e-3) +#define EPS_ANG_ZERO (1e-7) +#define SIN_EPS_ANG_SMALL (EPS_ANG_SMALL*DEGTORAD) +#define SIN_EPS_ANG_ZERO (EPS_ANG_ZERO*DEGTORAD) +#define COS_ORTO_ANG_SMALL SIN_EPS_ANG_SMALL +#define COS_ORTO_ANG_ZERO SIN_EPS_ANG_ZERO + +// conversione da gradi a radianti e viceversa +#define PIGRECO (3.14159265358979324) +#define DEGTORAD (PIGRECO / 180.) +#define RADTODEG (180. / PIGRECO) diff --git a/EGkPoint3d.h b/EGkPoint3d.h new file mode 100644 index 0000000..0f4aef0 --- /dev/null +++ b/EGkPoint3d.h @@ -0,0 +1,179 @@ +//---------------------------------------------------------------------------- +// 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 +#ifdef I_AM_EGK // da definirsi solo nei moduli della DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//-------------------------- Forward Definition ------------------------------- +class Frame3d ; + +//----------------------------------------------------------------------------- +class EGK_EXPORT Point3d +{ + public : + inline Point3d( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;} + inline Point3d( double dX, double dY) { x = dX ; y = dY ; z = 0 ;} + inline Point3d( void) { x = 0 ; y = 0 ; z = 0 ;} + inline void Set( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;} + inline const Point3d& operator =( const Point3d& ptSrc) + { if ( &ptSrc != this) { + x = ptSrc.x , y = ptSrc.y , z = ptSrc.z ; } + return *this ; } + public : + 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 Point3d& ptCen, double dCoeffX, double dCoeffY, double dCoeffZ) ; + bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) ; + bool ToGlob( const Frame3d& frRef) ; + bool ToLoc( const Frame3d& frRef) ; + + public : + double x ; + double y ; + double z ; +} ; + + +//---------------------------------------------------------------------------- +// 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) ; +} + +//---------------------------------------------------------------------------- +// 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 +DistSq( 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) ; +} + +//---------------------------------------------------------------------------- +// Verifica che due punti sono quasi coincidenti (Small error -> Near) +//---------------------------------------------------------------------------- +inline bool +AreSamePointNear( const Point3d& ptP1, const Point3d& ptP2) +{ + return ( DistSq( 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 ( DistSq( ptP1, ptP2) < ( EPS_ZERO * EPS_ZERO)) ; +} diff --git a/EGkVector3d.h b/EGkVector3d.h new file mode 100644 index 0000000..9ff7ba9 --- /dev/null +++ b/EGkVector3d.h @@ -0,0 +1,174 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgkVector3d.h Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe Vettore 3d. +// +// +// +// Modifiche : 31.12.12 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGeoConst.h" + +//----------------------- Macro per import/export ----------------------------- +#undef EGK_EXPORT +#ifdef I_AM_EGK // da definirsi solo nei moduli della DLL + #define EGK_EXPORT __declspec( dllexport) +#else + #define EGK_EXPORT __declspec( dllimport) +#endif + +//-------------------------- Forward Definition ------------------------------- +class Frame3d ; + +//----------------------------------------------------------------------------- +class EGK_EXPORT Vector3d +{ + public : + inline Vector3d( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;} + inline Vector3d( double dX, double dY) { x = dX ; y = dY ; z = 0 ;} + inline Vector3d( void) { x = 0 ; y = 0 ; z = 0 ;} + inline void Set( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;} + inline const Vector3d& operator =( const Vector3d& vtSrc) + { if ( &vtSrc != this) { + x = vtSrc.x , y = vtSrc.y , z = vtSrc.z ; } + return *this ; } + void FromSpherical( double dLen, double dAngVertDeg, double dAngOrizzDeg) ; + void FromPolar( double dLen, double dAngDeg) ; + + public : + double LenSq( void) const ; + double Len( void) const ; + inline bool IsSmall( void) const + { return ( ( x * x + y * y + z * z) < ( EPS_SMALL * EPS_SMALL)) ; } + inline bool IsZero( void) const + { return ( ( x * x + y * y + z * z) < ( EPS_ZERO * EPS_ZERO)) ; } + inline bool IsNormalized( void) const + { return ( fabs( 1.0 - (x * x + y * y + z * z)) < ( 2 * EPS_ZERO)) ; } + inline bool IsZplus( void) const + { return ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO && z > EPS_ZERO) ; } + inline bool IsZminus( void) const + { return ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO && z < - EPS_ZERO) ; } + void ToSpherical( double* pdLen, double* pdAngVertDeg, double* pdAngOrizzDeg) const ; + bool Normalize( void) ; + bool Rotate( const Vector3d& vtAx, double dAngRad) ; + bool Rotate( const Vector3d& vtAx, double dCosAng, double dSinAng) ; + bool Scale( double dCoeffX, double dCoeffY, double dCoeffZ) ; + bool Mirror( const Vector3d& vtNorm) ; + bool ToGlob( const Frame3d& frRef) ; + bool ToLoc( const Frame3d& frRef) ; + + public : + double x ; + double y ; + double z ; +} ; + +//---------------------------------------------------------------------------- +// Opposto di un vettore +//---------------------------------------------------------------------------- +inline Vector3d +operator-( const Vector3d& vtV) +{ + return ( Vector3d( - vtV.x, - vtV.y, - vtV.z)) ; +} + +//---------------------------------------------------------------------------- +// Somma di due vettori +//---------------------------------------------------------------------------- +inline Vector3d +operator+( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( Vector3d( vtV1.x + vtV2.x, vtV1.y + vtV2.y, vtV1.z + vtV2.z)) ; +} + +//---------------------------------------------------------------------------- +// Sottrazione di due vettori +//---------------------------------------------------------------------------- +inline Vector3d +operator-( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( Vector3d( vtV1.x - vtV2.x, vtV1.y - vtV2.y, vtV1.z - vtV2.z)) ; +} + +//---------------------------------------------------------------------------- +// Prodotto con uno scalare +//---------------------------------------------------------------------------- +inline Vector3d +operator*( const Vector3d& vtV, double dMul) +{ + return ( Vector3d( vtV.x * dMul, vtV.y * dMul, vtV.z * dMul)) ; +} + +//---------------------------------------------------------------------------- +inline Vector3d +operator*( double dMul, const Vector3d& vtV) +{ + return ( Vector3d( vtV.x * dMul, vtV.y * dMul, vtV.z * dMul)) ; +} + +//---------------------------------------------------------------------------- +// Divisione con uno scalare +//---------------------------------------------------------------------------- +inline Vector3d +operator/( const Vector3d& vtV, double dDiv) +{ + double dMul ; + + dMul = 1 / dDiv ; + return ( Vector3d( vtV.x * dMul, vtV.y * dMul, vtV.z * dMul)) ; +} + +//---------------------------------------------------------------------------- +// Prodotto scalare +//---------------------------------------------------------------------------- +inline double +operator*( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( vtV1.x * vtV2.x + vtV1.y * vtV2.y + vtV1.z * vtV2.z) ; +} + +//---------------------------------------------------------------------------- +// Prodotto vettoriale +//---------------------------------------------------------------------------- +inline Vector3d +operator^( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( Vector3d( vtV1.y * vtV2.z - vtV1.z * vtV2.y, + vtV1.z * vtV2.x - vtV1.x * vtV2.z, + vtV1.x * vtV2.y - vtV1.y * vtV2.x)) ; +} + +//---------------------------------------------------------------------------- +// Somma mediata di due vettori (baricentrica) +//---------------------------------------------------------------------------- +inline Vector3d +Media( const Vector3d& vtV1, const Vector3d& vtV2, double dCoeff) +{ + return ( Vector3d( ( 1 - dCoeff) * vtV1.x + dCoeff * vtV2.x, + ( 1 - dCoeff) * vtV1.y + dCoeff * vtV2.y, + ( 1 - dCoeff) * vtV1.z + dCoeff * vtV2.z)) ; +} + +//---------------------------------------------------------------------------- +// Verifica che due versori sono ortogonali (Small error -> Near) +//---------------------------------------------------------------------------- +inline bool +AreOrthoNear( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( fabs( vtV1 * vtV2) < COS_ORTO_ANG_SMALL) ; +} + +//---------------------------------------------------------------------------- +// Verifica che due versori sono ortogonali (Zero error -> Exact) +//---------------------------------------------------------------------------- +inline bool +AreOrthoExact( const Vector3d& vtV1, const Vector3d& vtV2) +{ + return ( fabs( vtV1 * vtV2) < COS_ORTO_ANG_ZERO) ; +} diff --git a/EgtTrace.h b/EgtTrace.h new file mode 100644 index 0000000..7221252 --- /dev/null +++ b/EgtTrace.h @@ -0,0 +1,23 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EgtTrace.h Data : 16.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione macro per TRACE. +// +// +// +// Modifiche : 16.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + + +#include + +#ifdef _DEBUG + #define EGT_TRACE( sz) OutputDebugStringA( sz) +#else + #define EGT_TRACE( sz) +#endif