C# - 获取代表点列表
C# - Get a list of representative points
我有一个方法可以在前端的 dygraph 部分中显示 returns 数千个点,它由这样的列表提供:
List<int> pointsResult = GetMyPoints();
这张图很小,我觉得只能显示代表点。
仅获取例如 100 个值而不是数千个值的最佳方法是什么?
这个int值可以很规律,只显示代表点。
图形看起来像:
我找到了这个 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;
}
我有一个方法可以在前端的 dygraph 部分中显示 returns 数千个点,它由这样的列表提供:
List<int> pointsResult = GetMyPoints();
这张图很小,我觉得只能显示代表点。
仅获取例如 100 个值而不是数千个值的最佳方法是什么?
这个int值可以很规律,只显示代表点。
图形看起来像:
我找到了这个 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;
}