Generating random points with defined minimum and maximum distance

前端 未结 4 1689
我在风中等你
我在风中等你 2020-12-11 06:34

I need algorithm ideas for generating points in 2D space with defined minimum and maximum possible distances between points.

Bassicaly, i want to find a good way to

4条回答
  •  臣服心动
    2020-12-11 07:00

    You could use a 2D regular grid of Points (P0,P1,P2,P3,...,P(m*n), when m is width and n is height of this grid )

    Each point is associated with 1) a boolean saying wether this grid point was used or not and 2) a 'shift' from this grid position to avoid too much regularity. (or you can put the point+shift coordinates in your grid allready)

    Then when you need a new point, just pick a random point of your grid which was not used, state this point as 'used' and use the Point+shift in your game.

    Depending on n, m, width/height of your 2D space, and the number of points you're gonna use, this could be just fine.

提交回复
热议问题