M
Marc Dansereau
Hi all,
I wonder what is the most efficient way to generate random point on a line
defined by 2 double points (x0,y0) and (x1,y1).
Here is the pseudocode of my method :
for each point {
dx=x1-x0
dy=y1-y1
if dx != 0 {
m=dy/dx
b = y0-m*x0
x = (rand()%(int)dx)+x0
y = m* x + b
printf("(%f, %f) is a random point on the line", x, y);
} else {
x = x0
y = (rand() %(int)dy)+y0
}
}
There is probably a problem with the rounding of dy and dx ... There is
probably a better way to do this, but I can't figure which ?
Thank you
I wonder what is the most efficient way to generate random point on a line
defined by 2 double points (x0,y0) and (x1,y1).
Here is the pseudocode of my method :
for each point {
dx=x1-x0
dy=y1-y1
if dx != 0 {
m=dy/dx
b = y0-m*x0
x = (rand()%(int)dx)+x0
y = m* x + b
printf("(%f, %f) is a random point on the line", x, y);
} else {
x = x0
y = (rand() %(int)dy)+y0
}
}
There is probably a problem with the rounding of dy and dx ... There is
probably a better way to do this, but I can't figure which ?
Thank you