Project

General

Profile

Revision 998

Added by Nico Paris about 15 years ago

View differences:

branches/simulator/projects/simulator/simulator/core/gauss.c
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

  
branches/simulator/projects/simulator/simulator/core/gaus.h
1
/**
2
 * @file gauss.h
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
#ifndef __GAUSS_H__
12
#define __GAUSS_H__
13

  
14
float gauss_noise( )
15

  
16

  
17
#endif
branches/simulator/projects/simulator/simulator/core/gauss.h
1
/**
2
 * @file gauss.h
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
#ifndef __GAUSS_H__
12
#define __GAUSS_H__
13
#define SEED 0
14

  
15
extern float chaos_scalar;
16
float gauss_noise(void);
17

  
18

  
19
#endif

Also available in: Unified diff