问题描述
我需要一种表征2D点集大小的方法,因此我可以根据视口的比例确定是将它们渲染为空间中的单个点还是表示为多边形。我已经有了一种算法来计算集合的凸包以生成代表性多边形,但是我需要一种表征其大小的方法。一个明显的度量是凸包上点之间的最大距离,即集合的直径。但是我真的更感兴趣于垂直于其直径的横截面的大小,以找出边界多边形有多窄。给定顶点和最远点的索引的排序列表(最好在Python中),是否有一种简单的方法?
I need a way to characterize the size of sets of 2-D points, so I can determine whether to render them as individual points in a space or as representative polygons, dependent on the scale of the viewport. I already have an algorithm to calculate the convex hull of the set to produce the representative polygon, but I need a way to characterize its size. One obvious measure is the maximum distance between points on the convex hull, which is the diameter of the set. But I'm really more interested in the size of its cross-section perpendicular to its diameter, to figure out how narrow the bounding polygon is. Is there a simple way to do this, given the sorted list of vertices and and the indices of the furthest points (ideally in Python)?
一种简单的方法来计算一组点的最小面积边界椭圆的半径?我已经看到了解决此问题的一些方法,但是没有什么可以轻易转换为Python的,所以我真的在寻找可以交钥匙的东西。
Or alternatively, is there an easy way to calculate the radii of the minimal area bounding ellipse of a set of points? I have seen some approaches to this problem, but nothing that I can readily convert to Python, so I'm really looking for something that's turnkey.
推荐答案
您可以计算:
,执行以下步骤:
- 找到凸包
- 找到距离最远的两个点
a
和b
- 找到方向向量
d =(a-b).normalized()
在这两个之间 -
使用矩阵旋转轴,使该方向向量位于水平方向。
- Find the convex hull
- Find the two points
a
andb
which are furthest apart - Find the direction vector
d = (a - b).normalized()
between those two Rotate your axes so that this direction vector lies horizontal, using the matrix:
[ d.x, d.y]
[-d.y, d.x]
在此新坐标系中找到点的最小和最大y值。区别在于您的宽度
Find the minimum and maximum y value of points in this new coordinate system. The difference is your "width"
请注意,这不是宽度的特别好定义-更好一个是:
Note that this is not a particularly good definition of "width" - a better one is:
另一个有用的尺寸定义可能是点上平均距离的两倍船体和中心
Another useful definition of size might be twice the average distance between points on the hull and the center
center = sum(convexhullpoints) / len(convexhullpoints)
size = 2 * sum(abs(p - center) for p in convexhullpoints) / len(convexhullpoints)
这篇关于任意多边形的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!