Matlab:如何在特定半径的圆上生成不均匀且不重叠的圆/矩形 [英] Matlab: how to generate non-uniform and non-overlap circle/rectangle in a circle with specific radius

查看:459
本文介绍了Matlab:如何在特定半径的圆上生成不均匀且不重叠的圆/矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在仿真中生成一系列点。



点密度为1 / 1000m ^ 3



这些点的形状就像真实的建筑物(圆形或矩形或其他形状)
为了达到现实,这些形状不应重叠。
问题是如何生成这些建筑物的中心点?



我尝试过此操作

  clusterNumber = round((pi * areaRadius ^ 2)/ 1000); 

半径= unifrnd(0,areaRadius,clusterNumber,1);
angle = unifrnd(-pi,pi,clusterNumber,1); i = 1的

:clusterNumber
Coordinate(i,1)= cos(angle(i))* radius(i); %x
坐标(i,2)= sin(angle(i))* radius(i); %y

结果显示为我所期望的...它没有用
当我使用 scatter 时,它显示了



因此,我的问题是如何在特定圆中生成非均匀且非重叠的圆或矩形。

解决方案

如果您不希望建筑物相交,则必须在随机位置创建建筑物之前检查与已创建建筑物的相交。



当然,如果您创建许多建筑物,则碰撞检测的成本很高。您可以使用高效的最近邻居搜索来加快搜索速度,例如使用



强制执行该标准也可能会影响您的算法:限制随机萌发的位置的数量,这样当没有更多的建筑物可以放置或找到合适的空间的可能性很小时,您就不会陷入无限循环。


I want to generate a series of points as building in simulation.

Points density is 1/1000m^3

The points have its shape just like the real buildings(circle or rectangle or something else) In order to reach the reality, these shapes should not be overlapped. The question is how to generate the center point of these 'buildings'?

I tried this

clusterNumber = round((pi*areaRadius^2)/1000); 

radius = unifrnd (0,areaRadius,clusterNumber,1);
angle = unifrnd (-pi,pi,clusterNumber,1);

for i=1:clusterNumber
Coordinate(i,1) = cos(angle(i))*radius(i); % x
Coordinate(i,2) = sin(angle(i))*radius(i); % y

and the result showed as what I expected... it did'nt work When I used scatter it showed

So, my question is how to generate non-uniform and non-overlap circles or rectangles in a specific circle.

解决方案

If you want your buildings not to intersect, you must check for intersections with already created buildings before creating one at your random position.

Of course, if you create many buildings, collision detection will be costly. You can speed it up with an efficient nearest neighbour search, for example with kd-trees or by creating a fine grid in the building space so that you have only a few neighbour cells to check.

Imposing the condition that buildings must not intersect will also alter your distribution. You will no longer have the marked clustering in the circle's centre. You still generate morre random positionsthere, but as your area gets more populated, most of them will be rejected.

Here's an example distribution:

Enforcing the criterion may also affect your algorithm: It might be a good idea to limit the number of randomly gerenated positions, so that you don't run into an infinite loop when no more buildings can be placed or when the probability to find a suitable space is very low.

这篇关于Matlab:如何在特定半径的圆上生成不均匀且不重叠的圆/矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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