如何减少 (x,y) 数据中的点数

发布于 2024-08-28 09:24:19 字数 248 浏览 4 评论 0原文

我有一组数据点:

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

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

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

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

I have a set of data points:

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

The number of sample points can be thousands. I want to represent the same curve as accurately as possible with minimal (lets suppose 30) set of points. I want to capture as many inflection points as possible. However, I have a hard limit on the number of allowed points to represent the data.

What is the best algorithm to achieve the same? Is there any free software library that can help?

PS: I have tried to implement relative slope difference based point elimination, but this does not always result in the best possible data representation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡淡の花香 2024-09-04 09:24:19

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

You are searching for an interpolation algorithm. Is your set of points a function in a mathematical sense (all x values are disjunct from each other) then you can go for a polynomial interpolation, or are they distributed over the 2d plane, then you could use bezier curves.

掩耳倾听 2024-09-04 09:24:19

多年后迟到的答复:
查看Douglas-Peucker 算法

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 轨迹并减少航点数量。作为准备,您可能需要对点进行排序,以将相邻点存储在列表或数组中。

Late answer after years:
Have a look at the 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

It is frequently used to simplify GPS tracks and reduce the number of waypoints. As a preparation, you may have to sort your points to store neighbour points adjacent in your list or array.

时间你老了 2024-09-04 09:24:19

这取决于您的曲线是否与每个点相交或者它是近似值。尝试:

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

it depends on must your curve intersect each point or it is approximation. Try:

  1. Take points
  2. Apply any interpolation (http://en.wikipedia.org/wiki/Polynomial_interpolation) to get equation of curve
  3. Then take sample points with specific step.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文