用不同数据结构表示三角剖分

2024-07-07 06:13:53 发布

您现在位置:Python中文网/ 问答频道 /正文

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

points = np.array([[0.2, 0], [0.1, 1.1], [0.6, 0.1], [1, 0.5], [0.6,0.9], [0.4,0.4]])
tri = Delaunay(points)

#plot
plt.triplot(points[:,0], points[:,1], tri.simplices)
plt.plot(points[:,0], points[:,1], 'o')
plt.show()

print(tri.points)
"""
[[0.2 0. ]
[0.  1.1]
[0.6 0. ]
[1.  1. ]
[0.2 0.8]
[0.4 0.4]]
"""
print(tri.simplices)
"""
[[0 5 1]
[5 4 1]
[4 5 3]
[5 2 3]
[2 5 0]]
"""

Delaunay

这是点阵列的delaunay三角剖分。我有点(tri.points)和三角形(tri.simplices)数组作为输出。我需要将它们转换为半边数据结构、翼边数据结构、角表数据结构和四边形数据结构,用于不同的表示形式,并选择存储较少空间的表示形式。在Python中是否有用于这些转换的库,或者我是否应该自己编写这些库


Tags: importnumpy数据结构plotmatplotlibasnpplt