[1] Re: Function for Kochs snowflake Date: Tue Jan 02 20:30:51 EST 2007 Lines: 89 e.g. see: http://mathworld.wolfram.com/KochSnowflake.html > 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" 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 --MORE--(91%)