简体   繁体   English

计算 scipy 中凸包的面积

[英]Computing the area of a convex hull in scipy

I wanted to compute the convex hull for a couple of points on a plane, using scipy .我想使用scipy计算平面上几个点的凸包。

Here is my code:这是我的代码:

import numpy as np
from scipy.spatial import ConvexHull

points = np.array([[10, 10], [30, 10], [30, 20], [10, 20]])
hull = ConvexHull(points)
print(hull.vertices, hull.area)

It prints: [0 1 2 3] 60.0它打印: [0 1 2 3] 60.0

So, the perimeter rather than area is returned (I checked another example, same behavior).因此,返回的是周长而不是面积(我检查了另一个示例,相同的行为)。 Is this a bug?这是一个错误吗? Python 3.7.4 (64-bit), scipy 1.3.1. Python 3.7.4(64 位),scipy 1.3.1。

I suppose hull.area refers to the perimeter in 1D and to the area in 2D.我想hull.area指的是一维的周长和二维的面积。 If you want the area delimited by a 1D hull or the volume delimited by a 2D hull, call hull.volume instead.如果您想要由 1D 外壳分隔的区域或由 2D 外壳分隔的体积,请改为调用hull.volume

The definition of the Convex Hull is based upon the perimeter, not the area: Convex Hull 的定义是基于周长,而不是面积:

In mathematics, the convex hull or convex envelope or convex closure of a set X of points in the Euclidean plane or in a Euclidean space (or, more generally, in an affine space over the reals) is the smallest convex set that contains X. For instance, when X is a bounded subset of the plane, the convex hull may be visualized as the shape enclosed by a rubber band stretched around X.在数学中,欧几里得平面或欧几里得空间(或更一般地,在实数上的仿射空间)中的一组点 X 的凸包或凸包络或凸闭包是包含 X 的最小凸集。例如,当 X 是平面的有界子集时,可以将凸包可视化为由围绕 X 拉伸的橡皮筋包围的形状。

So this is an expected result.所以这是一个预期的结果。 Although it seems to me that you have printed both the perimeter points ( [0 1 2 3] ) and the area ( 60.0 )?尽管在我看来您已经打印了周长点( [0 1 2 3] )和区域( 60.0 )?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM