3

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

Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
  • Why don't you just calculate an average for lets say 5 points, and only plot the average values? – Jan Jul 08 '13 at 09:35
  • @Jan: because if I have a big gap between two adjacents points, I don't want to draw only one point set to the average value. In this case I want to draw the two points. – Guillaume Paris Jul 08 '13 at 09:37
  • This isnt really a programming question. Try looking on Math Exchange for appropriate algorithms. – Brian O''Byrne Jul 08 '13 at 09:49
  • It depend a bit on the shape of the curve, but maybe you could create a formula for the curve using regression and only draw the points where the angle is changing. But it would be a little overkill imo. – Lennart Jul 08 '13 at 10:57

2 Answers2

3

You can use Douglas-Peucker algorithm to reduce number of points and save the curve shape. C# implementation can be found here

Mitya
  • 632
  • 5
  • 18
0

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;

            });
Rico-E
  • 1,806
  • 2
  • 28
  • 47
  • and how behavior a curve in which each points are separeted by each other with a value < at minimalValueDistance ? – Guillaume Paris Jul 08 '13 at 09:54
  • I think that you want to remove these points?!? Or don't I understand your question? You said, that you want to "[...] remove adjacent points which are too close of each other (in term of values[...])". And as the "too close" is very unspecific, I implemented a variable for this. So you can set it to a constant value, or calculate the value within your code. – Rico-E Jul 08 '13 at 09:59
  • for example take minimalValueDistance=1 , you can have a curve like that : 1,5,9,10,11,13,19,20 => wich become 1,5,9,10,13,19, but what happen if you have 1,2,3,4,5,6 ? – Guillaume Paris Jul 08 '13 at 10:31
  • 1
    This will result in the question of how to calculate the `minimalValueDistance`, won't it? I think that this is very difficult to anwser with so few Information. Because it depends on your list of values, on the range and binning of your graphics and so on. So I can only think about an anwser if you provide Information on: a) do you allow zooming in your graphics? b) does the range of the plot vary with the values, or ist it fixed? If it is fixed: to what value is it fixed? c) what is the binning? d) can you provide some exemplary code with exemplary values? – Rico-E Jul 08 '13 at 10:41
  • that's why I don't want to reinvent the wheel and ask for a famous algo – Guillaume Paris Jul 08 '13 at 12:20
  • I don't think, that it would be too hard, to make such an algorithm. (With all Infos provided). But of course you are right: if there is such an algorithm, you should take that. – Rico-E Jul 08 '13 at 13:19