Mesh operation code
1. 四边形网格转为三角网格
作用: 将每个四边网格转为两个三角网格
def quads2tris(F):
F_out = []
for f in F:
if len(f) <= 3: F_out += [f]
elif len(f) == 4:
F_out += [
[f[0], f[1], f[2]],
[f[0], f[2], f[3]]
]
else:
print('This should not happen, but might')
print('To solve: extend this to deal with 5-gons or ensure mesh is quads/tris only')
sys.exit()
return np.array(F_out, np.int32)
使用方式:
tri_mesh_face=quads2tris(quads_mesh_face)
2. 提取三角面的边信息
作用: 提取三角面三个点之间的连接关系
输出为每个面对应的三条边
def faces2edges(F):
E = set()
for f in F:
N = len(f)
for i in range(N):
j = (i + 1) % N
E.add(tuple(sorted([f[i], f[j]])))
return np.array(list(E), np.int32)
使用方式:</