Background Information for Assignment 3

In this assignment, you can use the second Sierpinski gasket program as a template to draw the Koch snowflake. You can use

glBegin(GL_LINES); 
        glVertex2f(x1,y1); 
        glVertex2f(x2,y2);
        //etc.
glEnd();
Also you can use the GL_LINE_STRIP with all point involved.  That means you need to have all your points set to use this function.
To draw lines (instead of the points drawn for the gasket). Note: Points 1 and 2 are connected, 3 and 4 are connected, etc. If you list 2N points, then N lines will be drawn.

The basic recursive step in drawing a Koch snowflake is to replace an edge P1P5 with the four edges P1P2, P2P3, P3P4 and P4P5. Here's the idea:

This

becomes

You can construct the second drawing by replacing the middle third of the segment with the other two edges of an equilateral triangle for which it is the base. Hence the distances P2P4, P2P3, and P3P4 are identical.

You can determine the points P2, P3, and P4 using a little vector arithmetic. If we rotate the vector connecting P2 and P4 through 60 degrees, we get the vector from P2 to P3. We'll call the matrix which does this rotation R. Then

If your matrix multiplication or vector addition is rusty, I'll go over this during class. You may also want to go over appendices C.1 and C.2 in our text.

For example, suppose that P1 = (50,100) and P5 = (350,100). Then the vector P1P5 is (350-50,100-100) = (300,0). We have P2 = (50,100) + (1/3) (300,0) = (50,100) + (100,0) = (150,100) and P4 = (50,100) + (2/3) (300,0) = (50,100) + (200,0) = (250,100).

The matrix product R (P2P4) is calculated by first deriving P2P4 = (100,0), then R (P2P4) =

This must be added to  , which results in a point with x coordinate 200 and y coordinate 100 + 50(3)1/2.

Once you can replace an edge with four edges, you can do the same thing to each of the four edges. In pseudocode, you want to write a Flake function like this:

to Flake(n, P1, P5)

if n is 0, then simply connect P1 to P5

else Flake(n-1,P1,P2), Flake(n-1,P2,P3), Flake(n-1,P3,P4) and Flake(n-1,P4,P5)

where P2, P3 and P4 are determined as above.