Question

I've been working with the Boost geometry, mostly for manipulating polygons; I was using the centroid built-in method (http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/reference/algorithms/centroid/centroid_2.html) for calculating the geometric (bary) center of my polygons, but recently after outputting the coordinates of my points (composing a specific polygon) (and analyzing them on the side with some Python scripts) I realized that the centroid coordinates the previous method was giving me do not correspond to the geometric mean of the points of the polygon.

I'm in two dimensions and putting it into equations, I should have:

x_centroid = \frac{1}{number of points composing the polygon} \sum{point i} x_i

and the same for the y coordinates. I'm now suspecting that this could have to do with the fact that the boost geometry library is not just looking at the points on the edge of the polygon (its outer ring) but treating it as a filled object.

Does any of you have some experience in manipulating these functions?

Btw, I using:

point my_center(0,0);
bg::centroid(my_polygon,my_center);

to compute the centroid.

Thank you.

Was it helpful?

Solution

In Boost.Geometry the algorithm proposed by Bashein and Detmer [1] is used by default for the calculation of a centroid of Areal Geometries.

The reason is that the simple average method fails for a case where many closely spaced vertices are placed at one side of a Polygon.


[1] Gerard Bashein and Paul R. Detmer. “Centroid of a Polygon”. Graphics Gems IV, Academic Press, 1994, pp. 3–6

OTHER TIPS

That's what the centroid is -- the mean of the infinite number of points making up the filled polygon. It sounds like what you want is not the centroid, but just the average of the vertices.

Incidentally, "geometric mean" has a different definition than you think, and is not in any way applicable to this situation.

Centroid of polygon is considered as mass center of plane figure (for example, paper sheet), not center of vertices only

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top