Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!binfeed1.tudelft.nl!tudelft.nl!binfeed2.tudelft.nl!news1.tudelft.nl!not-for-mail
From: Maarten van Reeuwijk <maarten@remove_this_ws.tn.tudelft.nl>
Subject: Re: Function for Kochs snowflake
Newsgroups: comp.soft-sys.matlab
Date: Wed, 03 Jan 2007 02:30:51 +0100
References: <ef4a06b.-1@webcrossing.raydaftYaTP> <C9702DE39F9829662A697201A9D08175@in.webcrossing.raydaftYaTP> <ef4a06b.1@webcrossing.raydaftYaTP>
Organization: Delft University of Technology
User-Agent: KNode/0.9.2
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
Message-ID: <936b3$459b06cd$82a1bcd4$14312@news1.tudelft.nl>
X-Complaints-To: sysadmin@dto.tudelft.nl
Lines: 89
NNTP-Posting-Host: duttwtm.ws.tn.tudelft.nl (130.161.188.212)
NNTP-Posting-Date: Wed, 03 Jan 2007 02:28:45 +0100
X-Trace: 936b3459b06cd2704197114312
Xref: news.mathworks.com comp.soft-sys.matlab:385807



> Ken - that would be the best solution but I don´t have much time so
> I´d hope somebody could guide me.
> 
>  Ken Davis wrote:
>>
>>
>> "Beginner" <partypingla@gmail.com> wrote in message
>> news:ef4a06b.-1@webcrossing.raydaftYaTP...
>>> Hi,
>>> I'm new on using Matlab and I could need some help.
>>> I want to create a picture of Kochs snowflake but I don´t know
>> how.
>>> Unforturnatly I dont even got a clue where to begin.
>>> Can somebody help me
>>> If you got time I´d be grateful for stepbystep instructions

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