Polar.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifndef CLAM_Polar_hxx
00024 #define CLAM_Polar_hxx
00025 
00026 #include <iosfwd>
00027 #include "CLAM_Math.hxx"
00028 #include "TypeInfo.hxx"
00029 
00030 namespace CLAM
00031 {
00032 
00033         class Polar
00034         {
00035                 typedef TData T;
00036         private:
00037                 T mMag, mAng;
00038 
00039         public:
00040                 Polar(T mag = 0.0,T ang = 0.0)// constructor
00041                 {
00042                         mMag = mag;
00043                         mAng = ang;
00044                 };
00045 
00046                 const T Mag(void) const {return mMag;}; // accessor 
00047                 const T Ang(void) const {return mAng;}; // accessor 
00048 
00049                 void SetMag(const T& mag) { mMag = mag;}; // accesor
00050                 void SetAng(const T& ang) { mAng = ang;}; // accesor
00051 
00052                 // returns real part
00053                 const T Real (void) const
00054                 {
00055                         return fabs(mMag) * CLAM_cos(mAng);
00056                 }
00057 
00058                 // returns imaginary part
00059                 const T Imag (void) const
00060                 {
00061                         return fabs(mMag) * CLAM_sin(mAng); 
00062                 }
00063 
00064                 // friend function to handle cartesian coordinates
00065                 friend Polar ToComplex(const T& real, const T& imag)
00066                 {
00067                         return Polar (CLAM_sqrt (real*real + imag*imag),CLAM_atan2 (imag,real));
00068                 };
00069 
00070                 // ------   member operators ... ------
00071                 //  complex '=' operator  (float)
00072                 const Polar& operator = (const float mag)
00073                 {
00074                         mMag = mag;
00075                         mAng = 0;
00076                         return *this;
00077                 }
00078 
00079                 // complex '=' operator           
00080                 const Polar& operator = (const Polar& a) 
00081                 {
00082                         mMag = a.mMag;
00083                         mAng = a.mAng;
00084                         return *this;
00085 
00086                 }
00087 
00088                 // complex '+=' operator
00089                 const Polar& operator += (const Polar& a);
00090 
00091                 //  complex '-=' operator 
00092                 const Polar& operator -= (const Polar& a);
00093 
00094                 // polar '-' operator 
00095                 Polar operator - (const Polar& b) const;
00096 
00097                 // polar '+' operator 
00098                 Polar operator + (const Polar& b) const;
00099 
00100                 // complex '*' operator
00101                 Polar operator * (const Polar& b) const
00102                 {
00103                         Polar ret(mMag * b.mMag,mAng + b.mAng);
00104                         return ret;  
00105                 }
00106 
00107                 // complex '/' operator 
00108                 Polar operator / (const Polar& b) const
00109                 {
00110                         Polar ret(mMag / b.mMag,mAng - b.mAng);
00111                         return ret;  
00112                 }
00113 
00114                 // complex '==' operator
00115                 bool operator == (const Polar& b) const
00116                 {       
00117                         if ((mMag == b.mMag)&&(mAng == b.mAng)) return true;
00118                         else return false;
00119                 }
00120 
00121                 // polar '!=' operator
00122                 bool operator != (const Polar& b) const
00123                 {       
00124                         if ((mMag == b.mMag)&&(mAng == b.mAng)) return false;
00125                         else return true;
00126                 }
00127 
00128         };
00129 
00130         std::istream& operator >> (std::istream & stream, Polar & a);
00131         std::ostream& operator << (std::ostream & stream, const Polar & a);
00132         
00133         CLAM_TYPEINFOGROUP(BasicCTypeInfo, Polar);
00134 
00135 } // namespace CLAM
00136 
00137 #endif // CLAM_Polar_hxx
00138 
Generated by  doxygen 1.6.3