generate random points on a line
- From: Marc Dansereau <bouloumag@xxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 20:59:23 -0400
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
.
- Follow-Ups:
- Re: generate random points on a line
- From: Martin Ambuhl
- Re: generate random points on a line
- From: Rouben Rostamian
- Re: generate random points on a line
- Prev by Date: Re: How is strlen implemented?
- Next by Date: Re: how to find a number whether its a power of 2 or not
- Previous by thread: How to use dlopen()???
- Next by thread: Re: generate random points on a line
- Index(es):