Numpy 从顶点坐标创建三角形网格

Numpy 从顶点坐标创建三角形网格,numpy,scipy,geometry,mesh,Numpy,Scipy,Geometry,Mesh,给定一组具有坐标x和y(左图)的二维数据点,是否有一种简单的方法在其上构建三角形网格(右图)?i、 e.返回元组列表,该列表指示连接的顶点。解决方案不是唯一的,但任何合理的网格都足够了。您可以尝试。从该链接: points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]]) from scipy.spatial import Delaunay tri = Delaunay(points) plt.triplot(points[:,0], point

给定一组具有坐标
x
y
(左图)的二维数据点,是否有一种简单的方法在其上构建三角形网格(右图)?i、 e.返回元组列表,该列表指示连接的顶点。解决方案不是唯一的,但任何合理的网格都足够了。

您可以尝试。从该链接:

points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]])

from scipy.spatial import Delaunay

tri = Delaunay(points)

plt.triplot(points[:,0], points[:,1], tri.simplices)

plt.plot(points[:,0], points[:,1], 'o')

plt.show()
输出:

您可以使用。下面是一个来自

import numpy as np
points = np.array([[-1,1],[-1.3, .6],[0,0],[.2,.8],[1,.85],[-.1,-.4],[.4,-.15],[.6,-.6],[.9,-.2]])
from scipy.spatial import Delaunay
tri = Delaunay(points)

import matplotlib.pyplot as plt
plt.triplot(points[:,0], points[:,1], tri.simplices)
plt.plot(points[:,0], points[:,1], 'o')
plt.show()
以下是与您的输入类似的结果:

三角形存储在Delaunay对象的
simplices
属性中,该属性引用存储在
属性中的坐标:

>>> tri.points
array([[-1.  ,  1.  ],
       [-1.3 ,  0.6 ],
       [ 0.  ,  0.  ],
       [ 0.2 ,  0.8 ],
       [ 1.  ,  0.85],
       [-0.1 , -0.4 ],
       [ 0.4 , -0.15],
       [ 0.6 , -0.6 ],
       [ 0.9 , -0.2 ]])
>>> tri.simplices
array([[5, 2, 1],
       [0, 3, 4],
       [2, 0, 1],
       [3, 0, 2],
       [8, 6, 7],
       [6, 5, 7],
       [5, 6, 2],
       [6, 3, 2],
       [3, 6, 4],
       [6, 8, 4]], dtype=int32)
如果要查找连接的顶点,则有一个属性也包含该信息:

>>> tri.vertex_neighbor_vertices
(array([ 0,  4,  7, 12, 16, 20, 24, 30, 33, 36], dtype=int32), array([3, 4, 2, 1, 5, 2, 0, 5, 1, 0, 3, 6, 0, 4, 2, 6, 0, 3, 6, 8, 2, 1,
       6, 7, 8, 7, 5, 2, 3, 4, 8, 6, 5, 6, 7, 4], dtype=int32))