【问题标题】:How to reduce the number of points in (x,y) data如何减少(x,y)数据中的点数
【发布时间】:2010-04-12 16:39:24
【问题描述】:

我有一组数据点:

(x1, y1) (x2, y2) (x3, y3) ... (xn, yn)

样本点的数量可以是数千个。我想用最少的(假设 30 个)点集尽可能准确地表示相同的曲线。我想捕捉尽可能多的拐点。但是,我对表示数据的允许点数有硬性限制。

实现相同目标的最佳算法是什么?有没有免费的软件库可以提供帮助?

PS:我已经尝试实现基于相对斜率差异的点消除,但这并不总能产生最佳的数据表示。

【问题讨论】:

  • @phild:我可以用 C、C++ 或 perl 中的任何一种对其进行编码。即使我找到其他语言的内容,我也会尝试将其移植到上述语言中。

标签: algorithm reduction


【解决方案1】:

您正在寻找一种插值算法。您的点集是数学意义上的函数(所有 x 值彼此分离),那么您可以进行多项式插值,或者它们是否分布在 2d 平面上,然后您可以使用贝塞尔曲线。

【讨论】:

    【解决方案2】:

    多年后迟到的答案:
    看看Douglas-Peucker algorithm

    function DouglasPeucker(PointList[], epsilon)
        // Find the point with the maximum distance
        dmax = 0
        index = 0
        end = length(PointList)
        for i = 2 to ( end - 1) {
            d = perpendicularDistance(PointList[i], Line(PointList[1], PointList[end])) 
            if ( d > dmax ) {
                index = i
                dmax = d
            }
        }
        // If max distance is greater than epsilon, recursively simplify
        if ( dmax > epsilon ) {
            // Recursive call
            recResults1[] = DouglasPeucker(PointList[1...index], epsilon)
            recResults2[] = DouglasPeucker(PointList[index...end], epsilon)
    
            // Build the result list
            ResultList[] = {recResults1[1...length(recResults1)-1], recResults2[1...length(recResults2)]}
        } else {
            ResultList[] = {PointList[1], PointList[end]}
        }
        // Return the result
        return ResultList[]
    end
    

    它经常用于简化 GPS 轨迹并减少航点的数量。作为准备,您可能需要对点进行排序以将相邻点存储在列表或数组中。

    【讨论】:

      【解决方案3】:

      这取决于您的曲线必须与每个点相交还是近似值。试试:

      1. 拿分
      2. 应用任何插值 (http://en.wikipedia.org/wiki/Polynomial_interpolation) 得到曲线方程
      3. 然后按特定步骤取采样点。

      【讨论】:

      • 这种方法的问题是,它会以固定的步长捕获点,而不考虑数据的变化。 yn 数据可能没有变化,但此方法将捕获那里的点。
      • 牛顿插值捕获任何点。在你有插值曲线方程后,你可以从中得到任何点。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2020-12-25
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      相关资源
      最近更新 更多