DataSet.find_closest_cell(point: Union[int, numpy.ndarray]) Union[int, numpy.ndarray]

Find index of closest cell in this mesh to the given point.

pointiterable(float) or np.ndarray

Length 3 coordinate of the point to query or a numpy array of coordinates.

int or numpy.ndarray

Index or indices of the cell in this mesh that is closest to the given point.


Find nearest cell to a point on a sphere

>>> import pyvista
>>> mesh = pyvista.Sphere()
>>> index = mesh.find_closest_cell([0, 0, 0.5])
>>> index

Find the nearest cells to several random points. Note that -1 indicates that the locator was not able to find a reasonably close cell.

>>> import numpy as np
>>> points = np.random.random((1000, 3))
>>> indices = mesh.find_closest_cell(points)
>>> indices.shape