【分享】不相交的随机大小的椭圆
此函数产生的椭圆通过调整长径比可以用来模拟纤维混凝土中的纤维,当然也可以模拟类似的其它材料。function myellipse% cheng wf 2007 6 11 19:51
close all
clear all
clc
%format compact
depth=60;
a=;b=;
number=;
x0=[];y0=[];xlat=[];ylon=[];
=myellipse_one(depth,a(1),b(1),number(1),x0,y0,xlat,ylon)
x0=x0new1;y0=y0new1;xlat=xlat1;ylon=ylon1;
for i=2:length(a)
=myellipse_rest(depth,a(i),b(i),number(i),x0,y0,xlat,ylon)
x0=x0new2;y0=y0new2;xlat=xlat2;ylon=ylon2;
end
%绘制椭圆图形
=size(xlat)
plot(xlat,ylon)
axis()function =myellipse_one(depth,a,b,number,x0,y0,xlat,ylon)
xxlen=length(x0);yylen=length(y0);
x0(xxlen+1)=a+(depth-2*a)*rand;
y0(yylen+1)=a+(depth-2*a)*rand;
ecc=axes2ecc(a,b);
=ellipse1(x0(xxlen+1),y0(yylen+1),,rand*180);
xlat=;ylon=;
for i=2:number
while 1
x0(xxlen+i)=a+(depth-2*a)*rand;
y0(yylen+i)=a+(depth-2*a)*rand;
=ellipse1(x0(xxlen+i),y0(yylen+i),,rand*180);
xlat=;ylon=;
for j=1:xxlen+i-1
in1=[];in2=[];
in1=inpolygon(xlat(:,xxlen+i),ylon(:,yylen+i),xlat(:,j),ylon(:,j))
in2=inpolygon(xlat(:,j),ylon(:,j),xlat(:,xxlen+i),ylon(:,yylen+i))
if all(in1==0)&&all(in2==0)
n_j=j;
if n_j==xxlen+i-1
N=1
break
end
continue
else
N=2;
xlat(:,xxlen+i)=[];ylon(:,xxlen+i)=[];x0(xxlen+i)=[];y0(yylen+i)=[];
break
end
end
if N==1
break
end
end
end
x0new=x0;y0new=y0;xlat=xlat;ylon=ylon;function =myellipse_rest(depth,a,b,number,x0,y0,xlat,ylon)
xxlen=length(x0);yylen=length(y0);
ecc=axes2ecc(a,b);N=0;
for i=1:number
while 1
x0(xxlen+i)=a+(depth-2*a)*rand;
y0(xxlen+i)=a+(depth-2*a)*rand;
=ellipse1(x0(xxlen+i),y0(xxlen+i),,rand*180);
xlat=;ylon=;
for j=1:xxlen+i-1
in1=[];in2=[];
in1=inpolygon(xlat(:,xxlen+i),ylon(:,xxlen+i),xlat(:,j),ylon(:,j));
in2=inpolygon(xlat(:,j),ylon(:,j),xlat(:,xxlen+i),ylon(:,yylen+i));
if all(in1==0)&&all(in2==0)
n_j=j;
if n_j==xxlen+i-1
N=1;
break
end
continue
else
N=2;
xlat(:,xxlen+i)=[];ylon(:,xxlen+i)=[];x0(xxlen+i)=[];y0(yylen+i)=[];
break
end
end
if N==1
break
end
end
end
x0new=x0;y0new=y0;xlat=xlat;ylon=ylon;
页:
[1]