Files
Include/EGkVector3d.h
T
2013-11-22 14:57:50 +00:00

182 lines
7.1 KiB
C++

//----------------------------------------------------------------------------
// 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
#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 :
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 ;
} ;
//----------------------------------------------------------------------------
// 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 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) ;
}