Skip to content
Snippets Groups Projects
Commit b79b800b authored by philippe.montando's avatar philippe.montando :iphone:
Browse files

Je me sens seul

parent 8e229ad5
Branches
No related tags found
No related merge requests found
opti 0 → 100644
File added
#include "opti.h"
int LINE_POINTS = 1000000;
int CLOUD_POINTS = 1000;
double X_VALUE = 0.000001;
double RANDOMNESS = 0.01;
// droite
// aléatoire "autour" de la droite
//f(x) = pente *xj + ordonnee + rj (rj doit être petit)
// y(x) = ax+b;
int main (void){
// y(x)=ax+b
Point* line(double a, double b){
Point * points = (Point*)malloc(sizeof(Point)*LINE_POINTS);
double x = 0.0;
for(int i=0;i<LINE_POINTS-1;i++){
Point d;
d.x = x;
d.y = (a*x)+b;
points[i]=d;
//printf("%lf, %lf", d.x, d.y);
x+=X_VALUE;
}
return points;
}
double double_random(double min, double max)
{
double my_random;
my_random = (double)rand()/RAND_MAX*(max-min)+min;
//printf ( "%f\n", my_random);
return my_random;
}
Point* cloud(Point* a_line){
Point * my_cloud = (Point*)malloc(sizeof(Point)*CLOUD_POINTS);
for(int i=0;i<CLOUD_POINTS-1;i++){
Point chosen_point = a_line[rand()%LINE_POINTS-1];
double new_y = double_random(chosen_point.y-RANDOMNESS, chosen_point.y+RANDOMNESS);
my_cloud[i].x=chosen_point.x;
my_cloud[i].y=new_y;
printf("\nx = %f | y = %f\n", my_cloud[i].x,my_cloud[i].y);
}
return my_cloud;
}
int main (void){
srand ( time ( NULL));
Point* first_line = line(7.0, 5.5);
cloud(first_line);
printf("\ndone\n");
return 0;
}
\ No newline at end of file
#ifndef _OPTI_H_
#define _OPTI_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct Point Point;
struct Point
{
double x, y;
};
Point* line(double a, double b);
double double_random(double min, double max);
Point* cloud(Point* a_line);
#endif
\ No newline at end of file
opti.o 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment