Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/3D/Vector3D.cpp

Go to the documentation of this file.
00001 // Implementation: Vector 3D class 
00002 
00003 #ifndef __J2K__Vector3D_CPP__
00004 #define __J2K__Vector3D_CPP__
00005 
00006 #include <j2k/Fred/3d/Vector3D.hpp>
00007 
00008 #include <math.h>
00009 
00010 // Assignment
00011 inline const Vector3DH& Vector3DH::operator=( const Vector3DH& v ) {
00012   a = v.a;
00013   b = v.b;
00014   return *this;
00015 }
00016 
00017 // Angle vertical theta du vecteur ( par rapport au plans xoy ).
00018 inline realtype Vector3DH::angle_ver() {
00019   realtype n = norme();
00020   if ( n == 0 ) return 0;
00021   return (realtype)asin( compoz() / n );
00022 }
00023 
00024 // cos et sin de l'angle vertical theta du vecteur.
00025 void Vector3DH::cos_sinangle_ver ( realtype& cos_Theta, realtype& sin_Theta )
00026 {
00027  realtype n   = norme(),
00028           dx  = compox(),
00029           dy  = compoy(),
00030           nxy = (realtype) sqrt( dy*dy + dx*dx );
00031 
00032   if ( n == 0 ) {
00033     cos_Theta = sin_Theta = 0;
00034 
00035   } else {
00036    cos_Theta = nxy / n;
00037    sin_Theta = compoz() / n;
00038 
00039   }
00040 }
00041 
00042 // cos de l'angle vertical theta du vecteur.
00043 realtype Vector3DH::cosangle_ver() {
00044   realtype n   = norme(),
00045            dx  = compox(),
00046            dy  = compoy(),
00047            nxy = (realtype)sqrt( dy*dy + dx*dx );
00048 
00049   return ( (n == 0) ? 0 : (nxy / n) );
00050 }
00051 
00052 // sin de l'angle vertical theta du vecteur.
00053 inline realtype Vector3DH::sinangle_ver() {
00054   realtype n = norme();
00055   return ( (n == 0) ? 0 : (compoz() / n) );
00056 }
00057 
00058 // Angle horizontal du vecteur ( sur le plans xoy à partir de l'axe ox dans
00059 // le sens trigonometrique pour un repère direct ).
00060 realtype Vector3DH::angle_hor() {
00061   return (realtype)atan2( compoy(), compox() );
00062 }
00063 
00064 // cos et sin de l'angle horizontal phi du vecteur.
00065 // Nb - le cas particulier où la vecteur est vertical rend la projection sur
00066 //      le plans XOY égale à un point.  Dans ce cas,  il n'y à pas de calcul
00067 //      d'angle possible. On suppose donc phi=0;
00068 
00069 void Vector3DH::cos_sinangle_hor( realtype& cos_Phi, realtype& sin_Phi )
00070 {
00071   realtype n   = norme(),
00072            dx  = compox(),
00073            dy  = compoy(),
00074            nxy = (realtype)sqrt( dy*dy + dx*dx );
00075 
00076   if ( n == 0 ) {
00077     cos_Phi = sin_Phi = 0;
00078     return;
00079   }
00080 
00081   if ( nxy == 0 ) {
00082     cos_Phi = 1;
00083     sin_Phi = 0;
00084     return;
00085   }
00086 
00087   cos_Phi = dx / nxy;
00088   sin_Phi = dy / nxy;
00089 }
00090 
00091 // cos de l'angle horizontal phi du vecteur.
00092 realtype Vector3DH::cosangle_hor() {
00093   realtype n   = norme(),
00094            dx  = compox(),
00095            dy  = compoy(),
00096            nxy = (realtype)sqrt( dy*dy + dx*dx );
00097 
00098   if ( n == 0 ) return 0;
00099 
00100   if ( nxy == 0 ) return 1;
00101 
00102   return dx / nxy;
00103 }
00104 
00105 // sin de l'angle horizontal phi du vecteur.
00106 realtype Vector3DH::sinangle_hor() {
00107   realtype n   = norme(),
00108            dx  = compox(),
00109            dy  = compoy(),
00110            nxy = (realtype)sqrt( dy*dy + dx*dx );
00111 
00112   if ( n == 0  ||  nxy == 0 ) return 0;
00113 
00114   return dy / nxy;
00115 }
00116 
00117 //Norme du vecteur.
00118 realtype Vector3DH::norme() {
00119   realtype dx = compox(),
00120            dy = compoy(),
00121            dz = compoz();
00122 
00123   return (realtype) sqrt( dx*dx + dy*dy + dz*dz );
00124 }
00125 
00126 // Composante X du vecteur.
00127 inline realtype Vector3DH::compox() {
00128   return ( b.x - a.x );
00129 }
00130 
00131 // Composante Y du vecteur.
00132 inline realtype Vector3DH::compoy() {
00133   return ( b.y - a.y );
00134 }
00135 
00136 // Composante Z du vecteur.
00137 inline realtype Vector3DH::compoz() {
00138   return ( b.z - a.z );
00139 }
00140 
00141 // normalisation du vecteur.
00142 void Vector3DH::normalisation() {
00143   realtype n  = norme(),
00144            dx = compox() / n,
00145            dy = compoy() / n,
00146            dz = compoz() / n;
00147 
00148   b.x = a.x + dx;
00149   b.y = a.y + dy;
00150   b.z = a.z + dz;
00151 }
00152 
00153 // produit scalaire du vecteur par un autre vecteur.
00154 realtype Vector3DH::produit_scalaire( const Vector3DH& v ) {
00155   realtype tmp = compox() * v.compox() +
00156                  compoy() * v.compoy() +
00157                  compoz() * v.compoz();
00158   return tmp;
00159 }
00160 
00161 // produit vectoriel du vecteur par un autre vecteur.
00162 // Application à l'obtention du vecteur normal 1.
00163 void Vector3DH::vecteur_normal( const Vector3DH& v, Sommet3DH& result ) {
00164   realtype adx = compox(),
00165            ady = compoy(),
00166            adz = compoz(),
00167            bdx = v.compox(),
00168            bdy = v.compoy(),
00169            bdz = v.compoz();
00170 
00171   result.x = ady * bdz - adz* bdy;
00172   result.y = adz * bdx - adx* bdz;
00173   result.z = adx * bdy - ady* bdx;
00174 }
00175 
00176 // produit vectoriel du vecteur par un autre vecteur.
00177 // Application à l'obtention du vecteur normal 2.
00178 inline void Vector3DH::vecteur_normal( const Vector3DH& v, Vector3DH& result )
00179 {
00180   result.a = a;
00181   vecteur_normal(v, result.b);
00182 }
00183 
00184 istream& operator>>( istream& in, const Vector3DH& v ) {
00185   return in  >> (Sommet3D&)v.a >> (Sommet3D&)v.b;
00186 }
00187 
00188 ostream& operator<<( ostream& out, const Vector3DH& v ) {
00189   return out << (Sommet3D&)v.a << (Sommet3D&)v.b;
00190 }
00191 
00192 #endif

Generated on Sun Oct 14 18:46:08 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001