pyvista.DataSet.find_closest_point#
- DataSet.find_closest_point(point: Iterable[float], n: int = 1) 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
- Parameters:
- Returns:
int
The index of the point in this mesh that is closest to the given point.
See also
Examples
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)