필터 지우기
필터 지우기

Matlab: compute Moore curve help.

조회 수: 5 (최근 30일)
Lam Chun Ting
Lam Chun Ting 2012년 5월 18일
답변: Henning U. Voss 2023년 8월 1일
Compute the fractal curve based on the following L system
Moore curve, 4 steps
Axiom: XFX+F+XFX
Production rules:
Newx=-YF+XFX+FYNewy=+
XF-YFY-FX+
Constants: α= π/2; θ=π/2
The following is my answer for Moore curve.But I know it's not a right curve, Because the picture is not same as what I have seen on wikipedia. I really don't know where am I go wrong. May anyone help me to slove this please? Many thanks for helping!!!
function [X,Y]=Moore_curve(Lmax)
Axiom='XFX+F+XFX';
Newf='F';
Newx='-YF+XFX+FY';
Newy='+XF-YFY-FX+';
theta=pi/2;
alpha=pi/2;
p=[0;0];
p=Coord(p,Lmax,Axiom,Newf,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,Newf,Newx,Newy,alpha,theta)
Rule=Moore_syst(Lmax,Axiom,Newf,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/(2^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=Moore_syst(Lmax,Axiom,Newf,Newx,Newy,n,tmp)
if n<=Lmax
if n==1
tmp=Axiom;
end
M=length(tmp);
tmp1='';
for i=1:M
if tmp(i)=='F'
tmp1=strcat(tmp1,Newf);
end
if tmp(i)=='X'
tmp1=strcat(tmp1,Newx);
end
if tmp(i)=='Y'
tmp1=strcat(tmp1,Newy);
end
if not(tmp(i)=='F') &&not(tmp(i)=='X') &&not(tmp(i)=='Y')
tmp1=strcat(tmp1,tmp(i));
end
end
tmp=tmp1;
n=n+1;
tmp=Moore_syst(Lmax,Axiom,Newf,Newx,Newy,n,tmp);
end
z1=tmp;

답변 (1개)

Henning U. Voss
Henning U. Voss 2023년 8월 1일
At the end of line 4 is a minus sign missing. It's apparently already missing in the task description... That's it.
Hope it's not too late.

카테고리

Help CenterFile Exchange에서 Fractals에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by