find_containing_cell#
- StructuredGrid.find_containing_cell(point: Union[numpy.ndarray, Sequence[Union[List[float], Tuple[float, float, float], numpy.ndarray]], Sequence[Union[float, int]]]) Union[int, numpy.ndarray] #
Find index of a cell that contains the given point.
- Parameters
- point
Sequence
(float
)or
np.ndarray
Coordinates of point to query (length 3) or a
numpy
array ofn
points with shape(n, 3)
.
- point
- Returns
int
ornumpy.ndarray
Index or indices of the cell in this mesh that contains the given point.
See also
Examples
A unit square with 16 equal sized cells is created and a cell containing the point
[0.3, 0.3, 0.0]
is found.>>> import pyvista >>> mesh = pyvista.UniformGrid(dims=[5, 5, 1], spacing=[1/4, 1/4, 0]) >>> mesh UniformGrid... >>> mesh.find_containing_cell([0.3, 0.3, 0.0]) 5
A point outside the mesh domain will return
-1
.>>> mesh.find_containing_cell([0.3, 0.3, 1.0]) -1
Find the cells that contain 1000 random points inside the mesh.
>>> import numpy as np >>> points = np.random.random((1000, 3)) >>> indices = mesh.find_containing_cell(points) >>> indices.shape (1000,)