aboutsummaryrefslogtreecommitdiff
path: root/py/data2.py
diff options
context:
space:
mode:
Diffstat (limited to 'py/data2.py')
-rw-r--r--py/data2.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/py/data2.py b/py/data2.py
index 505a79d..a073f4b 100644
--- a/py/data2.py
+++ b/py/data2.py
@@ -2,6 +2,7 @@
from scipy.spatial import Voronoi, voronoi_plot_2d, KDTree, distance
from enum import Enum
import matplotlib.pyplot as plt
+from matplotlib.path import Path
fancy = {'pits':'Artificial Pits', 'obstacles':'Artificial Obstacles',
'trails':'Trail Erasure'}
@@ -38,6 +39,9 @@ class Trial:
def plot(self, save=False):
vor = Voronoi([pit.loc for pit in self.pits])
voronoi_plot_2d(vor)
+ if self.method == 'obstacles':
+ for obstacle in self.fake:
+ plt.fill(*obstacle.unzip())
plt.xlabel('%s (dimension %dx%dcm)' % (fancy[self.method], self.size[0], self.size[1]))
if save:
plt.savefig('%s-%dx%d.png'%(self.method,self.size[0],self.size[1]),
@@ -53,6 +57,16 @@ class Trial:
class Obstacle:
def __init__(self, coords):
self.coords = coords
+ self.path = Path(coords)
+
+ def contains(self, point):
+ return self.path.contains_point(point)
+
+ def multicontains(self, points):
+ return self.path.contains_points(points)
+
+ def unzip(self):
+ return ([x[0] for x in self.coords],[x[1] for x in self.coords])
trials = [
Trial('trails', 1, 2, [24,24], [
@@ -135,8 +149,8 @@ trials = [
Pit((22,16),2,4),
], fake=[
Obstacle([(8,3),(1,7),(7,16)]),
- Obstacle([(18,1),(16,7),(21,4),(21,7)]),
- Obstacle([(17,15),(18,20),(23,19),(21,20)])
+ Obstacle([(18,1),(16,7),(21,7),(21,4)]),
+ Obstacle([(17,15),(18,20),(21,20),(23,19)])
]),
Trial('obstacles', 3, 0, [12,12], [
Pit((2,11),2,3),
@@ -149,6 +163,5 @@ trials = [
Pit((10,11),2,4),
Pit((6,3),3,5),
Pit((12,9),1,2),
- ], fake=[ Obstacle([(10,2),(11,9),(3,5),(3,8)]) ]),
+ ], fake=[ Obstacle([(10,2),(11,9),(3,8),(3,5)]) ]),
]
-