![](/img/trans.png)
[英]Finding a partial or complete inclusion of a set of points in convex hull of other set of points in 2D in python
[英]Perimeter of a 2D convex hull in Python
如何在Python中計算凸包的周長? 我知道SciPy
具有凸包的area
參數; 但是,我需要perimeter
。
您可以遍歷凸包的點並計算連續點之間的距離:
import numpy as np
from scipy.spatial.qhull import ConvexHull
from scipy.spatial.distance import euclidean
points = np.random.rand(30, 2)
hull = ConvexHull(points)
vertices = hull.vertices.tolist() + [hull.vertices[0]]
perimeter = np.sum([euclidean(x, y) for x, y in zip(points[vertices], points[vertices][1:])])
print(perimeter)
產量
3.11
注意:您還需要添加對(最后一個,第一個)
UPDATE
或者,假設數據為2D,則可以使用hull.area
。 也就是說,上述方法返回的值等於area屬性的值。 如果需要真實區域 ,則需要查詢hull.volume
。
進一步
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.