matlab绘制不重叠圆,MATLAB 随机生成互不重叠的多个矩形 您所在的位置:网站首页 matlab绘制多条曲线不重合 matlab绘制不重叠圆,MATLAB 随机生成互不重叠的多个矩形

matlab绘制不重叠圆,MATLAB 随机生成互不重叠的多个矩形

2022-05-29 16:49| 来源: 网络整理| 查看: 265

ef6a1ce353bdc476d339f2e9f8bc976e.png

建立m文件draw_rectangle.m.

其中p生成矩形的个数

function draw_rectangle(p)

t = 1;

x = rand(1)*10;

y = rand(1)*10;

w = rand(1)*10;

h = rand(1)*10;

b =[x y w h];

rectangle(‘Position‘, b)

a{t} =b;

flag =1;

while flag ==1

x = rand(1)*10;

y = rand(1)*10;

w = rand(1)*10;

h = rand(1)*10;

b =[x y w h];

num = 0;

for j = 1:t

if ~rectint(b,a{j})

num = num +1;

end

end

if num == t

hold on;

rectangle(‘Position‘, b)

t = t+1;

a{t} =b;

end

if t == p

break

end

end

% t = 1;

% flag =1

%

% while flag ==1

% for i =1:p

% x = rand(1)*10;

% y = rand(1)*10;

% w = rand(1)*10;

% h = rand(1)*10;

% b =[x y w h];

% % rectangle(‘Position‘, b)

% a{i} =b;

% end

% num = 0;

% for i = 1:(p-1)

% for j =(i+1) :p

% if rectint(a{i},a{j})

% break

% else

% num = num +1;

% end

% end

% end

%

% if num == (p-1)*p/2

% for i = 1:p

% rectangle(‘Position‘, a{i})

% end

% flag = 0;

% end

% end

原文:http://www.cnblogs.com/huadongw/p/4603030.html



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有