I am trying to smooth the edges of a polygon. This is for a mapping application that allows a user to zoom in and out. At a high zoom I don't need all the detail so I smooth the polygon to reduce the number of points. I simply iterate though all the points and remove any point that is within X distance from the last. Where X is appropriately 1 pixel on the resulting screen.
This seems to work great, except in a few cases. For example, if a user zooms in, I enlarge the vector, while loading the detail asynchronously. While the extra detail is being loaded, the user sees something like what's in the below image:
The square vector polygons have had their corners somewhat inadvertently rounded.
What I'm looking for, is a smoothly, or resizing algorithm, that will reduce the number of points to draw a polygon, whilst maintaining some of the features, such as the corners.
Maybe you could use something like the Douglas-Peucker algorithm.
It can be used to simplify poly-lines by removing the points that don't change the overall shape "too much" (where a tolerance value controls what's meant by "too much").
I would expect that this would remove points along the "straight-ish" part of a poly-line, while leaving the sharp features (like corners) intact.
Hope this helps.