Prev: Problem
Next: Data Filtering Window
From: Kevin on 4 May 2010 16:38 I have managed to make a little progress with the code i posted earlier, but the image shown is not quite the gosper curve and maybe missign something, ro soem variables are not right. function [X,Y]=Gosper_curve(Lmax) Axiom='XF'; Newx='X+YF++YF-FX--FXFX-YF+'; Newy='-FX+YFYF++YF+FX--FX-Y'; theta=pi/3; alpha=0; p=[0;0]; p=Coord(p,Lmax,Axiom,Newx,Newy,alpha,theta); M=size(p,2); X=p(1:1,1:M); Y=p(2:2,1:M); figure(1); plot(X,Y,'Color','k'); set(gca,'xtick',[],'ytick',[]); set(gca,'XColor','w','YColor','w'); function z=Coord(p,Lmax,Axiom,Newx,Newy,alpha,theta) Rule=Gosper_syst(Lmax,Axiom,Newx,Newy,1,''); M=length(Rule); for i=1:M Tmp=p(1:2,size(p,2):size(p,2)); if Rule(i)=='F' R=[cos(alpha);sin(alpha)]; R=R/(4^Lmax); Tmp=Tmp+R; p=cat(2,p,Tmp); end if Rule(i)=='+' alpha=alpha+theta; end if Rule(i)=='-' alpha=alpha-theta; end; end z=p; function z1=Gosper_syst(Lmax,Axiom,Newx,Newy,n,tmp); if n<=Lmax if n==1 tmp=Axiom; end M=length(tmp); tmp1=''; for i=1:M if tmp(i)=='X' tmp1=strcat(tmp1,Newx); end if tmp(i)=='Y' tmp1=strcat(tmp1,Newy); end if not(tmp(i)=='F') ¬(tmp(i)=='X') ¬(tmp(i)=='Y') tmp1=strcat(tmp1,tmp(i)); end end tmp=tmp1; n=n+1; tmp=Gosper_syst(Lmax,Axiom,Newx,Newy,n,tmp); end z1=tmp;
|
Pages: 1 Prev: Problem Next: Data Filtering Window |