From: Beginner <partypingla@gmail.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webcrossing
Newsgroups: comp.soft-sys.matlab
Subject: Re: Function for Kochs snowflake
Message-ID: <ef4a06b.3@webcrossing.raydaftYaTP>
Date: Wed, 3 Jan 2007 03:43:45 -0500
References: <ef4a06b.-1@webcrossing.raydaftYaTP> <C9702DE39F9829662A697201A9D08175@in.webcrossing.raydaftYaTP> <ef4a06b.1@webcrossing.raydaftYaTP> <936b3$459b06cd$82a1bcd4$14312@news1.tudelft.nl>
Lines: 82
NNTP-Posting-Host: 82.183.138.198
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:385824



Maarten . Dank u!
I really appriciate your help.
/Ulrika

Okay Beginner, I will give you a start.

As you know, the Koch snowflake starts from a triangle. We will
parameterize
this by a relative angle variable and a unit length l:

angle = [0, -2/3*pi, -2/3*pi];
l = 1;

which can be visualized as follows:

x = zeros([length(angle)+1, 1]);
y = zeros([length(angle)+1, 1]);

x(1) = 0; y(1) = 0;
phi=0;
for i=1:length(angle);
    phi = phi+angle(i);
    x(i+1) = x(i) + l * cos(phi);
    y(i+1) = y(i) + l * sin(phi);
end

plot(x,y);
axis tight equal;

This displays the basic shape. The thing you need to realize now is
that the
generator for the Koch snowflake in terms of the relative angle is

phi -> [phi, pi/3,-2*pi/3, pi/3] for each phi in angle;
l -> l /3;

That is, at each refinement of the curve, the angle array increases
by a
factor 4 and the length parameter l shrinks by a factor 3.

Here is the entire code (iters is the number of times you would like
to
refine the shape - do not set iters very high as the length of angle
goes
as 4^iters !!!!):

angle = [0, -2/3*pi, -2/3*pi];
l = 1;
iters=0;

for i=1:iters
    l = l/3;
    angle1 = zeros([4*length(angle),1]);
    for j=1:length(angle)
      % insert the Koch generator here
    end
    angle = angle1;
end

x = zeros([length(angle)+1, 1]);
y = zeros([length(angle)+1, 1]);

x(1) = 0; y(1) = 0;
phi=0;
for i=1:length(angle);
    phi = phi+angle(i);
    x(i+1) = x(i) + l * cos(phi);
    y(i+1) = y(i) + l * sin(phi);
end

plot(x,y);
axis tight equal;

You only need to add one line of code to make it work! Good luck,

Maarten

--
===================================================================
Maarten van Reeuwijk dept. of Multiscale Physics
Phd student Faculty of Applied Sciences
maarten.vanreeuwijk.net Delft University of Technology