root / branches / simulator / projects / simulator / simulator / core / gauss.c @ 1114
History | View | Annotate | Download (652 Bytes)
1 |
/**
|
---|---|
2 |
* @file gauss.c
|
3 |
* @author Colony Project
|
4 |
*
|
5 |
* @brief Generates noise.
|
6 |
*
|
7 |
* Uses a Gaussian curve to approximate noise
|
8 |
* for robots in the simulator.
|
9 |
**/
|
10 |
|
11 |
|
12 |
#include <stdlib.h> |
13 |
#include <math.h> |
14 |
#include "gauss.h" |
15 |
|
16 |
double chaos_scalar;
|
17 |
|
18 |
void gauss_init(double chaos, unsigned int seed) |
19 |
{ |
20 |
chaos_scalar = chaos; |
21 |
srand(seed); |
22 |
} |
23 |
|
24 |
double gauss_noise(void) |
25 |
{ |
26 |
double x1, x2, w, y1, y2;
|
27 |
|
28 |
do
|
29 |
{ |
30 |
x1 = 2.0 * rand()/RAND_MAX - 1.0; |
31 |
x2 = 2.0 * rand()/RAND_MAX - 1.0; |
32 |
w = x1 * x1 + x2 * x2; |
33 |
} while ( w >= 1.0 ); |
34 |
w = sqrtf( (-2.0 * logf( w ) ) / w ); |
35 |
|
36 |
return chaos_scalar*x1*w;
|
37 |
} |
38 |
|
39 |
|
40 |
|