Comp212 Project #2: Koch Curves

General discussion of Koch Curves

[back to main project page]

In this project we will explore the use of recursion in creating a fractal patterns.  We will also encounter many design patterns, including the State, Composite, Visitor and the Abstract Factory patterns.  A true mutable, object oriented recursive list, LRStruct, will be used, and we will take advantage of its powerful capabilities.

Koch Curves

Fractals are an important area of scientific study as it has been found that fractal behavior manifests itself in nature in everything from broccoli to coastlines. 

A Koch curve is a fractal curve that can be constructed by taking a straight line segment and replacing it with a pattern of multiple line segments.    Then the line segments in that pattern are replaced by the same pattern.   Then line segments in that are replaced,... etc., etc., etc ...  

Successive iterations through the construction of a Koch curve.

Three Koch curves in a triangle makes a "Koch Snowflake":

Clearly, the generation of a Koch curve is a prime candidate for recursion.

Also, in looking at the the operational definition of a Koch curve, we can see that if we examine the curve between any two vertices (corners) of the curve (for a given, finite iteration level), there are two possible states:

  1. The curve is a single straight line between the two points.
  2. The curve is a collection of multiple straight lines between the two points.

In particular, for #2 above, the collection of straight lines is composed of the repeated line pattern of smaller Koch curves.   Thus we can create a recursive definition of a Koch curve:

A Koch curve between two points is:

  1. A straight line between the two points, or
  2. A pattern of intermediate points with a Koch curve between each successive pair of points.

A Koch curve contains a Koch curve which contains a Koch curve which contains....until finally, the curve is a straight line.   Does this sound familiar?   It should.

Notice as well that when the curve "grows" from one iteration to the next, that all the straight line segments transition from the base case Koch curve (straight line) to the non-base case Koch curve (a pattern of Koch curves) which is the series of straight lines.     The Koch object appears to change its class because it has new behaviors for the same methods and same property values.  "Dynamic reclassification" and all that...where have we seen that before?

We can see from above that a Koch "snowflake" is just 3 Koch curves arranged in a triangle. This leads us to the following definition of a Koch snowflake:

A Koch snowflake is a Koch curve whose base case consists of a set of Koch curves all in their base cases.

Notice that the above definition does not say that the base case of a snowflake is a set of straight lines. Why do you think this was done?

How does the above definition for a snowflake force the constructor for snowflake factories to be different from those of regular Koch curves?