For my diploma, I want to make a component (if it doesn't work out, then a fig with it :), which, when drawing a line (I use WPF InkCanvas), would turn this line into a graph. Well, that is, straightened harder. Not good at math, so I don't know what I need to use for this. There is a set of points as input. What can be applied?

    2 answers 2

    For these purposes, there is already a ready-made Ramer-Douglas-Pecker algorithm. It seems to be used in vector graphics editors and cartography.

    And another list of algorithms that do the same:

    Then the resulting broken line can be turned into a beautiful curve by some kind of interpolation algorithm or use the points as reference points for constructing Bezier curves.

      Solution to the forehead: take the extreme points of the baseline, find equally distributed points of "kinks". We get the gaps conditions. Then, for each such interval, we look for points that fall into it and find the simplest arithmetic mean value for X and Y. We obtain the averaged values ​​on the sections, connect them with the points β€” the same graph, but less detailed. More points - more kinks - the picture is closer to the graph.

      • I did not quite understand about equally distributed break points. And is it possible to just take all the points through the step x, for example? - hinduCoder
      • Suppose you have the extreme points of the line (1.4) and (12, 24). You want to make a graph of 2 segments (i.e. average up to 3 points). For X, the limitations are 1–4, 4–8, 8–12, and for Y: 4–10, 10–16, 16–24, i.e. the first segment is replaced by a point falling into: {1 <x <= 4; 4 <y <= 10}, the second - {4 <x <= 8; 10 <y <= 16}, the third is {8 <x <= 12; 16 <y <= 24}. Averaging the values ​​of points falling into these intervals, we obtain 3 points that can be connected by a line graph. - free_ze
      • After a step - the same nonsense, you only need to either look for a multiple step, or enter some coefficients in the extreme interval ... In short, it is not scientific) - free_ze
      • In fact, you simply divide the graph into equal intervals (on each axis) and look for the middle point at each interval. And all the love. - free_ze
      • Well, in general, thanks, I still rethink - hinduCoder