简体   繁体   English

如何使用简单的高斯分布算法在平面上分布点?

[英]How do I do a simple Gaussian distribution algorithm to distribute points on a plane?

What I seek is to turn a grid into a somewhat "random" plane of tiles. 我想要的是将网格变成有点“随机”的瓷砖平面。

I tried just multiplying Math.random() individually with the width and height of the plane (in this case its 800 / 600). 我尝试仅将Math.random()分别乘以平面的宽度和高度(在本例中为800/600)。 The circles you see there are points that intersect each other and have been removed from the scene. 您所看到的圆圈中的点彼此相交,并且已从场景中删除。

As you can see, it looks very far from an "evenly distributed" field of points. 如您所见,它看起来与点的“均匀分布”域相去甚远。 There are large holes and just as bad, clusters of points can be seen. 有大洞,同样也可以看到点簇。

What I am looking for is a way to distribute these points better to have a minimum amount of clusters and holes. 我正在寻找一种更好地分布这些点的方法,以使簇和孔的数量最少。 Ideally, to have a value that is the minimum distance between any two points, while having the maximum number of points that can fit in the area. 理想情况下,具有的值是任意两点之间的最小距离,同时具有可容纳在该区域中的最大点数。 I am fine with approximations of all kinds, I just don't want to attempt to do a greedy distribution. 我可以接受各种近似值,但我只是不想尝试进行贪婪的分布。

Whatever ecma solution you give its fine, I can convert it to Actionscript. 无论您使用哪种ecma解决方案,都可以将其转换为Actionscript。

在此处输入图片说明

I have found a visual example. 我找到了一个直观的例子。 The left side is what I got and the right is what I aim for. 左边是我得到的,右边是我的目标。 在此处输入图片说明

You can try Loyds algorithm, ie centroidal weighted voronoi diagrams. 您可以尝试Loyds算法,即质心加权voronoi图。 Compute the vd and then the center of gravity of each cell. 计算vd,然后计算每个单元的重心。 Replace the old points and rinse and repeat: http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/ . 替换旧的点并冲洗并重复: http : //www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM