pointLocation

Finds the triangle or tetrahedron of a triangulation that contains each query point.

Category: Mathematics > Computational Geometry

Syntax

ti = pointLocation(TR, P)

Index of the simplex containing each row of P.

[ti, bc] = pointLocation(TR, P)

Also returns the barycentric coordinates of the points in those simplices.

Description

This is a point-in-triangle search over the whole mesh. A point on a shared edge belongs to more than one triangle and one of them is returned. The barycentric output is the base of linear interpolation: multiply bc by the values stored at the three vertices of triangle ti to interpolate.

Input arguments

TR
A triangulation, delaunayTriangulation or DelaunayTri object.
P
Query points, one per row.

Output arguments

ti
Column vector of simplex indices. A point outside the triangulation gives NaN.
bc
Matrix of barycentric coordinates, one row per point.

Example

Locate a point inside and outside

x = [0 1 1 0 0.5]';
y = [0 0 1 1 0.5]';
DT = delaunayTriangulation(x, y);
[ti, bc] = pointLocation(DT, [0.9 0.5; 5 5])
Output
ti = 2×1

     1
   NaN
bc = 2×3

    0.2000    0.4000    0.4000
       NaN       NaN       NaN

See also

nearestNeighbor cartesianToBarycentric delaunayTriangulation inpolygon