WPF 多边形的基本计算:面积和质心
System.Windows.Shapes.Shape 命名空间提供对可在 XAML 或代码中使用的 Polygon 对象的访问。
是否有 Microsoft 库提供一些非常基本的多边形(如面积或质心)计算?
我的偏好是不要自己重新实现这些函数或复制数学/几何库。
The System.Windows.Shapes.Shape namespace provides access to Polygon object that can be used in XAML or code.
Is there a Microsoft library that provides some very basic calculations on a Polygon like area or centriod?
My preference is to not re-implement these functions myself or copy a math/geometry library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RenderedGeometry
属性返回一个Geometry
对象,它本身有一个GetArea
方法。似乎没有任何东西可以计算质心,但根据
Polygon
的Points
属性,它应该很容易做到:The
RenderedGeometry
property returns aGeometry
object, which itself has aGetArea
method.There doesn't seem to be anything to compute the centroid, but it should be quite easy to do, based on the
Points
property of thePolygon
:我在这篇文章中发布了一些 linq 化的几何操作:
How to Zip one IEnumerable with本身
我发布的质心计算与@Thomas Levesque 发布的不同。我从 维基百科 - Centroid 获得它。他的看起来比我发布的简单得多。
这是我的算法(它使用上面链接中的 SignedArea 和 Pairwise):
该链接上还有一些其他算法,您可能会发现有用。
I posted some linq-ified geometric operations in this post:
How to Zip one IEnumerable with itself
The centroid computation I posted is different from the one that @Thomas Levesque posted. I got it from Wikipedia - Centroid. His looks a lot simpler than the one that I posted.
Here is my algorithm (it makes use of SignedArea and Pairwise from the link above):
There are also some other algorithms at that link that you might find useful.