如何计算二维多边形的面积? [英] How do I calculate the area of a 2d polygon?

查看:27
本文介绍了如何计算二维多边形的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设二维空间中的一系列点不自相交,确定结果多边形面积的有效方法是什么?

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.

推荐答案

这里是 标准方法,AFAIK.基本上对每个顶点周围的叉积求和.比三角剖分简单得多.

Here is the standard method, AFAIK. Basically sum the cross products around each vertex. Much simpler than triangulation.

Python 代码,给定一个多边形,表示为 (x,y) 顶点坐标列表,从最后一个顶点到第一个隐式环绕:

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 评论:值得一提的是为什么这个算法有效:它是 的应用函数-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个区域

这篇关于如何计算二维多边形的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆