src/util/MathUtils.h

Go to the documentation of this file.
00001 
00013 #ifndef MATHUTILS_H
00014 #define MATHUTILS_H
00015 
00016 #define _USE_MATH_DEFINES
00017 
00018 #include <cmath>
00019 #include <cassert>
00020 #include <time.h>
00021 #include <cstdlib>
00022 
00023 namespace green
00024 {
00029         inline
00030         double DegreesToRadians(double angle)
00031         {
00032                 using namespace std;
00033                 static const double over180 = 1.0 / 180.0;
00034                 return angle * M_PI * over180;
00035         }
00036         
00041         inline
00042         double RadiansToDegrees(double angle)
00043         {
00044                 using namespace std;
00045                 static const double my180_over_pi = 180.0 / M_PI;
00046                 return angle * my180_over_pi;
00047         }
00048         
00058         inline
00059         void GetVectorFromAngle(double angle, double& x, double& y, double length)
00060         {
00061                 double angleRad = DegreesToRadians(angle);
00062                 x = std::cos(angleRad) * length;
00063                 y = std::sin(angleRad) * length;
00064         }
00065         
00072         inline
00073         double randFloat(double min, double max)
00074         {
00075                 using namespace std;
00076                 if(max > min) {
00077                         double temp(max);
00078                         max = min;
00079                         min = temp;
00080                 }
00081                 double range = max - min;
00082                 double val = double(rand()) / double(RAND_MAX);
00083                 val *= range;
00084                 val += min; 
00085                 return val;
00086         }
00087         
00096         inline
00097         double DistanceBetween(double x1, double y1, double x2, double y2)
00098         {
00099                 double xdiff = x1 - x2;
00100                 double ydiff = y1 - y2;
00101                 return sqrt(xdiff * xdiff + ydiff * ydiff);
00102         }
00103 }
00104 
00105 #endif

Generated on Fri Apr 27 10:27:38 2007 for Green Engine by  doxygen 1.5.1