2D random generator
-
Hi, I need to generate random points inside of rectangle. But I need to have a certain distance between neighboring points. My input is rectangle and interval of distances . When I have a point P1, distance between P1 and any of closest points must be from . Is there any effective algorithm to do that? noIdea
-
Hi, I need to generate random points inside of rectangle. But I need to have a certain distance between neighboring points. My input is rectangle and interval of distances . When I have a point P1, distance between P1 and any of closest points must be from . Is there any effective algorithm to do that? noIdea
I don't understand your question. Are you saying that you need to generate random points located on a rectangular grid? If so, the co-ordinates are simply (nx*dx, ny*dy) where dx,dy are the grid spacings and nx and ny are integers. Simply generate random integers nx and ny. Alternatively, if the points can be randomly located, but each extra one must be >d from each other, then I can't think of a better way than generating them randomly and rejecting each new one if it is too close to the existing ones. You could speed up the searching by storing the generated points in some sort of grid pattern. Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
Hi, I need to generate random points inside of rectangle. But I need to have a certain distance between neighboring points. My input is rectangle and interval of distances . When I have a point P1, distance between P1 and any of closest points must be from . Is there any effective algorithm to do that? noIdea
I also don't quite understand what you are looking for, but if you are looking for a "uniform" distribution function you can use the boost libraries: http://www.boost.org/libs/random/random-distributions.html[^] if that is not what you are looking for, google on "random number distribution function" and see if the one you want pops up.
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
Hi, I need to generate random points inside of rectangle. But I need to have a certain distance between neighboring points. My input is rectangle and interval of distances . When I have a point P1, distance between P1 and any of closest points must be from . Is there any effective algorithm to do that? noIdea
noIdea77 wrote:
When I have a point P1, distance between P1 and any of closest points must be from
where from? the interval of distances ? is that a list of minimal distances alowed between points? can you use just a single distance? how many points ? (clearly if there is a minimal distance, you can have only so many points) the question sounds interesting, but I, for one, does not understand its terms completely.
there are no facts, only interpretations
-
Hi, I need to generate random points inside of rectangle. But I need to have a certain distance between neighboring points. My input is rectangle and interval of distances . When I have a point P1, distance between P1 and any of closest points must be from . Is there any effective algorithm to do that? noIdea
Simple way:
Assuming r = random number from 0 to 1 Xmin and Xmax = limit value of X Ymin and Ymax = limit value of Y Then generate X = Xmin + r * (Xmax - Xmin) [and Y = Ymin + r * (Ymax - Ymin) ] test if the distance from (X,Y) to the last valid (X,Y) generated is great than a the desired value, if not generate another point (X,Y)Complex way:
Use the polar coordinates (it will become a not uniform distribution) Start point is the last valid point (X,Y) found, now you need to generate the new point as a direction and a distance to move it. First generate a random angle uniformely from 0 to 360 degrees. Then generate a random distance uniformely from a minimal to a maximal distance: the minimal distance is the desired minimal distance from 2 consecutive points. The max distance is the simple calculation of the border of the rectangle moving with the found angle. (when the maximal apceptable distance is less then the minimal distance then this means that this angle is not valid, the rectangle border is too near,...so the solution is simply to generate another random angle value)
Russell