我如何计算2D多边形的面积?

编程入门 行业动态 更新时间:2024-10-28 10:22:07
本文介绍了我如何计算2D多边形的面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 假设在2D空间中的一系列不自相交的点,确定生成多边形面积的有效方法是什么?

作为一边请注意,这不是作业,我不是在寻找代码。我正在寻找我可以用来实现我自己的方法的描述。我有关于从点列表中拉出一系列三角形的想法,但是我知道有很多关于凸多边形和凹多边形的边缘案例,我可能无法捕捉。

解决方案

这是标准方法,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多边形的面积?

本文发布于:2023-08-01 22:16:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多边形   面积

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!