Scratchpad

If you are new to Scratchpad, and want full access as a Scratchpad editor, create an account!
If you already have an account, log in and have fun!!

READ MORE

Scratchpad
Register
Advertisement

Welcome to the The Koch Snowflake mini wiki at Scratchpad!

You can use the box below to create new pages for this mini-wiki. Make sure you type [[Category:The Koch Snowflake]] on the page before you save it to make it part of the The Koch Snowflake wiki (preload can be enabled to automate this task, by clicking this link and saving that page. Afterwards, you may need to purge this page, if you still see this message).



The Koch Snowflake is a fractal design described by Niels Fabian Helge von Koch, a Swedish mathematician, in the early twentieth century. As shown in the image below, the first iteration of the Koch Snowflake is an equilateral triangle.

Von Koch curve

The Koch Snowflake


As iterations progress through the Koch Snowflake, each segment in the triangle becomes a collection of four segments, each one-third the length of the segment that is being redrawn, with a 120° angle between the first and second segments, a 60° angle between the second and third segments, and a 120° angle between the third and fourth segments.

The Koch Snowflake and Recursion[]

The Koch Snowflake is an excellent visual example of recursion. If the segments that make up the Koch Snowflake are quantified in terms of their "pointiness," the first iteration of the snowflake would contain three segments that each have zero pointiness. In the second iteration, each side is a segment with one pointiness. As each one-pointiness segment is composed of four zero-pointiness segments, the recursion is evident. A five pointiness segment, for example, would be composed of four four-pointiness segments, each of which is composed of four three-pointiness segments, etc.. A reasonable base case in a recursive function designed to draw the Koch Snowflake, then, would be "if the pointiness equals zero, then just draw a regular line segment."

Drawing the Koch Snowflake with Java[]

The following Java code could draw the Koch Snowflake by calling drawSnowflake in some context. (Assume that there exist methods move, turnLeft and turnRight that are capable of drawing a line segment of a given length, turning left a given number of degrees, and turning right a given number of degrees, respectively.)

public void drawSnowflake(int pointiness, int sideLength) {

for (int j = 0; j < 3; j++) {
drawSegment(pointiness, sideLength);
turnRight(120);
}

}

public void drawSegment(int pointiness, int length) {

if (pointiness <= 0) move(length);
else {
drawSegment(pointiness - 1, length / 3);
turnLeft(60);
drawSegment(pointiness - 1, length / 3);
turnRight(120);
drawSegment(pointiness - 1, length / 3);
turnLeft(60);
drawSegment(pointiness - 1, length / 3);
}

}

External Links[]

Advertisement