我有一个方法可以返回数千个要显示在前端的笔形图部分中的点,它具有如下列表:

  List<int> pointsResult = GetMyPoints();


该图是一个非常小的图,我认为只能显示代表点。

仅获得100个值而不是数千个值的最佳方法是什么?

此int值可以非常规则,仅需要显示代表点。

该图如下所示:

c# - C#-获取代表点列表-LMLPHP

最佳答案

我发现了这个C#实现


  A C# Implementation of Douglas-Peucker Line Approximation Algorithm


public static List<Point> DouglasPeuckerReduction
    (List<Point> Points, Double Tolerance)
{
    if (Points == null || Points.Count < 3)
    return Points;

    Int32 firstPoint = 0;
    Int32 lastPoint = Points.Count - 1;
    List<Int32> pointIndexsToKeep = new List<Int32>();

    //Add the first and last index to the keepers
    pointIndexsToKeep.Add(firstPoint);
    pointIndexsToKeep.Add(lastPoint);

    //The first and the last point cannot be the same
    while (Points[firstPoint].Equals(Points[lastPoint]))
    {
        lastPoint--;
    }

    DouglasPeuckerReduction(Points, firstPoint, lastPoint,
    Tolerance, ref pointIndexsToKeep);

    List<Point> returnPoints = new List<Point>();
    pointIndexsToKeep.Sort();
    foreach (Int32 index in pointIndexsToKeep)
    {
        returnPoints.Add(Points[index]);
    }

    return returnPoints;
}

关于c# - C#-获取代表点列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35095623/

10-13 06:55