Koch snowflake in Haskell.

techguy101

n00b
Joined
Jan 14, 2009
Messages
62
Hi Guys,

I'm currently failing at a college assignment where I have to draw a koch snowflake.

I must write a function in Haskell that will take an integer as a parameter to indicate which iteration to draw to.

I can draw the first triangle in the center of a screen. My problem is the trigonometry involved in finding the points for each new triangle that is realtive to the existing triangle. i.e. point E,D,F in the below triangle..
triangle.GIF


I'm all out on attempt at how to find these ponts, would anybody have any advice for me? I am going to work on a few attempts and post them shortly to show my work..

Any suggestions?

Thanks,
 
I can think of a few ways, but without thinking too hard, not sure which is best... I'll do a parametric solution with minimal trig

You can represent a point on the any of the lines parametrically (x,y) = (1 - delta) (x0) + (delta) (x1):

For line BA, you can apply this to get:
x = (1-d)*4+d*6 = 2d + 4
y = (1-d)*3+d*6 = 3d + 3

To find the point 1/3 of the way up the line, use delta of 1/3 to find that D = (14/3,4)
Repeat for 2/3 to find E: (16/3, 5)

F is simply E - the length of FE on the x axis: (12/3,5)

That work?
 
Back
Top