作为一边请注意,这不是作业,我不是在寻找代码。我正在寻找我可以用来实现我自己的方法的描述。我有关于从点列表中拉出一系列三角形的想法,但是我知道有很多关于凸多边形和凹多边形的边缘案例,我可能无法捕捉。
解决方案这是标准方法,AFAIK。基本上总结每个顶点周围的交叉产品。
Python代码给出了一个表示为(x,y)顶点坐标列表的多边形,隐式地从最后一个顶点绕到第一个顶点: def area(p): return 0.5 * abs(sum(x0 * y1 - x1 * y0 $ b (p,p [1:0))中的((x0,y0),(x1,y1))的$ b) def segments(p): $大卫Lehavi评论:值得一提的是,为什么这个算法的工作原理:这是格林定理的函数-y和x的应用;完全符合计量器的工作方式。更具体地说:以上公式= integral_over_perimeter(-y dx + x dy)= integral_over_area(( - ( - dy)/ dy + dx / dx)dy dx)= 2 Area
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?
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.
解决方案Here is the standard method, AFAIK. Basically sum the cross products around each vertex. Much simpler than triangulation.
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]])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:
Formula above = integral_over_perimeter(-y dx + x dy) = integral_over_area((-(-dy)/dy+dx/dx) dy dx) = 2 Area
更多推荐
我如何计算2D多边形的面积?
发布评论