简体   繁体   English

Matlab:如何在特定半径的圆上生成不均匀且不重叠的圆/矩形

[英]Matlab: how to generate non-uniform and non-overlap circle/rectangle in a circle with specific radius

I want to generate a series of points as building in simulation. 我想在模拟中生成一系列点。

Points density is 1/1000m^3 点密度为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 结果显示出我所期望的...它不起作用当我使用scatter显示时 模拟图像

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. 您可以通过高效的最近邻居搜索(例如,使用kd树)或通过在建筑空间中创建精细网格来加快搜索速度,从而仅检查几个邻居单元格。

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. 您仍然可以在此处生成morre随机位置,但是随着您所在区域的人口增加,大多数将被拒绝。

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. 强制执行该标准可能还会影响您的算法:最好限制随机生成的位置数,这样一来,当不再放置建筑物或找到合适建筑物的可能性时,您就不会陷入无限循环空间很小。

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

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