如何在 Python 中设置 Delaunay 三角形边的最大距离 [英] How to set a maximum distance of a Delaunay triangle side in Python

查看:40
本文介绍了如何在 Python 中设置 Delaunay 三角形边的最大距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 scipy.spatial.Delaunay 对象处理一些数据集.但问题是我无法设置最大三角形边长.我想做类似

# 构建输入点集np.random.seed(0)x = 3.0 * np.random.rand(1000)y = 2.0 * np.random.rand(1000) - 1.0里面 = ((x ** 2 + y ** 2 > 1.0) & ((x - 3) ** 2 + y ** 2 > 1.0) & ((x-1.5) ** 2 + y** 2 > 0.09))点 = np.vstack([x[inside], y[inside]]).T

I'm trying to work on some datasets using the scipy.spatial.Delaunay object. But the problem is that I'm not able to set a maximum triangle side lenght. I would like to do something like How to set maximum length of triangle side in Delaunay triangulation?, but in Python

解决方案

Here is some code that separates large edges from small:

# 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')

On the data generated from the following code, I get this figure:

# 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

这篇关于如何在 Python 中设置 Delaunay 三角形边的最大距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆