scipy.spatial.
tsearch#
- scipy.spatial.tsearch(tri, xi)#
尋找包含給定點的單體。此函數的功能與
Delaunay.find_simplex
相同。- 參數:
- triDelaunayInfo
Delaunay 三角剖分
- xindarray of double, shape (…, ndim)
要定位的點
- 返回:
- indarray of int, shape 與 xi 相同
包含每個點的單體索引。三角剖分外部的點值為 -1。
註解
在版本 0.9 中新增。
範例
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from scipy.spatial import Delaunay, delaunay_plot_2d, tsearch >>> rng = np.random.default_rng()
一組隨機點的 Delaunay 三角剖分
>>> pts = rng.random((20, 2)) >>> tri = Delaunay(pts) >>> _ = delaunay_plot_2d(tri)
尋找包含給定點集的單體
>>> loc = rng.uniform(0.2, 0.8, (5, 2)) >>> s = tsearch(tri, loc) >>> plt.triplot(pts[:, 0], pts[:, 1], tri.simplices[s], 'b-', mask=s==-1) >>> plt.scatter(loc[:, 0], loc[:, 1], c='r', marker='x') >>> plt.show()