2 * @(#)robomath.h 07/08/13
4 * Description : useful matemathic functions.
6 * License : GNU GPL v.2
15 #define POWER(x) ((x)*(x))
16 #define DEG2RAD(a) ((a)/180.0*M_PI)
17 #define RAD2DEG(a) ((a)*180.0/M_PI)
18 #define DEGREES(a) RAD2DEG(a)
19 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
20 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
22 /* used to analyze angles frequency */
28 #ifdef MATLAB_MEX_FILE
38 static inline double distance(double x1, double y1, double x2, double y2)
40 double x = x2-x1, y = y2-y1;
41 return sqrt(x*x + y*y);
44 static inline float urand()
46 return ((float)rand()/RAND_MAX);
49 double gaussian_random(void);
50 float exprand(float lambda);
51 void angles_freq_sort(struct angles_freq *angles, int count);
54 * Gaussian probability density function.
56 * @param val value we are looking for
57 * @param sigma standard deviation
59 static inline double evaluate_gaussian(double val, double sigma)
61 return (1.0/(sqrt(2.0*M_PI) * sigma) *
62 exp(-0.5 * (val*val / (sigma*sigma))));
66 * Evaluate two angles using gaussian.
68 * @param a1 angle 1 (rad)
69 * @param a2 angle 2 (rad)
70 * @param sigma standard deviation
72 static inline double evaluate_angles(double a1, double a2, double sigma)
76 /* normalize angles */
77 /* a1 = fmod(a1, 2*M_PI); */
78 /* a2 = fmod(a2, 2*M_PI); */
81 if (diff > M_PI) diff = 2*M_PI-diff;
83 return evaluate_gaussian(diff, sigma);
86 int cmpi(const void *a, const void *b);
87 int cmpd(const void *a, const void *b);
92 #endif /* __robomath__ */