Boost::geometry : calculation of the centroid of a polygon

我只是一个虾纸丫 提交于 2019-12-11 06:16:04

问题


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.


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/23272386/boostgeometry-calculation-of-the-centroid-of-a-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!