Thread Subject: Function for Kochs snowflake

Subject: Function for Kochs snowflake

From: Beginner

Date: 2 Jan, 2007 15:33:02

Message: 1 of 9

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

Greetings

Subject: Function for Kochs snowflake

From: Ken Davis

Date: 2 Jan, 2007 16:33:34

Message: 2 of 9

"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
>
> Greetings

The MATLAB documentation has a part called Getting Started. I recommend that
you start there.


Subject: Function for Kochs snowflake

From: Beginner

Date: 2 Jan, 2007 17:13:19

Message: 3 of 9

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
>>
>> Greetings
>
> The MATLAB documentation has a part called Getting Started. I
> recommend that
> you start there.
>
>
>

Subject: Function for Kochs snowflake

From: Maarten van Reeuwijk

Date: 3 Jan, 2007 02:30:51

Message: 4 of 9

> 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

Subject: Function for Kochs snowflake

From: Beginner

Date: 3 Jan, 2007 03:43:45

Message: 5 of 9

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

Subject: Function for Kochs snowflake

From: Ulrika

Date: 3 Jan, 2007 08:49:31

Message: 6 of 9

YEEES
I´ve got it!

% insert the Koch generator here
angle1(4*j-3:4*j) = [angle(j), pi/3, -2*pi/3, pi/3];

Now is the diffucult part left. Try to understand what the diffrent
parts of the code does.

Maarten did a great job ealier but I need even more help... I need to
undestand the diffrent parts of the code. So if anyone can explain it
in a basic, basic way, you make my day!
/Ulrika

Beginner wrote:
>
>
> 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

Subject: Function for Kochs snowflake

From: Maarten van Reeuwijk

Date: 4 Jan, 2007 21:04:04

Message: 7 of 9

Ulrika wrote:

> YEEES
> I´ve got it!
>
> % insert the Koch generator here
> angle1(4*j-3:4*j) = [angle(j), pi/3, -2*pi/3, pi/3];

Yep that is it!

> Now is the diffucult part left. Try to understand what the diffrent
> parts of the code does.

It is not so difficult. All you have to do is make some sketches of the data
representations at different levels and an elementary trigonometrical
calculation to calculate the next point.

Hint: by removing the semicolons at the end you can see how the algorithm
works.

Good luck, Maarten

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

Subject: Function for Kochs snowflake

From: Ulrika

Date: 4 Jan, 2007 18:13:20

Message: 8 of 9

Maarten - the hint about the ; was vey useful.
Dank U
/Ulrika

Maarten van Reeuwijk wrote:
>
>
> Ulrika wrote:
>
>> YEEES
>> I´ve got it!
>>
>> % insert the Koch generator here
>> angle1(4*j-3:4*j) = [angle(j), pi/3, -2*pi/3, pi/3];
>
> Yep that is it!
>
>> Now is the diffucult part left. Try to understand what the
> diffrent
>> parts of the code does.
>
> It is not so difficult. All you have to do is make some sketches of
> the data
> representations at different levels and an elementary
> trigonometrical
> calculation to calculate the next point.
>
> Hint: by removing the semicolons at the end you can see how the
> algorithm
> works.
>
> Good luck, Maarten
>
> --
> ===================================================================
> Maarten van Reeuwijk dept. of Multiscale Physics
> Phd student Faculty of Applied Sciences
> maarten.vanreeuwijk.net Delft University of Technology
>

Subject: On another note

From: Mikkel Guldberg

Date: 16 Apr, 2008 07:01:25

Message: 9 of 9

Hi Guys

While we are on the subject i was wondering if anyone could point me to or give me a proof that the perimeter goes towards infinity and the "inside" of the star is finite...

Thanks in advance
Mikkel

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com