如何将单纯形添加到 scipy Delaunay 三角剖分对象 [英] How to add simplices to a scipy Delaunay triangulation object

查看:56
本文介绍了如何将单纯形添加到 scipy Delaunay 三角剖分对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个由 scipy.spatial.Delaunay() 对象三角剖分的矩形.我设法拉伸和弯曲它,使它看起来像沿着一条线切割的环.下面是一些代码来制作具有相同拓扑的东西:

I already have a rectangle triangulated by a scipy.spatial.Delaunay() object. I manage to stretch and curve it around so that it looks like an annulus cut along a line. Here is some code to make something with the same topology:

from scipy.spatial import Delaunay

NR = 22
NTheta = 36

Rin = 1
Rout = 3
alphaFactor = 33/64
alpha = np.pi/alphaFactor # opening angle of wedge

u=np.linspace(pi/2, pi/2 + alpha, NTheta)
v=np.linspace(Rin, Rout, 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
triLattice = Delaunay(points2D) #triangulate the rectangle U
triSimplices = triLattice.simplices
plt.figure()
plt.triplot(x, y, triSimplices, linewidth=0.5)

从这个拓扑开始,我现在想把两个开放的边连接起来,做一个封闭的环(改变拓扑,就是这样).如何手动将新三角形添加到现有三角剖分中?

Starting from this topology, I now want to join up the two open edges, and make a closed annulus (change the topology, that is). How do I manually add new triangles to the existing triangulation?

推荐答案

解决方案是合并间隙周围的点.这是通过跟踪相应点的索引来做到这一点的一种方法:

A solution is to merge the points around the gap. Here is a way to do this, by keeping track of the indexes of the corresponding points:

import matplotlib.pylab as plt
from scipy.spatial import Delaunay
import numpy as np

NR = 4
NTheta = 16

Rin = 1
Rout = 3
alphaFactor = 33/64  # -- set to .5 to close the gap
alpha = np.pi/alphaFactor  # opening angle of wedge

u = np.linspace(np.pi/2, np.pi/2 + alpha, NTheta)
v = np.linspace(Rin, Rout, NR)
u_grid, v_grid = np.meshgrid(u, v)
u = u_grid.flatten()
v = v_grid.flatten()

# Get the indexes of the points on the first and last columns:
idx_grid_first = (np.arange(u_grid.shape[0]),
                  np.zeros(u_grid.shape[0], dtype=int))

idx_grid_last = (np.arange(u_grid.shape[0]),
                 (u_grid.shape[1]-1)*np.ones(u_grid.shape[0], dtype=int))

# Convert these 2D indexes to 1D indexes, on the flatten array:
idx_flat_first = np.ravel_multi_index(idx_grid_first, u_grid.shape)
idx_flat_last = np.ravel_multi_index(idx_grid_last, u_grid.shape)

# 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
triLattice = Delaunay(points2D) # triangulate the rectangle U
triSimplices = triLattice.simplices

# Replace the 'last' index by the corresponding 'first':
triSimplices_merged = triSimplices.copy()
for i_first, i_last in zip(idx_flat_first, idx_flat_last):
    triSimplices_merged[triSimplices == i_last] = i_first

# Graph
plt.figure(figsize=(7, 7))
plt.triplot(x, y, triSimplices, linewidth=0.5)
plt.triplot(x, y, triSimplices_merged, linewidth=0.5, color='k')
plt.axis('equal');

plt.plot(x[idx_flat_first], y[idx_flat_first], 'or', label='first')
plt.plot(x[idx_flat_last], y[idx_flat_last], 'ob', label='last')
plt.legend();

给出:

也许您必须调整 alphaFactor 的定义,以便间隙具有正确的大小.

Maybe you will have to adjust the definition of the alphaFactor so that the gap has the right size.

这篇关于如何将单纯形添加到 scipy Delaunay 三角剖分对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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