find_closest_cell

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

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

Parameters
pointiterable(float) or np.ndarray

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

Returns
int or numpy.ndarray

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

Examples

Find nearest cell to a point on a sphere

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

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
(1000,)