I am trying to write a python script that performs the following computation:
Input: (1) List L: a list of some 2-d points (2) List V: vertices of a triangle (3) Positive integer n: the order of Koch snowflake to be created from that triangle
Output: List O, a subset of L, that contains points from L that lies on or inside the region Kn, which is the region defined by the snowflake of order n.
My attempt: First, I thought I'd start by implementing a standard algorithm to draw a snowflake of a given order (and side length). Here's the code I wrote:
import turtle
from test import test
world= turtle.Screen()
t= turtle.Turtle()
def koch(t, order, size):
if order == 0:
t.forward(size)
else:
for angle in [60, -120, 60, 0]:
koch(t, order-1, size/3)
t.left(angle)
def koch_fractal(t, order, size, main_polygon_sides= 3):
for i in range(main_polygon_sides):
koch(t, order, size)
t.right(360/main_polygon_sides)
koch_fractal(t, 2, 100)
world.mainloop()
but since it doesn't say anything about the region of the snowflake, I could not move any further. Next, I thought the area of the snowflake might hold some insights, so I wrote this function:
from math import sqrt
koch_cache={}
def koch_fractal_area(n, side):
original_area = (sqrt(3)/4) * side**2 #Area of the original triangle
koch_cache[0] = original_area
for i in range(n+1):
if i not in koch_cache:
koch_cache[i] = koch_cache[i-1] + (3*4**(i-1))*(sqrt(3)/4) * (side/(3**i))**2
return koch_cache[n]
It implements an explicit formula to calculate the area. Again, it didn't seem to be related to what I was trying to do.
How can I approach this problem? Thanks in advance!