【分享】随机圆生成程序
本帖最后由 funi 于 2012-9-11 09:17 编辑clear
clc
format compact
%depth画图范围,radi为圆的半径,number对应各种半径的圆的数量 .
depth=10
radi=0.8:-0.1:0.1
number=8:-1:1
%产生画第一批最大的圆
xxold=[]
yyold=[]
=huacirstart(depth,number(1),radi(1),xxold,yyold)
xxold=x
yyold=y
%产生第二批圆及以后的圆
for i=2:length(radi)
radrawn=radi(1:i-1)
numberdrawn=number(1:i-1)
=huacir(depth,number(i),radi(i),xxold,yyold,radrawn,numberdrawn)
xxold=x
yyold=y
end
%改变画圆的方法
aa=[]
for i=1:length(radi)
aa=
end
for i=1:length(aa)
rectangle('position',,'curvature',,'facecolor','b')
axis()
grid
hold on
end%开始画第一批最大的圆的方法
function =huacirstart(depth,number,radi,xxold,yyold)
xxlen=length(xxold)
yylen=length(yyold)
xxold(xxlen+1)=radi+(depth-2*radi)*rand
yyold(yylen+1)=radi+(depth-2*radi)*rand
for i=2:number
while 1
xxold(xxlen+i)=radi+(depth-2*radi)*rand
yyold(yylen+i)=radi+(depth-2*radi)*rand
for j=1:xxlen+i-1
distance(j)=((xxold(xxlen+i)-xxold(j))^2+(yyold(yylen+i)-yyold(j))^2)^0.5
end
judg=distance-2*radi
if judg>0
break
end
end
end
xxnew=xxold
yynew=yyold%画第二批及以后的圆的方法
function =huacir(depth,number,radi,xxold,yyold,radrawn,numberdrawn)
xxlen=length(xxold)
yylen=length(yyold)
for i=1:number
while 1
xxold(xxlen+i)=radi+(depth-2*radi)*rand
yyold(yylen+i)=radi+(depth-2*radi)*rand
for j=1:xxlen+i-1
distance(j)=((xxold(xxlen+i)-xxold(j))^2+(yyold(yylen+i)-yyold(j))^2)^0.5
end
%产生对比的矩阵
aa=[]
for I=1:length(radrawn)
aa=
end
aa=
aa=aa+radi
judg=distance-aa
if all(judg>0)
break
end
end
end
xxnew=xxold
yynew=yyold
页:
[1]