DataSet.find_closest_point#
- DataSet.find_closest_point(point: Iterable[float], n: int = 1) int | VectorLike[int][source]#
Find index of closest point in this mesh to the given point.
If wanting to query many points, use a KDTree with scipy or another library as those implementations will be easier to work with.
See: pyvista/pyvista-support#107
Warning
This filter internally builds and caches a vtkPointLocator. If the mesh’s geometry is modified, the cache will no longer be valid.
Examples#
Download Python source code | Download Jupyter notebook
Find the index of the closest point to (0, 1, 0).
>>> import pyvista as pv
>>> mesh = pv.Sphere()
>>> index = mesh.find_closest_point((0, 1, 0))
>>> index
239
Get the coordinate of that point.
>>> mesh.points[index]
pyvista_ndarray([-0.05218758, 0.49653167, 0.02706946], dtype=float32)