问题
I have a curve with a lot of points, resulting in a slowing down at GUI level. I would like to apply an algorithm which remove adjacent points which are too close of each other (in term of values, and so can be considered useless)
Is there any famous algorithm to do this ? I'm using C# and ZedGraph
回答1:
You can use Douglas-Peucker algorithm to reduce number of points and save the curve shape. C# implementation can be found here
回答2:
I'm not a professional, but I thought that you can do this without any famous algorithm. Here is what I thought (just a principle, as I don't know in which class you stored your Points):
Collection<float> ListOfValues = new Collection<float>();
float minimalValueDistance = 0.5f;
var listWithoutAdjacentPoints = ListOfValues.Where(x =>
{
int indexOfValue = ListOfValues.IndexOf(x);
// only considering the distance from the left
if (indexOfValue > 0 && Math.Abs(x - ListOfValues[indexOfValue - 1]) > minimalValueDistance)
return true;
else
return false;
});
来源:https://stackoverflow.com/questions/17523240/algorithm-to-smooth-curve