3
Ich möchte dieses folgende Python-Skript für RDP algorithm mit dem Ziel ändern, nicht mit Epsilon, sondern um die Anzahl der Punkte, die ich behalten möchte wählen beim Finale:Python: Ramer-Douglas-Peucker (RDP) Algorithmus mit der Anzahl der Punkte anstelle von Epsilon
class DPAlgorithm():
def distance(self, a, b):
return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
def point_line_distance(self, point, start, end):
if (start == end):
return self.distance(point, start)
else:
n = abs(
(end[0] - start[0]) * (start[1] - point[1]) - (start[0] - point[0]) * (end[1] - start[1])
)
d = sqrt(
(end[0] - start[0]) ** 2 + (end[1] - start[1]) ** 2
)
return n/d
def rdp(self, points, epsilon):
"""
Reduces a series of points to a simplified version that loses detail, but
maintains the general shape of the series.
"""
dmax = 0.0
index = 0
i=1
for i in range(1, len(points) - 1):
d = self.point_line_distance(points[i], points[0], points[-1])
if d > dmax :
index = i
dmax = d
if dmax >= epsilon :
results = self.rdp(points[:index+1], epsilon)[:-1] + self.rdp(points[index:], epsilon)
else:
results = [points[0], points[-1]]
return results
fand ich einen Java-Skript in diesem Sinne: https://gist.github.com/msbarry/9152218
Kennt jemand eine Version für Python 3.X?
Dank momow