<P>递归法生成Koch曲线<BR><BR>function [z,A]=Koch(z,A,n); <BR>% 递归法生成Koch曲线 <BR>% Example: <BR>% [z,A]=Koch(0,pi/2,0); <BR>% 算法见: <BR>% http://graphics.shu.edu.cn/course/fractal/program/p3-4-1-2.htm <BR><BR>N=4; % 递归次数 <BR>len=400/3^n; <BR>hold on; <BR><BR>if n>=N <BR> plot([z,z+len*exp(i*A)]/i); <BR> z=z+len*exp(i*A); <BR>else <BR> [z,A]=Koch(z,A,n+1); <BR> A=A+pi/3; <BR> [z,A]=Koch(z,A,n+1); <BR> A=A-pi*2/3; <BR> [z,A]=Koch(z,A,n+1); <BR> A=A+pi/3; <BR> [z,A]=Koch(z,A,n+1); <BR>end <BR>axis on;axis equal <BR>% zz=xlim; <BR>% xlim([min(zz),mean(zz)])</P> |