summaryrefslogtreecommitdiff
path: root/plot.py
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-08-26 22:46:06 +0200
committerAki <please@ignore.pl>2022-08-26 22:46:06 +0200
commitbeb3b7582ee8ceb0ea8af3e1747dbce2bf60bfb0 (patch)
treef6998a39495d5ff8bf290390989156b5dc23be43 /plot.py
parenta35565eb2ee1cccce726e912cd8a66c8126c0d8a (diff)
downloadszilagyi-beb3b7582ee8ceb0ea8af3e1747dbce2bf60bfb0.zip
szilagyi-beb3b7582ee8ceb0ea8af3e1747dbce2bf60bfb0.tar.gz
szilagyi-beb3b7582ee8ceb0ea8af3e1747dbce2bf60bfb0.tar.bz2
Implemented finding candidates for boundaries
Diffstat (limited to 'plot.py')
-rw-r--r--plot.py47
1 files changed, 43 insertions, 4 deletions
diff --git a/plot.py b/plot.py
index 1669c5a..6ba676e 100644
--- a/plot.py
+++ b/plot.py
@@ -1,6 +1,9 @@
import csv
+import math
+import operator
import os
import re
+from collections import deque
import matplotlib.pyplot as plot
@@ -21,11 +24,47 @@ def load(directory):
if match:
yield int(match.group(1)), os.path.join(directory, file)
- return [(x, _load(y)) for x, y in _files(directory)]
+ return [(x, _load(y)) for x, y in sorted(_files(directory), key=lambda x: x[0])]
-swis = load("dataset")
+def increment(x):
+ return x + 1
+
+
+def decrement(x):
+ return x - 1
+
-for index, data in swis:
- plot.plot([x[0] for x in data], [x[1] for x in data], label=index)
+def find_boundary_curves(swis, x, y):
+ segments = deque()
+ for index, data in swis:
+ width = data[-1][0] - data[0][0]
+ relative = x - data[0][0]
+ candidate = math.floor(relative / width * len(data)) + 1
+ condition = operator.lt if data[candidate][0] > x else operator.gt
+ step = decrement if data[candidate][0] > x else increment
+ j = candidate
+ i = candidate
+ while not condition(data[i][0], x):
+ j = i
+ i = step(i)
+ if i > j:
+ i, j = j, i
+ if data[i][1] > y and data[j][1] > y:
+ segments.append((index, data, i, j))
+ break
+ if data[i][1] < y and data[j][1] < y:
+ if segments:
+ segments.popleft()
+ segments.append((index, data, i, j))
+ return segments
+
+
+swis = load("dataset")
+x = 16.61
+y = 8600
+segments = find_boundary_curves(swis, x, y)
+plot.plot([x], [y], "rx")
+for index, data, i, j in segments:
+ plot.plot([x[0] for x in data], [x[1] for x in data], ".")
plot.show()