-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolygon_generator.py
45 lines (37 loc) · 1.21 KB
/
polygon_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
import random
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as mpatches
np.random.seed(10)
def generate_increasing_random_numbers(n):
if n <= 0:
return []
numbers = [random.uniform(0, 2*np.pi) for i in range(n)]
numbers.sort()
return numbers
def polygon_generator(n):
random_numbers = generate_increasing_random_numbers(n)
vertices =[]
for i in range(n):
if random_numbers[i] > np.pi/2 and random_numbers[i] < 3*np.pi/2:
x = -5*np.random.random(1)[0]
y = x*np.tan(random_numbers[i])
else:
x = 5*np.random.random(1)[0]
y = x*np.tan(random_numbers[i])
vertices.append((x,y))
# print(vertices)
# y_coordinates = [y[1] for y in vertices]
# vertices.append(vertices[0])
# path = mpath.Path(vertices)
# patch = mpatches.PathPatch(path, lw=2,facecolor='white', alpha = 0.5)
# fig, ax = plt.subplots()
# ax.add_patch(patch)
# ax.set_xlim(-5,5)
# ax.set_ylim(min(y_coordinates)-0.5,max(y_coordinates)+0.5)
# plt.show()
return vertices
polygons = []
for i in range(4,200):
polygons.append(polygon_generator(i))