find_closest_point

DataSet.find_closest_point(point: Iterable[float], n=1) int

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: https://github.com/pyvista/pyvista-support/issues/107

Parameters
pointiterable(float)

Length 3 coordinate of the point to query.

nint, optional

If greater than 1, returns the indices of the n closest points.

Returns
int

The index of the point in this mesh that is closest to the given point.

Examples

Find the index of the closest point to (0, 1, 0).

>>> import pyvista
>>> mesh = pyvista.Sphere()
>>> index = mesh.find_closest_point((0, 1, 0))
>>> index
212

Get the coordinate of that point.

>>> mesh.points[index]
pyvista_ndarray([-0.05218758,  0.49653167,  0.02706946], dtype=float32)