展开全部
N=8;
x0=0;
y0=sqrt(3)/3;
dx=[0.5 -1 0.5];
dy=[-sqrt(3)/2 0 sqrt(3)/2];
for ii=2:N
a=[dx;dx/2-sqrt(3)/2*dy;dx/2+sqrt(3)/2*dy;dx]/3;
b=[dy;sqrt(3)/2*dx+dy/2;-sqrt(3)/2*dx+dy/2;dy]/3;
dx=a(:)';dy=b(:)';
end
x=cumsum([x0 dx]);
y=cumsum([y0 dy]);
h=plot(x0,y0);
axis equal;
axis([-0.5 0.5 -sqrt(3)/3 sqrt(3)/3]);
axis off;
for ii=1:N
set(h,'xdata',x(1:4^(N-ii):end));
set(h,'ydata',y(1:4^(N-ii):end));
title(['N=' num2str(ii)]);
drawnow;
pause(1);
end