【问题标题】:Output vertices from delaunay triangulation with scipy使用 scipy 从 delaunay 三角剖分输出顶点
【发布时间】:2020-10-20 22:53:47
【问题描述】:

如何在下面的代码中输出我的 delaunay 三角剖分结果。我知道如何用 matplotlib 绘制它,但不知道如何输出数字。打印只是输出对象,但我不知道如何访问它。

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

points = np.array([[0.1933333, 0.47],
                   [0.1966667, 0.405],
                   [0.2066667, 0.3375]])


tri = Delaunay(points)
print(tri)

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

【问题讨论】:

    标签: python scipy triangulation vertices delaunay


    【解决方案1】:

    三角形顶点的 id 存储在三角剖分对象的simplices attribute 中。存储输入点数组中顶点的索引。

    >>> points = np.array([[0.1933333, 0.47],
                       [0.1966667, 0.405],
                       [0.2066667, 0.3375]])
    >>> tri = Delaunay(points)
    >>> print(tri)
    <scipy.spatial.qhull.Delaunay object at 0x000002E1EB4EE348>
    >>> tri.simplices
    array([[1, 2, 0]], dtype=int32)
    

    要返回顶点的坐标,您需要在输入点数组中查找它们:

    >>> points[tri.simplices]
    array([[[0.1966667, 0.405    ],
            [0.2066667, 0.3375   ],
            [0.1933333, 0.47     ]]])
    

    生成的 Delaunay 三角剖分还包含一些其他属性,特别是 neighbors 包含有关相邻三角形的信息,vertex_to_simplex 允许您找到给定顶点所属的某个 Delaunay 三角形(然后使用 @987654326 开始遍历三角剖分@)。

    【讨论】:

      猜你喜欢
      • 2020-08-05
      • 2020-10-17
      • 2021-05-27
      • 2015-01-07
      • 2016-05-19
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2016-06-12
      相关资源
      最近更新 更多