Fibonacci弧线

先定义个function画圆弧

function arc(cen,R,ths,the)
    %cen为圆心坐标,R为边长,ths和the是起始和结束弧度
    theta=ths:-pi/50:the;
    x=R*cos(theta)+cen(1); 
    y=R*sin(theta)+cen(2); 
    plot(x,y,'-') 
    axis equal 
end

然后再来画Fibonacci弧线

function fibonacci(N)
%Fibonacci弧线
%N为迭代次数
if nargin==0
    N=5;
end
figure;
hold on;
%定义一些起始值,cen为圆心坐标
cen=[0,0];
R0=0;R1=1;R=1;
ths=0;
for i=1:N
    way = mod(i,4);
    switch way
        case 2
            cen(1)=cen(1)+R0;
            ths=1;
        case 3
            cen(2)=cen(2)-R0;
            ths=1/2;
        case 0
            cen(1)=cen(1)-R0;
            ths=0;
        case 1
            cen(2)=cen(2)+R0;
            ths=3/2;
    end
    R=R0+R1;
    R0=R1;R1=R;
    arc(cen,R,ths*pi,(ths-1/2)*pi);
end

测试下:

fibonacci(20);    %迭代20次

效果图:

fibonacci


文献:
http://baike.baidu.com/link?url=VNzjn1S_SHm0IpTIz-9k4zUIGfuMKqQQbtidp7SSJUU7BFMysKVCisvavKmOADzt

Leave a Reply

Your email address will not be published. Required fields are marked *