#include <marVector.h>
Public Member Functions | |
marVector (size_t s=3) | |
marVector (double *v, size_t s) | |
marVector (const marVector &v) | |
virtual | ~marVector () |
marVector & | operator= (const marVector &o) |
marVector & | operator= (double o) |
marVector & | operator= (double *o) |
operator double * () const | |
double & | operator() (size_t i) |
const double & | operator() (size_t i) const |
bool | operator== (const marVector &o) const |
bool | operator!= (const marVector &o) const |
marVector | operator+ (const marVector &o) |
marVector | operator+ (double o) |
marVector | operator+ (double *o) |
marVector & | operator+= (const marVector &o) |
marVector & | operator+= (double o) |
marVector & | operator+= (double *o) |
marVector | operator- (const marVector &o) |
marVector | operator- (double o) |
marVector | operator- (double *o) |
marVector & | operator-= (const marVector &o) |
marVector & | operator-= (double o) |
marVector & | operator-= (double *o) |
marVector | operator * (double o) |
marVector & | operator *= (double o) |
marVector | operator/ (double o) |
marVector & | operator/= (double o) |
double | dot (const marVector &o) |
double | dot (double *o) |
marVector | cross (const marVector &o) |
marVector | cross (double *o) |
int | scross (const marVector &o) |
int | scross (double *o) |
double | norm2 () |
marVector | normalize () |
int | snormalize () |
size_t | size () const |
Private Attributes | |
bool | shallowCopy |
size_t | _size |
double * | _data |
Friends | |
std::ostream & | operator<< (std::ostream &os, const marVector &v) |
Definition at line 7 of file marVector.h.
marVector::marVector | ( | size_t | s = 3 |
) |
Definition at line 12 of file marVector.cpp.
Referenced by normalize().
00013 :shallowCopy(false) 00014 { 00015 if (s!=0) 00016 { 00017 _data=new double[s]; 00018 _size=s; 00019 } 00020 else 00021 { 00022 _data=NULL; 00023 _size=0; 00024 assert(false); 00025 } 00026 }
marVector::marVector | ( | double * | v, | |
size_t | s | |||
) |
Definition at line 40 of file marVector.cpp.
00041 :shallowCopy(true) 00042 { 00043 if (s!=0) 00044 { 00045 _size=s; 00046 _data=v; 00047 // PS -> _data=new double[_size]; 00048 // PS -> for (int i=0;i<_size;i++) 00049 // PS -> { 00050 // PS -> _data[i]=v[i]; 00051 // PS -> } 00052 00053 } 00054 else 00055 { 00056 _data=NULL; 00057 _size=0; 00058 assert(false); 00059 } 00060 00061 }
marVector::marVector | ( | const marVector & | v | ) |
marVector::~marVector | ( | ) | [virtual] |
Definition at line 66 of file marVector.cpp.
References _data, and shallowCopy.
00067 { 00068 if (!shallowCopy) 00069 { 00070 delete _data; 00071 } 00072 else 00073 { 00074 _data=NULL; 00075 } 00076 }
Definition at line 115 of file marVector.cpp.
References _data, _size, and shallowCopy.
00116 { 00117 _size=o._size; 00118 if (!(_data==NULL)&&(!shallowCopy)) 00119 { 00120 delete _data; 00121 } 00122 shallowCopy=false; 00123 _data=new double[_size]; 00124 int i; 00125 for (i=0;i<_size;i++) 00126 { 00127 _data[i]=o._data[i]; 00128 } 00129 return (*this); 00130 }
marVector & marVector::operator= | ( | double | o | ) |
Definition at line 132 of file marVector.cpp.
References _data, _size, and shallowCopy.
00133 { 00134 if (_size!=0) 00135 { 00136 if (!(_data==NULL)&&(!shallowCopy)) 00137 { 00138 delete _data; 00139 } 00140 shallowCopy=false; 00141 _data=new double[_size]; 00142 int i; 00143 for (i=0;i<_size;i++) 00144 { 00145 _data[i]=o; 00146 } 00147 } 00148 else 00149 { 00150 assert(false); 00151 } 00152 return (*this); 00153 }
marVector & marVector::operator= | ( | double * | o | ) |
Definition at line 155 of file marVector.cpp.
References _data, _size, and shallowCopy.
00156 { 00157 if (_size!=0) 00158 { 00159 if (!(_data==NULL)&&(!shallowCopy)) 00160 { 00161 delete _data; 00162 } 00163 shallowCopy=false; 00164 _data=new double[_size]; 00165 int i; 00166 for (i=0;i<_size;i++) 00167 { 00168 _data[i]=o[i]; 00169 } 00170 } 00171 else 00172 { 00173 assert(false); 00174 } 00175 return (*this); 00176 }
marVector::operator double * | ( | ) | const |
double & marVector::operator() | ( | size_t | i | ) |
Definition at line 103 of file marVector.cpp.
References _data.
00104 { 00105 return(_data[i]); 00106 }
const double & marVector::operator() | ( | size_t | i | ) | const |
Definition at line 108 of file marVector.cpp.
References _data.
00109 { 00110 return(_data[i]); 00111 }
bool marVector::operator== | ( | const marVector & | o | ) | const |
bool marVector::operator!= | ( | const marVector & | o | ) | const |
Definition at line 204 of file marVector.cpp.
00205 { 00206 marVector result(*this); 00207 size_t s=result._size; 00208 00209 if ((o._size!=s) || (s==0)) 00210 { 00211 assert(false); 00212 } 00213 else 00214 { 00215 for (int i=0;i < s;i++) 00216 { 00217 result._data[i] +=o._data[i]; 00218 } 00219 } 00220 return result; 00221 }
marVector marVector::operator+ | ( | double | o | ) |
Definition at line 223 of file marVector.cpp.
00224 { 00225 marVector result(*this); 00226 size_t s=result._size; 00227 00228 if (s==0) 00229 { 00230 assert(false); 00231 } 00232 else 00233 { 00234 for (int i=0;i < s;i++) 00235 { 00236 result._data[i] +=o; 00237 } 00238 } 00239 return result; 00240 }
marVector marVector::operator+ | ( | double * | o | ) |
Definition at line 242 of file marVector.cpp.
00243 { 00244 marVector result(*this); 00245 size_t s=result._size; 00246 00247 if (s==0) 00248 { 00249 assert(false); 00250 } 00251 else 00252 { 00253 for (int i=0;i < s;i++) 00254 { 00255 result._data[i] +=o[i]; 00256 } 00257 } 00258 return result; 00259 }
marVector & marVector::operator+= | ( | double | o | ) |
marVector & marVector::operator+= | ( | double * | o | ) |
Definition at line 313 of file marVector.cpp.
00314 { 00315 marVector result(*this); 00316 size_t s=result._size; 00317 00318 if ((o._size !=s) || (s==0)) 00319 { 00320 assert(false); 00321 } 00322 else 00323 { 00324 for (int i=0;i < s;i++) 00325 { 00326 result._data[i] -=o._data[i]; 00327 } 00328 } 00329 return result; 00330 }
marVector marVector::operator- | ( | double | o | ) |
Definition at line 332 of file marVector.cpp.
00333 { 00334 marVector result(*this); 00335 size_t s=result._size; 00336 00337 if (s==0) 00338 { 00339 assert(false); 00340 } 00341 else 00342 { 00343 for (int i=0;i < s;i++) 00344 { 00345 result._data[i] -=o; 00346 } 00347 } 00348 return result; 00349 }
marVector marVector::operator- | ( | double * | o | ) |
Definition at line 351 of file marVector.cpp.
00352 { 00353 marVector result(*this); 00354 size_t s=result._size; 00355 00356 if (s==0) 00357 { 00358 assert(false); 00359 } 00360 else 00361 { 00362 for (int i=0;i < s;i++) 00363 { 00364 result._data[i] -=o[i]; 00365 } 00366 } 00367 return result; 00368 }
marVector & marVector::operator-= | ( | double | o | ) |
marVector & marVector::operator-= | ( | double * | o | ) |
marVector marVector::operator * | ( | double | o | ) |
Definition at line 422 of file marVector.cpp.
00423 { 00424 marVector result(*this); 00425 size_t s=result._size; 00426 00427 if (s==0) 00428 { 00429 assert(false); 00430 } 00431 else 00432 { 00433 for (int i=0;i < s;i++) 00434 { 00435 result._data[i]*=o; 00436 } 00437 } 00438 return result; 00439 }
marVector & marVector::operator *= | ( | double | o | ) |
marVector marVector::operator/ | ( | double | o | ) |
Definition at line 461 of file marVector.cpp.
00462 { 00463 marVector result(*this); 00464 size_t s=result._size; 00465 00466 if (s==0) 00467 { 00468 assert(false); 00469 } 00470 else 00471 { 00472 for (int i=0;i < s;i++) 00473 { 00474 result._data[i] /=o; 00475 } 00476 } 00477 return result; 00478 }
marVector & marVector::operator/= | ( | double | o | ) |
double marVector::dot | ( | const marVector & | o | ) |
Definition at line 503 of file marVector.cpp.
00504 { 00505 double result; 00506 if ((_size!=o._size) || (_size==0)) 00507 { 00508 assert(false); 00509 } 00510 else 00511 { 00512 result=0.0; 00513 for (int i=0;i<_size;i++) 00514 { 00515 result+=(_data[i]*o._data[i]); 00516 } 00517 } 00518 return result; 00519 }
double marVector::dot | ( | double * | o | ) |
Definition at line 521 of file marVector.cpp.
00522 { 00523 double result; 00524 if (_size==0) 00525 { 00526 assert(false); 00527 } 00528 else 00529 { 00530 result=0.0; 00531 for (int i=0;i<_size;i++) 00532 { 00533 result+=(_data[i]*o[i]); 00534 } 00535 } 00536 return result; 00537 }
Definition at line 541 of file marVector.cpp.
Referenced by scross().
00542 { 00543 marVector result(*this); 00544 if ((o._size!=_size) || (_size!=3)) 00545 { 00546 assert(false); 00547 } 00548 else 00549 { 00550 double S,s; 00551 00552 // 1st element 00553 S=_data[1]*o._data[2]; 00554 s=_data[2]*o._data[1]; 00555 result._data[0]=S - s; 00556 00557 // 2nd element 00558 S=_data[2]*o._data[0]; 00559 s=_data[0]*o._data[2]; 00560 result._data[1]=S - s; 00561 00562 // 3rd element 00563 S=_data[0]*o._data[1]; 00564 s=_data[1]*o._data[0]; 00565 result._data[2]=S - s; 00566 } 00567 return(result); 00568 }
marVector marVector::cross | ( | double * | o | ) |
Definition at line 570 of file marVector.cpp.
00571 { 00572 marVector result(*this); 00573 if (_size!=3) 00574 { 00575 assert(false); 00576 } 00577 else 00578 { 00579 double S,s; 00580 00581 // 1st element 00582 S=_data[1]*o[2]; 00583 s=_data[2]*o[1]; 00584 result._data[0]=S - s; 00585 00586 // 2nd element 00587 S=_data[2]*o[0]; 00588 s=_data[0]*o[2]; 00589 result._data[1]=S - s; 00590 00591 // 3rd element 00592 S=_data[0]*o[1]; 00593 s=_data[1]*o[0]; 00594 result._data[2]=S - s; 00595 } 00596 return(result); 00597 }
int marVector::scross | ( | const marVector & | o | ) |
int marVector::scross | ( | double * | o | ) |
double marVector::norm2 | ( | ) |
Definition at line 627 of file marVector.cpp.
Referenced by marAxis::getAxisLenght(), normalize(), and snormalize().
00630 { 00631 00632 double norme2=0.0; 00633 if (_size==0) 00634 { 00635 assert(false); 00636 } 00637 else 00638 { 00639 const double seuil1=pow( 2., 154. ),seuil2=1/seuil1; 00640 double n1=0; /* les sommes partielles */ 00641 double n2=0; 00642 double n3=0; 00643 double n4; 00644 int i; 00645 for ( i=0; i<_size; i++ ) 00646 { 00647 double x=_data[i]; /* x=abs(vecteur[i]) */ 00648 00649 if (x<0) 00650 { 00651 x=-x; 00652 } 00653 /* sommation par classe */ 00654 if ( x > seuil1 ) 00655 { 00656 x *=seuil2; 00657 n1 +=x*x; 00658 } 00659 else if ( x < seuil2 ) 00660 { 00661 x *=seuil1; 00662 n2 +=x*x; 00663 } 00664 else 00665 { 00666 n3 +=x*x; 00667 } 00668 } 00669 00670 n3=sqrt(n3); 00671 if (n1>0) 00672 { 00673 n4=seuil1 * sqrt(n1); 00674 } 00675 else 00676 { 00677 n4=seuil2 * sqrt(n2); 00678 } 00679 00680 // EED 00681 /* 00682 if (n3 < n4) 00683 { 00684 n3 /=n4; 00685 norme2=n4 * sqrt( 1 + n3*n3 ); 00686 } 00687 else 00688 { 00689 n4 /=n3; 00690 norme2=n3 * sqrt( 1 + n4*n4 ); 00691 } 00692 */ 00693 norme2=n3; 00694 } 00695 return norme2; 00696 }
marVector marVector::normalize | ( | ) |
Definition at line 700 of file marVector.cpp.
References marVector(), and norm2().
00701 { 00702 marVector result=marVector(*this); 00703 result *= (1/result.norm2()); 00704 return result; 00705 }
int marVector::snormalize | ( | ) |
Definition at line 707 of file marVector.cpp.
References norm2().
00708 { 00709 (*this)*=(1/this->norm2()); 00710 return(0); 00711 }// renvoie 0 si OK, 1 sinon
size_t marVector::size | ( | ) | const |
Definition at line 717 of file marVector.cpp.
References _size.
Referenced by marMatrix::operator *(), and operator<<().
00718 { 00719 return _size; 00720 }
std::ostream& operator<< | ( | std::ostream & | os, | |
const marVector & | v | |||
) | [friend] |
Definition at line 83 of file marVector.cpp.
00084 { 00085 int i; 00086 for(i=0;i < v.size();i++) 00087 { 00088 os << " " << v(i); 00089 } 00090 os <<"\n"; 00091 return(os); 00092 }
bool marVector::shallowCopy [private] |
size_t marVector::_size [private] |
Definition at line 93 of file marVector.h.
Referenced by cross(), dot(), marVector(), norm2(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator==(), scross(), and size().
double* marVector::_data [private] |
Definition at line 94 of file marVector.h.
Referenced by cross(), dot(), marVector(), norm2(), operator *(), operator *=(), operator double *(), operator()(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator==(), and ~marVector().