Boost logo

Geometry :

Subject: [ggl] Simplifying polygons with co-linear points
From: Simonson, Lucanus J (lucanus.j.simonson)
Date: 2011-10-13 03:30:56

> On 12-10-2011 15:50, John Swensen wrote:

>I should have gone and looked at the code before I responded earlier. This actually looks fairly easy to modify for my >needs. I think I will make another class (not sure what to call it because the mod definitely wouldn't merit adding my >name to the class/algorithm). I am going to run the standard Douglas-Peucker algorithm as it is now and then rotate >until the start point is not co-linear with the point in front and behind, then simplify again. This naive approach >will still be O (2*n*log(n) + n), if I computed right. O(n*log(n)) for the first simplify, O(n) for the maximum >possible number of rotations, and O(n*log(n)) for the second simplify. I don't think a full simplify is required the
>second time around, but it is the "easy" way to do it.

A simple alternative is to scan the polygon for the point with the max distance from the line segment that joins the two points on either side of it (including the wrap around case) and rotate the polygon so that point is first. It solves the original problem since a collinear point would never be chosen, but it also generalizes it because nearly collinear points will also not be chosen. It requires one pass instead of two of the Douglas-Peucker and it is built out of the same building blocks as Douglas-Peucker so should be simple to implement. We ought to be able modify the original DP implementation to work this way rather than creating a new interface because it is arguably still doing DP and not a new algorithm.


Geometry list run by mateusz at