如何在 Python 中设置 Delaunay 三角形边的最大距离

How to set a maximum distance of a Delaunay triangle side in Python

我正在尝试使用 scipy.spatial.Delaunay 对象处理一些数据集。 但问题是我无法设置最大三角形边长。我想做类似 How to set maximum length of triangle side in Delaunay triangulation? 的事情,但在 Python

下面是一些将大边与小边分开的代码:

# Computing Delaunay
tri = Delaunay(points)

# Separating small and large edges:
thresh = 1.0  # user defined threshold
small_edges = set()
large_edges = set()
for tr in tri.vertices:
    for i in xrange(3):
        edge_idx0 = tr[i]
        edge_idx1 = tr[(i+1)%3]
        if (edge_idx1, edge_idx0) in small_edges:
            continue  # already visited this edge from other side
        if (edge_idx1, edge_idx0) in large_edges:
            continue
        p0 = points[edge_idx0]
        p1 = points[edge_idx1]
        if np.linalg.norm(p1 - p0) <  thresh:
            small_edges.add((edge_idx0, edge_idx1))
        else:
            large_edges.add((edge_idx0, edge_idx1))

# Plotting the output
figure()
plot(points[:, 0], points[:, 1], '.')
for i, j in small_edges:
    plot(points[[i, j], 0], points[[i, j], 1], 'b')
for i, j in large_edges:
    plot(points[[i, j], 0], points[[i, j], 1], 'c')

根据以下代码生成的数据,我得到了这个图:

# Constructing the input point set
np.random.seed(0)
x = 3.0 * np.random.rand(1000)
y = 2.0 * np.random.rand(1000) - 1.0
inside = ((x ** 2 + y ** 2 > 1.0) & ((x - 3) ** 2 + y ** 2 > 1.0) & ((x-1.5) ** 2 + y ** 2 > 0.09))
points = np.vstack([x[inside], y[inside]]).T