Java Koch Curves

39
Koch Curves The Walker School APCSA 1

Transcript of Java Koch Curves

Koch Curves

The Walker School

APCSA

1

2

Koch Curve

3

Depth 1

1 line segment

4

Depth 2

Contains 4 depth-1 curves(4 line segments)

5

Depth 3

Contains 4 depth-2 curves(16 line segments)

6

Depth 4

Contains 4 depth-3 curves(64 line segments)

7

Depth 5

Contains 4 depth-4 curves(256 line segments)

8

Pseudocode Algorithm

To make a Koch Curve:

• Draw a straight line if depth is zero; otherwise draw four smaller Koch Curves.

Koch Curve

Start with a line.

Line Segment Transformation

(x1,y1)

(x2,y2)

(x3,y3)

(x4,y4)

(x5,y5)

(x1,y1)

(x5,y5)

Segment Calculations

Calculating the Projection

ll

x = ½l

y = √3/2l

m2 + (½ l)2 = l2

m2 + ¼ l2 = l2

√m2 = √¾ l2

m = √3/2l * 1/3 = √3l/61/3 length of each iteration

Other Geometric Shapes?

Koch Snowflake

Start with a triangle.

Triangles Need 3 Calls to drawFractal()

Call the method drawFractal() for each side of the triangle. You need to establish variables for the x,y coordinates for the line on each side of the base triangle.

What aspects can you change?

Aspects

• Ratio Expression

• Shape of the Triangle

• Shape of the Base

– Square, Pentagon, Trapazoid

• Tessellations

• Color

Ratio Change to Projection

How does the projection change when you change the ratio?

Change Ratio through Expressions

Change Base to Koch Square

Start with a square.

Calculates the Tip of the Projection

How does the projection change when you change the ratio?

Square Needs 4 Calls to drawFractal()

How do we get curves that look like landmasses?

24

Fractals in Nature

Coastlines

25

Fractals in Nature

Coastlines

26

Fractals in Nature

Coastlines

27

Fractals in Nature

Coastlines

28

Fractals in Nature

Coastlines

29

Fractals in Nature

Coastlines

30

Fractals in Nature

Coastlines

Use the Random Class

Add Randomness to the Ration

Generates a random number between 3 and 10 for the denominator of the ratio.

3 Calls to the Method drawFractal()

6 Recursive Calls Approximates Landmass

Examples for Inspiration

Koch Snowflake Tessellations

You can tessellate Koch snowflakes to create pattern on a canvas.

Cesaro Curves

Cesaro curves are variations on a Koch snowflake.

Koch Curve(4/3n or log 4/log 3 = approx. 1.26)

https://www.behance.net/gallery/720515/Worlds-Largest-Fractal-Vectors

Contact

If you want the Java code for some of the basic Koch Curves you can contact me at:

Thomas Cooper

The Walker School

Marietta, GA 30062

Website: http://www.thewalkerschool.org

Email: [email protected]