产生随机点具有确定的最小和最大距离 [英] Generating random points with defined minimum and maximum distance

查看:125
本文介绍了产生随机点具有确定的最小和最大距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于产生随机点具有确定的最小和最大距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆