MarSTDv2004: CMath.h Source File

MarSTDv2004

CMath.h

Go to the documentation of this file.
00001 #ifndef __cMATH_h__
00002 #define __cMATH_h__
00003 
00005 // MarSTD version 2004 - (c)2004 - Marcel Smit                      //
00006 //                                                                  //
00007 // [email protected]                                      //
00008 // [email protected]                                          //
00009 //                                                                  //
00010 // This code may not be used in a commercial product without my     //
00011 // permission. If you redistribute it, this message must remain     //
00012 // intact. If you use this code, some acknowledgement would be      //
00013 // appreciated. ;-)                                                 //
00015 
00017 
00018 
00019 
00020 // NOTE: Default angle type used throughout the librairy is radians.
00021 
00022 #include <math.h>
00023 #include <stdlib.h>
00024 
00025 //---------------------------------------------------------------------------
00026 // Complement incomplete math headers.
00027 //---------------------------------------------------------------------------
00028 
00029 #if !defined(M_PI)
00030     #if defined(PI)
00031         #define M_PI PI
00032     #else
00033         #define M_PI 3.14159265358979323846             
00034     #endif
00035 #endif
00036 
00037 //---------------------------------------------------------------------------
00038 // Angle conversions.
00039 //---------------------------------------------------------------------------
00040 
00041 #define RAD2DEG(_x) ( (_x) / M_PI  * 180.0 )    
00042 #define RAD2BIN(_x) ( (_x) / M_PI  * 128.0 )    
00043 #define DEG2RAD(_x) ( (_x) / 180.0 * M_PI  )    
00044 #define DEG2BIN(_x) ( (_x) / 180.0 * 128.0 )    
00045 #define BIN2RAD(_x) ( (_x) / 128.0 * M_PI  )    
00046 #define BIN2DEG(_x) ( (_x) / 128.0 * 180.0 )    
00047 
00048 //---------------------------------------------------------------------------
00049 // Trig.
00050 //---------------------------------------------------------------------------
00051 
00057 static inline float dxdy2rad(float dx, float dy)
00058 {
00059 
00060         if (dy == 0.0)
00061     {
00062                 if (dx < 0.0)
00063                         return 180.0;
00064                 else
00065                         return 0.0;                     
00066         }
00067         
00068         float dxdy = dx/dy;
00069         float angle = acos(dxdy);
00070         
00071         if (dy < 0.0)
00072                 angle = 2.0*M_PI-angle;
00073                 
00074         return angle;                   
00075         
00076 }
00077 
00078 //---------------------------------------------------------------------------
00079 
00080 #endif

Generated on Tue Feb 8 21:59:02 2005 for MarSTDv2004 by  doxygen 1.4.1