Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. 2D random generator

2D random generator

Scheduled Pinned Locked Moved Algorithms
algorithmsquestionlounge
5 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vlasto77
    wrote on last edited by
    #1

    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

    C E Y R 4 Replies Last reply
    0
    • V vlasto77

      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

      C Offline
      C Offline
      cp9876
      wrote on last edited by
      #2

      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."

      1 Reply Last reply
      0
      • V vlasto77

        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

        E Offline
        E Offline
        El Corazon
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        • V vlasto77

          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

          Y Offline
          Y Offline
          yoaz
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • V vlasto77

            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

            R Offline
            R Offline
            Russell
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups