[英]How to set a maximum distance of a Delaunay triangle side in Python
我正在嘗試使用scipy.spatial.Delaunay
對象處理一些數據集。 但問題是我無法設置最大三角形邊長。 我想做類似如何在 Delaunay 三角剖分中設置三角形邊的最大長度之類的操作? ,但在 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.