Newer
Older
int LINE_POINTS = 1000000;
int CLOUD_POINTS = 1000;
double X_VALUE = 0.000001;
double RANDOMNESS = 0.01;
// 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");