pyvista.DataSet.find_containing_cell#
- DataSet.find_containing_cell( ) int | NumpyArray[int] [source]#
Find index of a cell that contains the given point.
- Parameters:
- point
VectorLike
[float
] |MatrixLike
[float
], Coordinates of point to query (length 3) or a
numpy.ndarray
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.
Changed in version 0.35.0: Inputs of shape
(1, 3)
now return anumpy.ndarray
of shape(1,)
.
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 as pv >>> mesh = pv.ImageData(dimensions=[5, 5, 1], spacing=[1 / 4, 1 / 4, 0]) >>> mesh ImageData... >>> 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.default_rng().random((1000, 3)) >>> indices = mesh.find_containing_cell(points) >>> indices.shape (1000,)