| 1 | #include <math.h> | 
|---|
| 2 | #include "sopnamsp.h" | 
|---|
| 3 | #include "unitvector.h" | 
|---|
| 4 | //***************************************************************************** | 
|---|
| 5 | //++ | 
|---|
| 6 | // Class        UnitVector | 
|---|
| 7 | // | 
|---|
| 8 | // include      unitvector.h vector3d.h math.h | 
|---|
| 9 | //-- | 
|---|
| 10 | //++ | 
|---|
| 11 | // | 
|---|
| 12 | // Links        Parents | 
|---|
| 13 | // | 
|---|
| 14 | //    Vector3d | 
|---|
| 15 | // | 
|---|
| 16 | //-- | 
|---|
| 17 | //++ | 
|---|
| 18 | // Titre        Constructors | 
|---|
| 19 | //-- | 
|---|
| 20 | //++ | 
|---|
| 21 | UnitVector::UnitVector() : Vector3d(1.,0.,0.) | 
|---|
| 22 | // | 
|---|
| 23 | //-- | 
|---|
| 24 | { | 
|---|
| 25 | } | 
|---|
| 26 | //++ | 
|---|
| 27 | UnitVector::UnitVector(double x, double y, double z) : Vector3d(x,y,z) | 
|---|
| 28 | // | 
|---|
| 29 | //-- | 
|---|
| 30 | { | 
|---|
| 31 | this->Normalize(); | 
|---|
| 32 | } | 
|---|
| 33 | //++ | 
|---|
| 34 | UnitVector::UnitVector(double theta, double phi) : Vector3d(theta,phi) | 
|---|
| 35 | // | 
|---|
| 36 | //-- | 
|---|
| 37 | { | 
|---|
| 38 | this->Normalize(); | 
|---|
| 39 | } | 
|---|
| 40 | //++ | 
|---|
| 41 | UnitVector::UnitVector(const Vector3d& v) : Vector3d(v) | 
|---|
| 42 | // | 
|---|
| 43 | //-- | 
|---|
| 44 | { | 
|---|
| 45 | this->Normalize(); | 
|---|
| 46 | } | 
|---|
| 47 | //++ | 
|---|
| 48 | // Titre        Public Method | 
|---|
| 49 | //-- | 
|---|
| 50 | //++ | 
|---|
| 51 | void UnitVector::Print(ostream& os) const | 
|---|
| 52 | // | 
|---|
| 53 | //-- | 
|---|
| 54 | { | 
|---|
| 55 | os << "UnitVector : (X,Y,Z)= (" << _x << ", " << _y << ", " << _z | 
|---|
| 56 | << ") Theta,Phi= " << _theta << ", " << _phi << "\n" | 
|---|
| 57 | << "norme =" << this->Norm() << endl; | 
|---|
| 58 | } | 
|---|
| 59 | //++ | 
|---|
| 60 | // Titre        Operators | 
|---|
| 61 | //-- | 
|---|
| 62 | //++ | 
|---|
| 63 | Vector3d& UnitVector::operator = (const Vector3d& v) | 
|---|
| 64 | // | 
|---|
| 65 | //-- | 
|---|
| 66 |  | 
|---|
| 67 | { | 
|---|
| 68 | Setxyz(v.X(),v.Y(),v.Z()); | 
|---|
| 69 | this->Normalize(); | 
|---|
| 70 | return *this; | 
|---|
| 71 | } | 
|---|
| 72 | //++ | 
|---|
| 73 | Vector3d& UnitVector::operator += (const Vector3d& v) | 
|---|
| 74 | // | 
|---|
| 75 | //-- | 
|---|
| 76 | { | 
|---|
| 77 | Setxyz(_x+v.X(),_y+v.Y(),_z+v.Z()); | 
|---|
| 78 | this->Normalize(); | 
|---|
| 79 | return *this; | 
|---|
| 80 | } | 
|---|
| 81 | //++ | 
|---|
| 82 | Vector3d& UnitVector::operator -= (const Vector3d& v) | 
|---|
| 83 | // | 
|---|
| 84 | //-- | 
|---|
| 85 | { | 
|---|
| 86 | Setxyz(_x-v.X(),_y-v.Y(),_z-v.Z()); | 
|---|
| 87 | this->Normalize(); | 
|---|
| 88 | return *this; | 
|---|
| 89 | } | 
|---|
| 90 | //++ | 
|---|
| 91 | Vector3d UnitVector::operator + (const Vector3d& v) const | 
|---|
| 92 | // | 
|---|
| 93 | //-- | 
|---|
| 94 | { | 
|---|
| 95 | return UnitVector(_x+v.X(),_y+v.Y(),_z+v.Z()); | 
|---|
| 96 | } | 
|---|
| 97 | //++ | 
|---|
| 98 | Vector3d UnitVector::operator - (const Vector3d& v) const | 
|---|
| 99 | // | 
|---|
| 100 | //-- | 
|---|
| 101 | { | 
|---|
| 102 | return UnitVector(_x-v.X(),_y-v.Y(),_z-v.Z()); | 
|---|
| 103 | } | 
|---|