Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Phi.h

Go to the documentation of this file.
00001 //===============================================
00002 //                Phi class
00003 //===============================================
00004 //
00005 //  A utility class to implement the cyclic nature
00006 //  of the phi variable in the range  -Pi <-> Pi
00007 // 
00008 //  The constructor uses a double number, which is reduced to
00009 //  the required range by repeated addition or subtraction of 2*Pi
00010 // 
00011 //  The operation in any arithmetic expression involving Phi and
00012 //  double numbers is understood in this way:
00013 //
00014 //  - wherever any double number is used then it is implicitly converted
00015 //    to a Phi as per the constructor. The operation then proceeds exactly
00016 //    as if the expression contained only 
00017 //
00018 // -  The user can add and subtract Phi objects and the result is automatically
00019 //  kept within a cyclic range.
00020 //
00021 //  -The difference between two PHI objects always represents the smallest 
00022 //   angle between them, signed according to whether this is clockwise
00023 //   or anticlockwise.
00024 //
00025 // - Most operations are convertable to use a double arguments where sensible. 
00026 //
00027 
00028 
00029 #ifndef ___phiutility__
00030 #define ___phiutility__
00031 
00032 #include <iostream>
00033 #include <cmath>
00034 
00039 class Phi {
00040   
00041  private:
00042   
00043   double m_val ;
00044   
00045   void reduce() {
00046     while( m_val >  UPPER_LIMIT )  { m_val -= RANGE ; }
00047     while( m_val <= LOWER_LIMIT  ) { m_val += RANGE ; }
00048   }
00049   
00050   
00051  public:
00052   
00053   static const double UPPER_LIMIT;
00054   static const double LOWER_LIMIT;
00055   static const double RANGE;
00056 
00057   // Constructors:
00058   Phi() { this->m_val = 0. ;  }
00059   Phi( const double init ) { this->m_val = init ; this->reduce() ; }
00060   Phi( Phi& src ) { this->m_val = src.m_val ; } 
00061   
00062   // Arithmetic:
00063   
00064   Phi& operator= ( const Phi& rhs ) { 
00065     this->m_val = rhs.m_val; 
00066     return *this; 
00067   }
00068   
00069   Phi& operator+= ( Phi& rhs )  { 
00070     this->m_val += rhs.m_val ; 
00071     reduce() ;
00072     return *this; 
00073   }
00074   
00075   Phi& operator-= ( Phi& in )  { 
00076     this->m_val -= in.m_val;
00077     reduce() ;
00078     return *this; 
00079   }
00080   
00081   Phi operator+ ( Phi& in )  const { 
00082     Phi result( this->m_val + in.m_val ) ;
00083     return result ;
00084   }
00085   
00086   Phi operator- ( Phi& in )  const { 
00087     Phi result(this->m_val - in.m_val ) ;
00088     return result ;
00089   }
00090   
00091   // boolean 
00092   bool operator< ( Phi& in ) const { return this->m_val < in.m_val ; }
00093   bool operator> ( Phi& in ) const { return this->m_val > in.m_val ; }
00094   
00095   // Conversions
00096   operator double() const { return this->m_val ; }
00097   
00098 };
00099 
00100 #endif
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 
00128 

Generated on Wed Jan 23 12:58:32 2002 for Atlfast by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001