//---------------------------------------------------------------------------- // 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" #include //----------------------- 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 Vector3d { public : Vector3d( double dX, double dY, double dZ) : x( dX), y( dY), z( dZ) {} Vector3d( double dX, double dY) : x( dX), y( dY), z( 0) {} Vector3d( void) : x( 0), y( 0), z( 0) {} void Set( double dX, double dY, double dZ) { x = dX ; y = dY ; z = dZ ;} 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 SqLen( void) const ; double Len( void) const ; 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)) ; } bool IsNormalized( void) const { return ( fabs( 1.0 - (x * x + y * y + z * z)) < ( 2 * EPS_ZERO)) ; } bool IsXplus( void) const { return ( x > EPS_ZERO && fabs( y) < EPS_ZERO && fabs( z) < EPS_ZERO) ; } bool IsXminus( void) const { return ( x < - EPS_ZERO && fabs( y) < EPS_ZERO && fabs( z) < EPS_ZERO) ; } bool IsYplus( void) const { return ( fabs( x) < EPS_ZERO && y > EPS_ZERO && fabs( z) < EPS_ZERO) ; } bool IsYminus( void) const { return ( fabs( x) < EPS_ZERO && y < - EPS_ZERO && fabs( z) < EPS_ZERO) ; } bool IsZplus( void) const { return ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO && z > EPS_ZERO) ; } bool IsZminus( void) const { return ( fabs( x) < EPS_ZERO && fabs( y) < EPS_ZERO && z < - EPS_ZERO) ; } const Vector3d& operator +=( const Vector3d& vtV) { this->x += vtV.x ; this->y += vtV.y ; this->z += vtV.z ; return *this ; } const Vector3d& operator -=( const Vector3d& vtV) { this->x -= vtV.x ; this->y -= vtV.y ; this->z -= vtV.z ; return *this ; } const Vector3d& operator *=( double dMul) { this->x *= dMul ; this->y *= dMul ; this->z *= dMul ; return *this ; } const Vector3d& operator /=( double dDiv) { double dMul = 1 / dDiv ; this->x *= dMul ; this->y *= dMul ; this->z *= dMul ; return *this ; } 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( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) ; bool Mirror( 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)) ; } bool GetAngle( const Vector3d& vtEnd, double& dAngDeg) const ; bool GetRotation( const Vector3d& vtEnd, const Vector3d& vtAx, double& dAngDeg, bool& bDet) const ; public : double x ; double y ; double z ; } ; //---------------------------------------------------------------------------- // Vettori notevoli //---------------------------------------------------------------------------- const Vector3d X_AX( 1, 0, 0) ; const Vector3d Y_AX( 0, 1, 0) ; const Vector3d Z_AX( 0, 0, 1) ; //---------------------------------------------------------------------------- // 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 vettori sono quasi coincidenti (Small error -> Near) //---------------------------------------------------------------------------- inline bool AreSameVectorNear( const Vector3d& vtV1, const Vector3d& vtV2) { return ( ( vtV1 - vtV2).IsSmall()) ; } //---------------------------------------------------------------------------- // Verifica che due vettori sono esattamente coincidenti (Zero error -> Exact) //---------------------------------------------------------------------------- inline bool AreSameVectorExact( const Vector3d& vtV1, const Vector3d& vtV2) { return ( ( vtV1 - vtV2).IsZero()) ; } //---------------------------------------------------------------------------- // Verifica che due vettori sono quasi opposti (Small error -> Near) //---------------------------------------------------------------------------- inline bool AreOppositeVectorNear( const Vector3d& vtV1, const Vector3d& vtV2) { return ( ( vtV1 + vtV2).IsSmall()) ; } //---------------------------------------------------------------------------- // Verifica che due vettori sono esattamente coincidenti (Zero error -> Exact) //---------------------------------------------------------------------------- inline bool AreOppositeVectorExact( const Vector3d& vtV1, const Vector3d& vtV2) { return ( ( vtV1 + vtV2).IsZero()) ; } //---------------------------------------------------------------------------- // 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) ; }