• Remix
  • Share
  • New Entry

on 20 Nov 2023
  • 14
  • 16
  • 0
  • 0
  • 1960
drawframe(1);
Write your drawframe function below
function drawframe(f1)
v=[0,0;1,0;1,1;0,1];
v=v*3;
f=[1,2,3,4];
fv.F=f;
fv.V=v;
index=linspace(15,75,48);
azi=index(f1);
n=4;
nn=3;
fv.V(3,:)=fv.V(2,:)+(fv.V(3,:)-fv.V(2,:))*nn;
fv.V(4,:)=fv.V(1,:)+(fv.V(4,:)-fv.V(1,:))*nn;
fv_out=fv;
fv_out.gF=[1,2];
fv_out.gV=fv.V(fv.F([3,4]),:);
fv_out=Fractal_Pythagorean(fv_out,azi,n,nn);
%plotPythagorean(fv_out)
plotPythagorean_ellipse(fv_out,3,1.1);
function fv_out=Fractal_Pythagorean(fv,azi,n,nn)
for i=1:n
f=[];
v=[];
gf=[];
gv=[];
for j= 1:size(fv.gF,1)
T=fv;
T.gF=fv.gF(1,:);
T.gV=fv.gV(fv.gF(j,:),:);
Tfv=Pythagorean_seed(T,azi,nn);
if j==1
f=[f;Tfv.F];
v=[v;Tfv.V];
gf=[gf;Tfv.gF];
gv=[gv;Tfv.gV];
else
f=[f;Tfv.F+size(v,1)];
v=[v;Tfv.V];
gf=[gf;Tfv.gF+size(gv,1)];
gv=[gv;Tfv.gV];
end
end
fv_out.F=[fv.F;f+size(fv.V,1)];
fv_out.V=[fv.V;v];
fv_out.gF=gf;
fv_out.gV=gv;
fv=fv_out;
end
end
function fv_out=Pythagorean_seed(fv,azi,nn)
%% 构建勾股树
% 初始化旋转矩阵
azi0=90;
%azi=45;
RM1=[cosd(azi0),-sind(azi0);sind(azi0),cosd(azi0)];
RM2=[cosd(-azi0),-sind(-azi0);sind(-azi0),cosd(-azi0)];
RM3=[cosd(azi),-sind(azi);sind(azi),cosd(azi)];
% %1构建勾股树的底部;
% p3=[-1,1]*fv.gV*RM1+[1,0]*fv.gV;
% p4=[1,-1]*fv.gV*RM2+[0,1]*fv.gV;
% fv_out.V=[fv.gV;p3;p4];
% fv_out.F=[1,2,4,3];
%2构建勾股树的左上部;
p5=[-1,1]*fv.gV*RM3*cosd(azi)+[1,0]*fv.gV;
fv_out.V=[fv.gV;p5];
%nn=randi([1,3],1,1);
p6=[-1,1]*fv_out.V([1,3],:)*RM1*nn+[1,0]*fv_out.V([1,3],:);
p7=[1,-1]*fv_out.V([1,3],:)*RM2*nn+[0,1]*fv_out.V([1,3],:);
fv_out.V=[fv_out.V;p6;p7];
fv_out.F=[1,3,5,4];
%3构建勾股树的右上部。
%nn=randi([1,3],1,1);
p8=[-1,1]*fv_out.V([3,2],:)*RM1*nn+[1,0]*fv_out.V([3,2],:);
p9=[1,-1]*fv_out.V([3,2],:)*RM2*nn+[0,1]*fv_out.V([3,2],:);
fv_out.V=[fv_out.V;p8;p9];
fv_out.F=[fv_out.F;[2,3,6,7]];
%% 更新可生长对
fv_out.gV=fv_out.V([4,5,6,7],:);
fv_out.gF=[[1,2];[3,4]];
end
function fv=plotPythagorean_ellipse(fv,m,nn)
n=log2(size(fv.F,1)+1);
color=jet(n);
%% 求圆心半径
for i=1:size(fv.F,1)
fv.center(i,:)=mean(fv.V(fv.F(i,:),:),1);
[fv.Legth(i,1),t]=max([norm(fv.V(fv.F(i,2),:)-fv.V(fv.F(i,3),:)),norm(fv.V(fv.F(i,1),:)-fv.V(fv.F(i,2),:))]/2*nn);
Tecc=axes2ecc(10,m);
fv.ecc(i,1)=Tecc;
if t==1
p2=fv.V(fv.F(i,2),:);
p3=fv.V(fv.F(i,3),:);
else
p2=fv.V(fv.F(i,1),:);
p3=fv.V(fv.F(i,2),:);
end
fv.azi(i,1)=atand((p3(2)-p2(2))/(p3(1)-p2(1)));
end
%%绘图
hold on;
for i=1:n
for j=2^(i-1):2^(i)-1
[elat,elon] = ellipse1(fv.center(j,1),fv.center(j,2),[fv.Legth(j,1) fv.ecc(j,1)],fv.azi(j,1));
fill(elat,elon,color(i,:));
end
end
axis equal off;
end
end
Animation
Remix Tree