1

I have the two points p1 and p2 and the line l (black). The line is made of 100+ internal points arranged in an array starting from p1 and ending in p2.

enter image description here

Now, I would like to convert the curved line to a "straight" line like the red line on the above illustration. I am, however, a little unsure how to do this.

So far, my idea is to iterate the line with a fixed distance (e.g. take all points from start and 100 pixels forward), calculate the curve of the line, if it exceeds a threshold, make the straigt line change direction, then iterate the next part and so on. I'm not sure this would work as intended.

Another idea would to make a greedy algorith trying to minimize the distance between the black and red line. This could, however, result in small steps which I would like to avoid. The steps might be avoided by making turns costly.

Are there any algorithms about this particular problem, or how would you solve it?

MortenGR
  • 803
  • 1
  • 8
  • 22

1 Answers1

4

Search for the phrase polygonal chain simplification and you'll see there is quite a literature on this topic. Here is one reference that could lead you to others:

Buzer, Lilian. "Optimal simplification of polygonal chains for subpixel-accurate rendering." Computational Geometry 42.1 (2009): 45-59.


      Fig17

Joseph O'Rourke
  • 4,346
  • 16
  • 25
  • Nice reference. "Polygonal chain simplification" is a new term to add to my vocabulary. Thank you! – duffymo Jan 25 '18 at 14:00
  • Hi Joseph. Thank you for the source. I've read the article and it seems quite advanced (but not impossible to implement). Right now I would prefer a more simple solution as I'm not that concerned with computing time. Can you recommended an algorith that would still yield near optimal result but more slow and simple? The keep every k'th point is a bit too simple :-). Maybe the Douglas-Peucker algorith? – MortenGR Jan 25 '18 at 14:40
  • @MortenGR: Yes, Douglas-Peucker is relatively easy to implement, and you could even find existing code for that. – Joseph O'Rourke Jan 25 '18 at 15:07