【发布时间】:2016-03-23 11:39:41
【问题描述】:
我需要随机生成固定数量的非重叠圆圈。我可以显示圆圈,在本例中为 20,使用这段代码随机定位,
for i =1:20
x=0 + (5+5)*rand(1)
y=0 + (5+5)*rand(1)
r=0.5
circle3(x,y,r)
hold on
end
但是圆圈重叠,我想避免这种情况。这是以前使用 Mathematica https://mathematica.stackexchange.com/questions/69649/generate-nonoverlapping-random-circles 的用户实现的,但我使用的是 MATLAB,我想坚持下去。
为了重现性,这是我用来画圆圈的函数 circle3
function h = circle3(x,y,r)
d = r*2;
px = x-r;
py = y-r;
h = rectangle('Position',[px py d d],'Curvature',[1,1]);
daspect([1,1,1])
谢谢。
【问题讨论】:
-
请显示您尝试检查重叠的内容。
-
不一样,但让我想起了这一点:stackoverflow.com/q/7833534/97160
-
我认为您可以使用 Tiles into Squares 将您的区域切割成正方形,然后在其中填充圆圈
标签: matlab