Python:圆柱体(或任何周期性表面)的Delaunay三角剖分

时间:2019-02-18 14:43:02

标签: python scipy triangulation delaunay

一年前,我问过如何在平面上对三角形状进行适当的三角剖分:环(Getting a proper Delaunay triangulation of an annulus (using python))。

我现在想将其扩展为对圆柱体(或一般而言,任何周期性表面)进行三角剖分。我尝试直接扩展2D代码:

from scipy.spatial import Delaunay
NZ = 14
NTheta = 14

R = 1 #radius of cylinder 
L = 3 #length of cylinder 

#define base rectangle (u,v)
u=np.linspace(0, 2*np.pi, NTheta) #periodic direction
v=np.linspace(0, L, NZ)
# u=u[:-1] #leave out one point
u,v=np.meshgrid(u,v)
u=u.flatten()
v=v.flatten()

#evaluate the parameterization at the flattened u and v
x=R*np.cos(u)
y=R*np.sin(u)
z=v

#define 2D points, as input data for the Delaunay triangulation of U
points2D=np.vstack([u,v]).T
tri = Delaunay(points2D, incremental=True)#triangulate the rectangle U
triSimplices = tri.simplices

xyz0 = np.vstack([x,y,z]).T

我通过参数化创建一个圆柱体,并通过基本域(矩形)的scipy.spatial.Delaunay()获得三角剖分。显然,这种三角测量不知道周期性。我可以通过移动最后一行并作图来清楚地看到这一点: enter image description here

要解决此问题,我尝试直接扩展2D解决方案-我在3D中添加了一个额外的点,重新进行了三角测量并删除了不需要的单纯形。

Tri1 = Delaunay(points2D) #triangulate the rectangle U
Tri2 = Delaunay(xyz0)

## we add a central (0,0,L/2) point to xy0 to fill it up with triangles
last_pt = xyz0.shape[0]
xy1 = np.vstack((xyz0,(0,0,L/2)))  # add ctr point
Tri3 = Delaunay(xyz1)
print(Tri3.points.shape, Tri3.simplices.shape)
print(Tri1.points.shape, Tri1.simplices.shape)
print(Tri2.points.shape, Tri2.simplices.shape)

## remove the simplices that contain the central point
mask = ~(Tri3.simplices==last_pt).any(axis=1)
triSimplices = Tri3.simplices[mask,:]

但是,将2D代码扩展到3D似乎有一个大问题-3D中的三角剖分给出的是四面体,而不是三角形!而且,它似乎对中心点的选择更为敏感。简而言之,我被困住了。

那么,对这种周期性表面进行三角剖分的正确方法是什么?

0 个答案:

没有答案