-
Notifications
You must be signed in to change notification settings - Fork 0
/
hatch_r.py
52 lines (39 loc) · 1.3 KB
/
hatch_r.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
46
47
48
49
50
51
52
# draw lines and find intersections
from cortexdraw import *
width = 100
height = 100
lines = []
fig, ax = plt.subplots(figsize=(11, 8.5), frameon=False)
patches = []
# gin up some random lines
lines = []
inters = []
for i in range(10):
lines.append([ [random.random() * 50, random.random() * 50], [random.random() * 50, random.random() * 50]])
patches.append(mpatches.Polygon(lines[i],closed=False, fill=None, color="black"))
# test them all for intersections
for i in range(len(lines)-1):
for j in range(i+1, len(lines)):
p1 = lines[i][0]
p2 = lines[i][1]
p3 = lines[j][0]
p4 = lines[j][1]
p = find_intersection(p1,p2,p3,p4)
if(p != None):
patches.append(mpatches.Circle(p, radius= 0.5, fill=None, color="green"))
inters.append(p)
for i in range(len(inters)-1):
for j in range(i+1, len(inters)):
patches.append(mpatches.Polygon([ inters[i],inters[j] ], closed=False, fill=None, color="red" ))
plt.grid(False)
plt.axis('off')
ax.set_aspect('equal')
x_bounds = [-5, 55]
y_bounds = [-5, 55]
ax.set_xlim(x_bounds)
ax.set_ylim(y_bounds)
collection = PatchCollection(patches, match_original=True)
ax.add_collection(collection)
plt.savefig('hatch.svg', bbox_inches = 'tight', pad_inches = 0)
plt.show()
vpypeout(['hatch.svg'])