产生随机点具有确定的最小和最大距离最小、距离、最大

2023-09-11 05:48:31 作者:是作业还是作孽

我需要算法的思想在二维空间中定义的最小和最大可能的距离点之间产生点。

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

Bassicaly,我想找到插入在充满点的二维空间中的点,以这样的方式,该点具有随机位置的好方法,但也超过MINIMUM_DISTANCE_NUM且小于MAXIMUM_DISTANCE_NUM距离最近的点。

Bassicaly, i want to find a good way to insert a point in a 2D space filled with points, in such manner that the point has random location, but is also more than MINIMUM_DISTANCE_NUM and less than MAXIMUM_DISTANCE_NUM away from nearest points.

我需要它的游戏,所以它应该是快速,而不是依赖于随机概率。

I need it for a game, so it should be fast, and not depending on random probability.

推荐答案

您可以使用点的二维规则网格(P0,P1,P2,P3,...,P(M * N),当m宽而n是该网格的高度)

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 )

每个点与1)一个布尔说阉使用该网格点或不和2)从这个发车位置'转移',以避免过多的规律有关。 (或者你可以把点+ SHIFT坐标网格媒体链接)

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)

然后,当你需要一个新的起点,随便挑一个随机点网格的这是不使用的,国家这一点是拿来主义,用在你的游戏点+ SHIFT。

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.

根据N,M,宽度/你的二维空间的高度,点你会使用的数量,这可能是就好了。

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