00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00129
00130 #define Vector3_hpp
00131
00132 #include "FixedSizeMatrix.h"
00133 #include "Vector.h"
00134
00136 namespace OSCAR {
00137
00147 class Vector3 : public FixedSizeArray<Vector, 3>
00148 {
00149 public:
00150
00156 Vector3();
00157
00166 Vector3(double x, double y, double z);
00167
00174 explicit Vector3(double *array);
00175
00183 Vector3(const Vector& arg);
00184
00190 virtual ~Vector3();
00191
00198 double& X() {
00199 return element[0];
00200 }
00201
00208 const double& X() const {
00209 return element[0];
00210 }
00211
00218 double& Y() {
00219 return element[1];
00220 }
00221
00228 const double& Y() const {
00229 return element[1];
00230 }
00231
00238 double& Z() {
00239 return element[2];
00240 }
00241
00248 const double& Z() const {
00249 return element[2];
00250 }
00251
00258 double GetX() const {
00259 return element[0];
00260 }
00261
00268 double GetY() const {
00269 return element[1];
00270 }
00271
00278 double GetZ() const {
00279 return element[2];
00280 }
00281
00288 double Distance(const Vector3& vec) const {
00289 return sqrt(DistanceSqr(vec));
00290 }
00291
00298 double DistanceSqr(const Vector3& vec) const {
00299 return (element[0]-vec.at(0))*(element[0]-vec.at(0))+(element[1]-vec.at(1))*(element[1]-vec.at(1))+(element[2]-vec.at(2))*(element[2]-vec.at(2));
00300 }
00301
00308 void X(double x) {
00309 element[0] = x;
00310 }
00311
00318 void Y(double y) {
00319 element[1] = y;
00320 }
00321
00328 void Z(double z) {
00329 element[2] = z;
00330 }
00331
00332
00339 bool operator==(const Vector3& rhs) const
00340 {
00341 if(at(0) != rhs.at(0) || at(1) != rhs.at(1) || at(2) != rhs.at(2)){
00342 return false;
00343 }
00344 return true;
00345 }
00346
00354 Vector3 Cross(const Vector3& v2) const;
00355
00360 void Null(){
00361 at(0) = at(1) = at(2) = 0.0;
00362 }
00363
00371 double Dot(const Vector3& rhs) const
00372 {
00373 return at(0)*rhs.at(0) + at(1)*rhs.at(1)+ at(2)*rhs.at(2);
00374 }
00375
00382 Matrix Cross();
00383
00384 Vector3& operator=(const Vector3& rhs) {
00385 at(0) = rhs.at(0);
00386 at(1) = rhs.at(1);
00387 at(2) = rhs.at(2);
00388 return *this;
00389 }
00390
00391
00392 Vector3& operator=(const Vector& rhs) {
00393 if(rhs.GetSize() != GetSize()){
00394 DisplayError(arraySizeMismatch);
00395 exit(EXIT_FAILURE);
00396 }
00397 at(0) = rhs.at(0);
00398 at(1) = rhs.at(1);
00399 at(2) = rhs.at(2);
00400 return *this;
00401 }
00402
00403 Vector3& operator=(double rhs) {
00404 at(0) = at(1) = at(2) = rhs;
00405 return *this;
00406 }
00407
00408 Vector3& operator+=(const Vector3& rhs){
00409 at(0) += rhs.at(0);
00410 at(1) += rhs.at(1);
00411 at(2) += rhs.at(2);
00412 return *this;
00413 }
00414
00415 Vector3& operator-=(const Vector3& rhs){
00416 at(0) -= rhs.at(0);
00417 at(1) -= rhs.at(1);
00418 at(2) -= rhs.at(2);
00419 return *this;
00420 }
00421
00422 Vector3& operator*=(const Vector3& rhs){
00423 at(0) *= rhs.at(0);
00424 at(1) *= rhs.at(1);
00425 at(2) *= rhs.at(2);
00426 return *this;
00427 }
00428
00429 Vector3& operator+=(double rhs) {
00430 at(0) += rhs;
00431 at(1) += rhs;
00432 at(2) += rhs;
00433 return *this;
00434 }
00435
00436 Vector3& operator-=(double rhs) {
00437 at(0) -= rhs;
00438 at(1) -= rhs;
00439 at(2) -= rhs;
00440 return *this;
00441 }
00442
00443 Vector3& operator*=(double rhs) {
00444 at(0) *= rhs;
00445 at(1) *= rhs;
00446 at(2) *= rhs;
00447 return *this;
00448 }
00449
00450 Vector3& operator/=(double rhs) {
00451 if(rhs == 0.0){
00452 DisplayError(divideByZero);
00453 exit(EXIT_FAILURE);
00454 }
00455 at(0) /= rhs;
00456 at(1) /= rhs;
00457 at(2) /= rhs;
00458 return *this;
00459 }
00460
00461
00462 Vector3 operator+(const Vector3& rhs) const {
00463
00464 STATIC_THREAD_LOCAL(Vector3, p_result);
00465
00466
00467
00468 p_result->at(0) = this->at(0) + rhs.at(0);
00469 p_result->at(1) = this->at(1) + rhs.at(1);
00470 p_result->at(2) = this->at(2) + rhs.at(2);
00471
00472 return *p_result;
00473 }
00474
00481 void Add(const Vector3& rhs, Vector3& result) const {
00482
00483
00484
00485 result.at(0) = this->at(0) + rhs.at(0);
00486 result.at(1) = this->at(1) + rhs.at(1);
00487 result.at(2) = this->at(2) + rhs.at(2);
00488 }
00489
00490 Vector3 operator-(const Vector3& rhs) const {
00491
00492 STATIC_THREAD_LOCAL(Vector3, p_result);
00493
00494
00495
00496 p_result->at(0) = this->at(0) - rhs.at(0);
00497 p_result->at(1) = this->at(1) - rhs.at(1);
00498 p_result->at(2) = this->at(2) - rhs.at(2);
00499
00500 return *p_result;
00501 }
00502
00509 void Subtract(const Vector3& rhs, Vector3& result) const {
00510
00511
00512
00513 result.at(0) = this->at(0) - rhs.at(0);
00514 result.at(1) = this->at(1) - rhs.at(1);
00515 result.at(2) = this->at(2) - rhs.at(2);
00516 }
00517
00518 Vector3 operator*(const Vector3& rhs) const {
00519
00520 STATIC_THREAD_LOCAL(Vector3, p_result);
00521
00522
00523
00524
00525 p_result->at(0) = this->at(0) * rhs.at(0);
00526 p_result->at(1) = this->at(1) * rhs.at(1);
00527 p_result->at(2) = this->at(2) * rhs.at(2);
00528
00529 return *p_result;
00530 }
00531
00538 void Multiply(const Vector3& rhs, Vector3& result) const {
00539
00540
00541
00542 result.at(0) = this->at(0) * rhs.at(0);
00543 result.at(1) = this->at(1) * rhs.at(1);
00544 result.at(2) = this->at(2) * rhs.at(2);
00545 }
00546
00547 Vector3 operator*(double rhs) const {
00548
00549 STATIC_THREAD_LOCAL(Vector3, p_result);
00550
00551
00552
00553 p_result->at(0) = this->at(0) * rhs;
00554 p_result->at(1) = this->at(1) * rhs;
00555 p_result->at(2) = this->at(2) * rhs;
00556 return *p_result;
00557 }
00558
00565 void Multiply(double rhs, Vector3& result) const {
00566
00567
00568
00569 result.at(0) = this->at(0) * rhs;
00570 result.at(1) = this->at(1) * rhs;
00571 result.at(2) = this->at(2) * rhs;
00572 }
00573
00574 Vector3 operator+(double rhs) const {
00575
00576 STATIC_THREAD_LOCAL(Vector3, p_result);
00577
00578
00579
00580 p_result->at(0) = this->at(0) + rhs;
00581 p_result->at(1) = this->at(1) + rhs;
00582 p_result->at(2) = this->at(2) + rhs;
00583
00584 return *p_result;
00585 }
00586
00593 void Add(double rhs, Vector3& result) const {
00594
00595
00596
00597 result.at(0) = this->at(0) + rhs;
00598 result.at(1) = this->at(1) + rhs;
00599 result.at(2) = this->at(2) + rhs;
00600 }
00601
00602 Vector3 operator-(double rhs) const {
00603
00604 STATIC_THREAD_LOCAL(Vector3, p_result);
00605
00606
00607
00608 p_result->at(0) = this->at(0) - rhs;
00609 p_result->at(1) = this->at(1) - rhs;
00610 p_result->at(2) = this->at(2) - rhs;
00611
00612 return *p_result;
00613 }
00614
00621 void Subtract(double rhs, Vector3& result) const {
00622
00623
00624
00625 result.at(0) = this->at(0) - rhs;
00626 result.at(1) = this->at(1) - rhs;
00627 result.at(2) = this->at(2) - rhs;
00628 }
00629
00638 Vector3 operator/(double rhs) const {
00639
00640 STATIC_THREAD_LOCAL(Vector3, p_result);
00641
00642
00643
00644 if(rhs == 0.0){
00645 DisplayError(divideByZero);
00646 return Vector3();
00647 }
00648 p_result->at(0) = this->at(0)/ rhs;
00649 p_result->at(1) = this->at(1)/rhs;
00650 p_result->at(2) = this->at(2)/rhs;
00651 return *p_result;
00652 }
00653
00663 bool Divide(double rhs, Vector3& result) const {
00664
00665
00666
00667 if(rhs == 0.0){
00668 DisplayError(divideByZero);
00669 return false;
00670 }
00671 result.at(0) = this->at(0)/ rhs;
00672 result.at(1) = this->at(1)/rhs;
00673 result.at(2) = this->at(2)/rhs;
00674 return true;
00675 }
00676
00677 protected:
00678
00685 void init(const double* array = 0);
00686 };
00687
00688
00689 #include "Vector3.ipp"
00690
00691 typedef Vector3 Vector3D;
00692 }
00693 #endif // Vector3_hpp