不规则形状的面积
我有一组位于图像上的点。这组点形成一个不规则的闭合形状。我需要找到这个形状的面积。是否有任何机构用于计算面积的正常算法?或者是否有诸如 boost 之类的库提供支持?我正在使用 C++。
I have set of points which lies on the image. These set of points form a irregular closed shape. I need to find the area of this shape. Does any body which is the normal algorithm used for calculating the area ? Or is there any support available in libraries such as boost? I am using C++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您的多边形很简单(除了成对的连续线段之外,它没有任何共同点),那么维基百科可以帮助您:
面积的公式为
(假设最后一个点与第一个点相同)
您可以轻松地将其实现为
当然顶点必须根据它们的顺序进行排序多边形中的自然跟随..
If you polygon is simple (it doesn't have any point in common except for the pairs of consecutive segments) then wikipedia comes to help you:
The formula for the area is
(it assumes that the last point is the same of the first one)
You can easily implement it as
Of course vertices must be ordered according to their natural following in the polygon..
有一个求和公式。
There's a summation formula for that.
您可能想要更精确,甚至可能提供一个图形示例。
例如,如果您拥有的点只是像素,那么像素数等于面积。但如果这些点是多边形的角,那么多边形的面积就不容易确定。您可以使用多边形三角剖分,并对获得的三角形面积求和。
You might want to be more precise, possibly even providing a graphical example.
For instance, if the points you have are merely pixels, then the number of pixels equals the area. But if the points are the corners of a polygon, then the area of the polygon isn't that easily determined. You'd use polygon triangulation, and sum the areas of the triangles obtained.
注意:如果您不知道点的顺序并且不能保证多边形是凸的,则无法确定形状的顺序,因为产生多边形的点可能有不止一种可能的顺序。如果您确实知道多边形是凸多边形,则确定点的顺序很容易。仅按与一个特定点的角度对点进行排序,第一个点是在其自身和初始点之间形成一条线的点,以便所有其他点都位于该线的同一侧。通过此过程形成的三角形也可用于计算面积。
Note: If you don't know the order of the points and cannot guarantee that your polygon is convex, it is not possible to determine the ordering of the shape, since there may be more than one possible order the points which produces a polygon. If you do know that the polygon is convex, determining the ordering of the points is easy. Merely sort the points by angle from one particular point., with the first point being the one that forms a line between itself and the initial point such that all the other points are on the same side of the line. The triangles formed by this process can also be used to calculate the area.
Boost.Geometry 支持多边形面积计算(Boost.Geometry 尚未接受该功能,并且使用起来非常混乱)。
否则,您必须首先确定由您的点定义的多边形。从外观上看,所有点都是多边形的顶点,因此这只是正确排序点集的问题。另一种可能性是您正在寻找点集的凸包(请参阅 http://en.wikipedia .org/wiki/Convex_hull_algorithms)。
There is support for area calculation of polygons in Boost.Geometry (which isn't yet accepted into boost and which is very confusing to use).
Otherwise you would have to determine the polygon that is defined by your points first. From the looks of it all of your points are vertices of the polygon so this is a simply a matter of ordering your point sets correctly. Another possibility is that you are looking for the convex hull of your point set (see http://en.wikipedia.org/wiki/Convex_hull_algorithms).
毫不谦虚,我请您参考我对另一个问题的回答重叠圆的组合面积< /a>.蒙特卡罗功能强大、易于并行化,并且最终将为您提供所需精度的答案。
Without modesty, I refer you to my answer to another question Combined area of overlapping circles. Monte Carlo is robust, easy-to-parallelise and will, eventually, give you an answer to the accuracy you require.
最简单的方法可能是对形状进行三角测量并计算三角形的面积。 Dave Eberly 有一个名为(Boost 许可证)的库,可以帮助进行三角测量; 此处有更多信息。例如,查找 TriangulateEC。
The simplest way to do this is probably to triangulate your shape and calculate the area of the triangles. Dave Eberly has a library called (Boost license) that may help with the triangulation; there is more information here. Look for TriangulateEC, for example.