Kohn曲線

相比基本的科赫曲線,加入了角度的修改


function draw_Kohn_Curve(P1, P2, N, options)

% P1,P2是線段的始末兩點(必須是1*2的向量),N是遞歸層數
% options(1):線段寬度
% options(2):旋轉角度
% options(3:5):線段顏色
% 分支會往向量 P1P2 的逆時針方向凸

default_options = [3 pi/3 0 1 0];
if nargin == 3
    options = default_options;
end
LineWidth = options(1);
theta = options(2);
Color = options(3:5);

A = [cos(theta) sin(theta); -sin(theta) cos(theta) ];
Rate = 1 / (2 + 2*cos(theta));

if N == 1
    plot([P1(1) P2(1)], [P1(2) P2(2)], 'Color', Color, 'LineWidth', LineWidth, 'EraseMode', 'xor');
else
    mid = (P2 - P1) * Rate;
    L = P1 + mid;
    R = P2 - mid;
    New = L + mid * A;
    draw_Kohn_Curve(P1, L, N-1, options);
    draw_Kohn_Curve(L, New, N-1, options);
    draw_Kohn_Curve(New, R, N-1, options);
    draw_Kohn_Curve(R, P2, N-1, options);
end

端點處由於被畫了兩次,會有神奇的效果。

把EraseMode改爲none,就不會擦除了。

角度範圍是0~pi,角度大於pi/2時最好用xor模式,不然圖片比較紊亂。


科赫雪花,經典的的分形圖像,由正三角形展成。


function Koch_Snowflake(N)

% N 是迭代次數

fig = figure('NumberTitle','off','name','科赫雪花','MenuBar','none');
set(fig, 'color', [255 235 215]/255);

axis equal;
axis off; hold on;

draw_Kohn_Curve([1 0], [-1 0], N);
draw_Kohn_Curve([-1 0], [0 sqrt(3)], N);
draw_Kohn_Curve([0 sqrt(3)], [1 0], N);




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章