Main Content

findCell

Find cells by coordinates of points located inside them

Since R2025a

    Description

    cellIDs = findCell(g,Coords) returns the IDs of the cells containing query points with Cartesian coordinates Coords. The function returns NaN values for points located outside of the geometry. For query points located on a boundary and, therefore, belonging to more than one cell, the function returns the lowest cell ID.

    example

    Examples

    collapse all

    Identify cells in a geometry of nested spheres.

    Create and plot the geometry representing 10 nested spheres.

    g = fegeometry(multisphere(1:10));
    pdegplot(g,FaceAlpha=0.3)

    Figure contains an axes object. The axes object contains 5 objects of type quiver, text, patch.

    Create a matrix of query points.

    QP = zeros(10,3);
    QP(:,1) = (1:10).'-0.1
    QP = 10×3
    
        0.9000         0         0
        1.9000         0         0
        2.9000         0         0
        3.9000         0         0
        4.9000         0         0
        5.9000         0         0
        6.9000         0         0
        7.9000         0         0
        8.9000         0         0
        9.9000         0         0
    
    

    Identify cells where these points are located.

    cellID = findCell(g,QP)
    cellID = 1×10
    
         1     2     3     4     5     6     7     8     9    10
    
    

    For points outside the geometry, findCell returns NaN.

    cellID = findCell(g,[15 0 0])
    cellID = 
    NaN
    

    For query points located on the boundaries and, therefore, belonging to more than one cell, findCell returns the lowest cell ID.

    QP(:,1) = (1:10).'
    QP = 10×3
    
         1     0     0
         2     0     0
         3     0     0
         4     0     0
         5     0     0
         6     0     0
         7     0     0
         8     0     0
         9     0     0
        10     0     0
    
    
    cellID = findCell(g,QP)
    cellID = 1×10
    
         1     2     3     4     5     6     7     8     9    10
    
    

    Modify the damping mounts geometry by deleting two mounts located diagonally.

    Import the geometry representing four damping mounts.

    g = fegeometry("DampingMounts.stl")
    g = 
      fegeometry with properties:
    
           NumCells: 4
           NumFaces: 16
           NumEdges: 16
        NumVertices: 16
           Vertices: [16×3 double]
               Mesh: []
    
    

    Plot the imported geometry. The geometry has four cells: one cell representing each mount.

    pdegplot(g)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Find the IDs of the cells containing the points with these coordinates: (50,250,50) and (1450,1200,50).

    cellIDs = findCell(g,[50 250 50; 1450 1200 50])
    cellIDs = 1×2
    
         2     3
    
    

    Show the two points on the geometry plot.

    pdegplot(g,FaceAlpha=0.3,CellLabels="on")
    hold on
    scatter3([50 1450],[250 1200],[50 50],"filled","red")

    Figure contains an axes object. The axes object contains 7 objects of type quiver, text, patch, line, scatter.

    Delete the cells containing the points with the specified coordinates.

    g = deleteCell(g,cellIDs)
    g = 
      fegeometry with properties:
    
           NumCells: 2
           NumFaces: 8
           NumEdges: 8
        NumVertices: 8
           Vertices: [8×3 double]
               Mesh: []
    
    

    Plot the resulting geometry.

    figure
    pdegplot(g,CellLabels="on",FaceAlpha=0.3)

    Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

    Input Arguments

    collapse all

    3-D geometry, specified as an fegeometry object.

    Query point coordinates, specified as an N-by-3 numeric matrix. Here, N is the number of query points.

    Output Arguments

    collapse all

    Cell IDs, returned as an N-by-1 vector of positive integers and NaN values. The function returns positive integers for query points located in a cell of a geometry, and NaN values for points located outside of the geometry. For query points located on a boundary (face, edge, or vertex) and, therefore, belonging to more than one cell, the function returns the lowest cell ID.

    Version History

    Introduced in R2025a