-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
38 lines (29 loc) · 772 Bytes
/
utils.h
File metadata and controls
38 lines (29 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
float rad2deg(float rad)
{
return rad * (180.0 / PI);
}
float deg2rad(float deg)
{
return deg * (PI/ 180.0);
}
/*
* This is quite a computationally expensive routine,
* so you might want to consider not using it. But
* gaussian random numbers are really nice for a random
* walk behaviour :)
* From: http://www.taygeta.com/random/gaussian.html
*/
float randGaussian( float mean, float sd ) {
float x1, x2, w, y;
do {
// Adaptation here because arduino random() returns a long
x1 = random(0,2000) - 1000;
x1 *= 0.001;
x2 = random(0,2000) - 1000;
x2 *= 0.001;
w = (x1 * x1) + (x2 * x2);
} while( w >= 1.0 );
w = sqrt( (-2.0 * log( w ) )/w );
y = x1 * w;
return mean + y * sd;
}