mapbox / polylabel

A fast algorithm for finding the pole of inaccessibility of a polygon (in JavaScript and C++)
Other
1.44k stars 151 forks source link

suboptimal centroid #3

Closed kevbot1000 closed 8 years ago

kevbot1000 commented 8 years ago

I'm getting suboptimal centroids for non-skewed rectangular polygons (horizontal and vertical).

centroid_issue

Coordinates: 32.71997,-117.19310 32.71997,-117.21065 32.72408,-117.21065 32.72408,-117.19310

mourner commented 8 years ago

I found that this happens because the polygon centroid calculation, which is used as the first guess, has some floating point errors so it ends up not being exactly in the center of the rectangle — -117.2018749838539 and not -117.201875 latitude. The algorithm then proceeds to find a slightly better solution in terms of distance to the polygon (0.0020549999999985857 compared to 0.002054995497083212).