function koch ( A, B, k ) % % plots a Koch curve between A and B, % using k levels of recursion % if k == 0 plot([A(1) B(1)],[A(2) B(2)],'-'); hold on; else L = (2*A + B)/3; % left point R = (A + 2*B)/3; % right point M = [0 1; -1 0]; % rotation matrix s = sqrt(3)/6; % scaling factor T = (A+B)/2 + s*(M*(A-B)')'; % top point koch(A,L,k-1); % left branch koch(L,T,k-1); % left mid branch koch(T,R,k-1); % right mid branch koch(R,B,k-1); % right branch end;