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

WP_Math.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00016 
00017 #ifndef WP_MATH_H
00018 #define WP_MATH_H
00019 
00020 #include "WP_Def.h"
00021 
00022 namespace WPCG
00023 {
00042 class WP_Math
00043 {
00044 public:
00045         ~WP_Math(){};
00046 
00051         static WP_Math* getInstance()
00052         {       if (!_instance)
00053                         _instance = new WP_Math();
00054                 return _instance;
00055         }
00056 
00062         scalar degreeToRad(int angle) const
00063           {
00064             return ((scalar)angle) * DEGRAD;
00065           }
00066 
00072         scalar fDegreeToRad(scalar angle) const
00073         {
00074           return angle * DEGRAD;
00075         }
00076 
00082         int radToDegree(scalar rad) const
00083         {
00084           int result = (int)(round(rad * RADDEG));
00085   
00086           if (result < 0)
00087             {
00088               result %= 360;
00089               return result + 360;
00090             }
00091   
00092           if (result >= 360)
00093             {
00094               result %= 360;
00095               return result - 360;
00096             }
00097 
00098           return result % 360;
00099         }
00100 
00106         scalar fRadToDegree(scalar rad) const
00107         {
00108           return rad * RADDEG;
00109         }
00110 
00116         scalar round(scalar s) const
00117         {
00118           scalar f = (scalar)floor(s);
00119           if ((s - 0.5) < f)
00120             return f;
00121           return (scalar)ceil(s);
00122         }
00123 
00129         scalar getSin(int i) const 
00130           { 
00131             if (i < 0)
00132               {
00133                 i %= 360;
00134                 if (i < 0)
00135                   {
00136                     i = 360 + i ;
00137                   }
00138               }
00139             else
00140               {
00141                 i %= 360;
00142               }
00143             return aSin[i];
00144           };
00145 
00151         scalar getCos(int i) const 
00152           { 
00153             if (i < 0)
00154               {
00155                 i %= 360;
00156                 if (i < 0)
00157                   {
00158                     i = 360 + i;
00159                   }
00160               }
00161             else
00162               {
00163                 i %= 360;
00164               }
00165             return aCos[i];
00166           };
00167 
00168 private:
00169         WP_Math();
00170 
00174         scalar aSin[360];
00175 
00179         scalar aCos[360];
00180 
00184         static WP_Math* _instance;
00185 };      
00186 }
00187 #endif
00188 

Generated on Tue Jan 28 20:26:33 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002