如何按标准 select 边缘?
How to select edges by criterion?
我正在使用 Python 3.7.
有一组点。我通过这些点生成 Delaunay 三角剖分。
import numpy as np
points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1], [1.5, 0.6], [1.2, 0.5], [1.7, 0.9], [1.1, 0.1]])
from scipy.spatial import Delaunay
tri = Delaunay(points)
计算边长为 dict1:
simplices = points[tri.simplices]
edge_lengths = {}
for point in points:
key = tuple(point)
vertex_edges = edge_lengths.get(key,[])
adjacency_mask = np.isin(simplices, point).all(axis=2).any(axis=1)
for simplex in simplices[adjacency_mask]:
self_mask = np.isin(simplex, point).all(axis=1)
for other in simplex[~self_mask]:
dist = np.linalg.norm(point - other)
if dist not in vertex_edges:
vertex_edges.append(dist)
edge_lengths[key] = vertex_edges
计算边长的平均值(连接到同一点)作为 dict2:
local_mean_edge_lengths = {}
for point in points:
key = tuple(point)
local_mean_edge_lengths[key] = np.mean(edge_lengths[key])
我得到两个命令:
In[1]:edge_lengths
Out[1]:
{(0.0, 0.0): [1.4142135623730951, 1.1, 1.3, 1.0],
(0.0, 1.1): [1.004987562112089, 1.3416407864998738, 1.4866068747318506],
(1.0, 0.0): [1.4866068747318506,0.5385164807134504,0.7810249675906654,1.140175425099138,0.14142135623730956],
(1.0, 1.0): [1.004987562112089,1.4142135623730951,0.5385164807134504,0.6403124237432849,0.7071067811865475],
(1.5, 0.6): [0.6403124237432849, 0.36055512754639896, 0.31622776601683794, 0.6403124237432848],
(1.2, 0.5): [0.5385164807134504, 1.3, 0.31622776601683794, 0.41231056256176607],
(1.7, 0.9): [0.7071067811865475, 0.36055512754639896],
(1.1, 0.1): [0.14142135623730956, 0.41231056256176607, 0.6403124237432848]}
In[2]:local_mean_edge_lengths
Out[2]:
{(0.0, 0.0): 1.2035533905932738,
(0.0, 1.1): 1.2777450744479377,
(1.0, 0.0): 0.8175490208744828,
(1.0, 1.0): 0.8610273620256933,
(1.5, 0.6): 0.4893519352624517,
(1.2, 0.5): 0.6417637023230136,
(1.7, 0.9): 0.5338309543664732,
(1.1, 0.1): 0.3980147808474535}
如何按标准select边缘?
喜欢,
为键(0.0, 0.0)
,
有 4 个边长(1.4142135623730951, 1.1, 1.3, 1.0)
和 1 个平均边长( 1.2035533905932738)
edge_length1 = 1.4142135623730951 > 1.2035533905932738,
删除这条边;
edge_length2 = 1.1 < 1.2035533905932738,
保持这个优势;
edge_length3 = 1.3 > 1.2035533905932738,
删除这条边;
edge_length4 = 1.0 < 1.2035533905932738,
保持这个优势;
与其他键相同。
如何绘制新的Delaunay三角剖分(去除边后)?
查看 以识别 Delaunay 三角剖分中的大边并绘制结果。下图取自那里,大边是青色的。稍作修改即可解决您的问题。
请注意,您不能删除 Delaunay 三角剖分本身的边,因为这会使三角剖分无效。
因此,通过您的标准的边集将需要在单独的数据结构中表示。在我的回答中,它们表示为一组 (i, j)
对,即边列表,然后您可以使用 networkx library 使用 G.add_edges_from
方法构建图形。
我正在使用 Python 3.7.
有一组点。我通过这些点生成 Delaunay 三角剖分。
import numpy as np
points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1], [1.5, 0.6], [1.2, 0.5], [1.7, 0.9], [1.1, 0.1]])
from scipy.spatial import Delaunay
tri = Delaunay(points)
计算边长为 dict1:
simplices = points[tri.simplices]
edge_lengths = {}
for point in points:
key = tuple(point)
vertex_edges = edge_lengths.get(key,[])
adjacency_mask = np.isin(simplices, point).all(axis=2).any(axis=1)
for simplex in simplices[adjacency_mask]:
self_mask = np.isin(simplex, point).all(axis=1)
for other in simplex[~self_mask]:
dist = np.linalg.norm(point - other)
if dist not in vertex_edges:
vertex_edges.append(dist)
edge_lengths[key] = vertex_edges
计算边长的平均值(连接到同一点)作为 dict2:
local_mean_edge_lengths = {}
for point in points:
key = tuple(point)
local_mean_edge_lengths[key] = np.mean(edge_lengths[key])
我得到两个命令:
In[1]:edge_lengths
Out[1]:
{(0.0, 0.0): [1.4142135623730951, 1.1, 1.3, 1.0],
(0.0, 1.1): [1.004987562112089, 1.3416407864998738, 1.4866068747318506],
(1.0, 0.0): [1.4866068747318506,0.5385164807134504,0.7810249675906654,1.140175425099138,0.14142135623730956],
(1.0, 1.0): [1.004987562112089,1.4142135623730951,0.5385164807134504,0.6403124237432849,0.7071067811865475],
(1.5, 0.6): [0.6403124237432849, 0.36055512754639896, 0.31622776601683794, 0.6403124237432848],
(1.2, 0.5): [0.5385164807134504, 1.3, 0.31622776601683794, 0.41231056256176607],
(1.7, 0.9): [0.7071067811865475, 0.36055512754639896],
(1.1, 0.1): [0.14142135623730956, 0.41231056256176607, 0.6403124237432848]}
In[2]:local_mean_edge_lengths
Out[2]:
{(0.0, 0.0): 1.2035533905932738,
(0.0, 1.1): 1.2777450744479377,
(1.0, 0.0): 0.8175490208744828,
(1.0, 1.0): 0.8610273620256933,
(1.5, 0.6): 0.4893519352624517,
(1.2, 0.5): 0.6417637023230136,
(1.7, 0.9): 0.5338309543664732,
(1.1, 0.1): 0.3980147808474535}
如何按标准select边缘?
喜欢,
为键(0.0, 0.0)
,
有 4 个边长(1.4142135623730951, 1.1, 1.3, 1.0)
和 1 个平均边长( 1.2035533905932738)
edge_length1 = 1.4142135623730951 > 1.2035533905932738,
删除这条边;
edge_length2 = 1.1 < 1.2035533905932738,
保持这个优势;
edge_length3 = 1.3 > 1.2035533905932738,
删除这条边;
edge_length4 = 1.0 < 1.2035533905932738,
保持这个优势;
与其他键相同。
如何绘制新的Delaunay三角剖分(去除边后)?
查看
请注意,您不能删除 Delaunay 三角剖分本身的边,因为这会使三角剖分无效。
因此,通过您的标准的边集将需要在单独的数据结构中表示。在我的回答中,它们表示为一组 (i, j)
对,即边列表,然后您可以使用 networkx library 使用 G.add_edges_from
方法构建图形。