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