# SciPy spatial模块：实现三角剖分

scipy.spatial软件包可以利用Qhull库来计算一组点的三角剖分, Voronoi图和凸包。同样, 它包含用于最近邻点查询的KDTree实现以及用于各种度量中距离计算的实用程序。

• Delaunay三角剖分

``````from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
points = np.array([[0, 3], [1, 1.1], [1, 4], [1, 2]])
triang = Delaunay(points)
plt.triplot(points[:, 0], points[:, 1], triang.simplices.copy())
plt.plot(points[:, 0], points[:, 1], 'o')
plt.show()``````

### 共平面点

``````from scipy.spatial import Delaunay
points = np.array([[0, 0], [0, 1], [1, 0], [1, 1], [1, 1]])
tri = Delaunay(points)
print(tri.coplanar)``````

``[[4 0 3]]``

### 凸包

``````from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
points = np.random.rand(10, 2) # 30 random points in 2-D
hull = ConvexHull(points)
plt.plot(points[:, 0], points[:, 1], 'o')
for simplex in hull.simplices:
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
plt.show()``````

### Scipy cdist

SciPy提供了space.distance.cdist, 用于计算两个输入集合中的每对之间的距离。以下是调用约定：

1. Y = cdist(XA, XB, ‘欧几里得’)

2. Y = cdist(XA, XB, ‘minkowski’, p = 2。)

3. Y = cdist(XA, XB, ” cityblock”)

• 回顶