Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / gauss.c @ 998

History | View | Annotate | Download (540 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
float chaos_scalar;
15
float gauss_noise( )
16
{
17

    
18
        srand( SEED );
19
        
20
        do 
21
        {
22
                x1 = 2.0 * rand()/RAND_MAX - 1.0;
23
        x2 = 2.0 * rand()/RAND_MAX - 1.0;
24
        w = x1 * x1 + x2 * x2;
25
    }
26
        while ( w >= 1.0 );
27

    
28
    w = sqrt( (-2.0 * M_LOG2E( w ) ) / w );
29
    y1 = x1 * w;
30
    y2 = x2 * w;
31
        return y1;
32
}
33

    
34

    
35