Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (553 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
float chaos_scalar;
17

    
18
float gauss_noise(void)
19
{
20
    float x1, x2, w, y1, y2;
21

    
22
    srand( SEED );
23
    do 
24
    {
25
        x1 = 2.0 * rand()/RAND_MAX - 1.0;
26
        x2 = 2.0 * rand()/RAND_MAX - 1.0;
27
        w = x1 * x1 + x2 * x2;
28
    } while ( w >= 1.0 );
29
    w = sqrt( (-2.0 * log( w ) ) / w );
30
    return (x1 * w);
31
}
32

    
33

    
34