小编Mom*_*mow的帖子

Python:具有点数而不是epsilon的Ramer-Douglas-Peucker(RDP)算法

我想针对RDP算法修改以下python脚本,目的是不使用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 …
Run Code Online (Sandbox Code Playgroud)

python algorithm simplification computational-geometry

7
推荐指数
1
解决办法
2722
查看次数