Skip to main content
 首页 » 编程设计

python之获得环面的正确 Delaunay 三角剖分(使用 python)

2024年09月07日12wuhuacong

我正在尝试使用 scipy.spatial.Delaunay() 函数对环形空间进行三角剖分,但无法获得所需的结果。这是我的代码:

from scipy.spatial import Delaunay 
NTheta = 26 
NR = 8 
a0 = 1.0 
 
#define base rectangle (r,theta) = (u,v) 
u=np.linspace(0, 2*np.pi, NTheta) 
v=np.linspace(1*a0, 3*a0, NR) 
u,v=np.meshgrid(u,v) 
u=u.flatten() 
v=v.flatten() 
 
#evaluate the parameterization at the flattened u and v 
x=v*np.cos(u) 
y=v*np.sin(u) 
 
#define 2D points, as input data for the Delaunay triangulation of U 
points2D=np.vstack([u,v]).T 
xy0 = np.vstack([x,y]).T 
 
Tri1 = Delaunay(points2D) #triangulate the rectangle U 
Tri2 = Delaunay(xy0) #triangulate the annulus 
 
#plt.scatter(x, y) 
plt.triplot(x, y, Tri1.simplices, linewidth=0.5) 
plt.show() 
plt.triplot(x, y, Tri2.simplices, linewidth=0.5) 
plt.show() 

我得到以下信息:

环形本身的三角剖分显然给出了不需要的三角形。基本矩形的三角剖分似乎给出了正确的结果,直到您通过稍微拉伸(stretch)圆环(即移动其节点)意识到圆环实际上未闭合。

所以,我的问题是,如何获得能够解释非平凡拓扑的正确三角剖分?我可以从环形的三角剖分中移除单纯形——例如,基于键的长度——或者以某种方式将基本矩形的两端缝合在一起吗?有没有简单的方法可以做到这一点?

回答:

我接受了下面的答案,但它并没有完全解决所问的问题。我仍然不知道如何使用 scipy.Delaunay(即 qhull 例程)平铺周期性表面。然而,使用下面定义的掩码,可以创建一个新的三角形单形列表,这应该有多种用途。但是,不能将此列表与 scipy.Delaunay 类中定义的其他方法一起使用。所以,要小心!

请您参考如下方法:

qhull 使用凸包。所以它不能直接与凹陷的内部一起工作。在图 2 中,它用三角形填充内部。如果我们向 xy0 添加一个 (0,0) 点,这可能会更明显。

last_pt = xy0.shape[0] 
xy1 = np.vstack((xy0,(0,0)))  # add ctr point 
Tri3 = Delaunay(xy1) 
print(Tri3.points.shape, Tri3.simplices.shape) 
 
plt.triplot(Tri3.points[:,0], Tri3.points[:,1], Tri3.simplices, linewidth=0.5) 
plt.show() 

删除包含该中心点的单纯形:

mask = ~(Tri3.simplices==last_pt).any(axis=1) 
plt.triplot(Tri3.points[:,0], Tri3.points[:,1], Tri3.simplices[mask,:], linewidth=0.5) 
plt.show() 

要将两端缝合在一起,从 u 中删除一个值似乎可行:

u = u[:-1] 

在 FEM 模型中,您可以将中心元素留在原地,但为它们赋予适当的“中性”属性(绝缘或任何有效的属性)。