- clear
- clc
- format compact
- %depth画图范围,radi为圆的半径,number对应各种半径的圆的数量 .
- depth=10
- radi=0.8:-0.1:0.1
- number=8:-1:1
- %产生画第一批最大的圆
- xxold=[]
- yyold=[]
- [x,y]=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)
- [x,y]=huacir(depth,number(i),radi(i),xxold,yyold,radrawn,numberdrawn)
- xxold=x
- yyold=y
- end
- %改变画圆的方法
- aa=[]
- for i=1:length(radi)
- aa=[aa ones(1,number(i))*radi(i)]
- end
- for i=1:length(aa)
- rectangle('position',[x(i)-aa(i),y(i)-aa(i),2*aa(i),2*aa(i)],'curvature',[1,1],'facecolor','b')
- axis([0,depth,0,depth])
- grid
- hold on
- end
复制代码- %开始画第一批最大的圆的方法
- function [xxnew,yynew]=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 [xxnew,yynew]=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=[aa ones(1,numberdrawn(I))*radrawn(I)]
- end
- aa=[aa ones(1,i-1)*radi]
- aa=aa+radi
- judg=distance-aa
- if all(judg>0)
- break
- end
- end
- end
- xxnew=xxold
- yynew=yyold
复制代码 本文内容由 funi 提供 |