问题描述
假设的一系列二维空间中的点是不自相交的,什么是确定所得多边形的面积的有效方法
Assuming a series of points in 2d space that do not self-intersect, what is an efficient method of determining the area of the resulting polygon?
作为一个方面说明,这不是功课,我不是找code。我要寻找一个说明,我可以用它来实现自己的方法。我有我的想法,从点的名单拉三角形的序列,但我知道有相关的凸凹面,我可能不会赶上一堆的边缘情况。
As a side note, this is not homework and I am not looking for code. I am looking for a description I can use to implement my own method. I have my ideas about pulling a sequence of triangles from the list of points, but I know there are a bunch of edge cases regarding convex and concave polygons that I probably won't catch.
推荐答案
下面是的,AFAIK。基本上总结了跨产品周围的每个顶点。远远高于三角简单。
Here is the standard method, AFAIK. Basically sum the cross products around each vertex. Much simpler than triangulation.
的Python code,给出psented作为(X,Y)的顶点坐标,隐式地从最后一个顶点到第一缠绕列表的多边形重新$ P $
Python code, given a polygon represented as a list of (x,y) vertex coordinates, implicitly wrapping around from the last vertex to the first:
def area(p):
return 0.5 * abs(sum(x0*y1 - x1*y0
for ((x0, y0), (x1, y1)) in segments(p)))
def segments(p):
return zip(p, p[1:] + [p[0]])
大卫Lehavi点评:值得一提的,为什么这种算法的工作原理:它是一个应用格林公式的职能-y和X;正是在这样一个求积仪的作品。更具体地讲:
David Lehavi comments: It is worth mentioning why this algorithm works: It is an application of Green's theorem for the functions -y and x; exactly in the way a planimeter works. More specifically:
以上=
式 integral_over_perimeter(-y DX + X DY)=
integral_over_area(( - ( - DY)/ DY + DX / DX)DY DX)=
2区
Formula above =
integral_over_perimeter(-y dx + x dy) =
integral_over_area((-(-dy)/dy+dx/dx) dy dx) =
2 Area
这篇关于如何计算二维多边形的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!