ID = pointLocation(TR,P)
returns the IDs of the triangles or tetrahedra enclosing the query points in
P. Each row in the matrix P contains the
coordinates of a query point.
ID = pointLocation(TR,x,y)
specifies the x-coordinates and y-coordinates
of 2-D query points as separate column vectors.
ID = pointLocation(TR,x,y,z)
specifies the x-coordinates, y-coordinates,
and z-coordinates of 3-D query points as separate column
vectors.
[ID,B] =
pointLocation(___)
also returns the barycentric coordinates of each query point with respect to its
enclosing triangle or tetrahedron for any of the previous syntaxes.
Find the barycentric coordinates of each query point with respect to its enclosing triangle. For points outside the triangulation, pointLocation returns NaN.
[~,B] = pointLocation(TR,P)
B = 6×3
0.1667 0.2500 0.5833
0.1250 0.3750 0.5000
0 0 1.0000
0.5000 0.5000 0
0 1.0000 0
NaN NaN NaN
Use the barycentric coordinates to determine if a query point lies on a vertex, on an edge, in a triangle, or outside the triangulation. If a query point is located on a vertex, one of its barycentric coordinates is 1 and the other coordinates are 0. If a query point is located on an edge but does not coincide with a vertex, one of its barycentric coordinates is 0 and none of the other coordinates is 1. For query points outside of the triangulation, the barycentric coordinates are NaN.
M = size(B,1);
loc = cell(M,2);
tol = 1e-10;
for i = 1:M
b = B(i,:);
loc{i,1} = P(i,1:2);
if ismembertol(1,b,tol)
loc{i,2} = "Vertex";
elseif ismembertol(0,b,tol)
loc{i,2} = "Edge";
elseif isnan(B(i))
loc{i,2} = "Outside";
else
loc{i,2} = "Triangle";
endend
loc
Query points, specified as a 2-column matrix (2-D) or a 3-column matrix
(3-D). P contains the x-coordinates,
y-coordinates, and (possibly)
z-coordinates of the query points.
Data Types: double
x-coordinates of query points, specified as a column
vector.
Data Types: double
y-coordinates of query points, specified as a column
vector.
Data Types: double
z-coordinates of query points, specified as a column
vector.
Triangle or tetrahedra IDs of the triangles or tetrahedra enclosing the
query points, returned as a column vector. A triangle or tetrahedron ID is
the row number of the corresponding triangle or tetrahedron in the
ConnectivityList property.
If a query point lies on the boundary of two or more triangles or
tetrahedra, then the largest ID is returned.
ID contains NaN values for points
that are not located in a triangle or tetrahedron of the
triangulation.
Data Types: double
Barycentric coordinates of each query point with respect to its enclosing
triangle or tetrahedron, returned as a 3-column matrix (2-D) or a 4-column
matrix (3-D).
If the query point is on a vertex, then one of its barycentric
coordinates is 1 and the others are 0.
If the query point is on an edge, then one of its barycentric
coordinates is 0 and none of the others is 1.
If the query point is in a triangle, then all of its barycentric
coordinates are nonzero.
If the query point outside the triangulation, all barycentric
coordinates are NaN.
These syntaxes using DelaunayTri objects as Delaunay
triangulation representations DT are not recommended:
ID = pointLocation(DT,P) returns the indices
ID of the enclosing simplex (triangle/tetrahedron)
for each query point location in matrix P. The enclosing
simplex for point P(k,:) is ID(k).
pointLocation returns
NaN for all points outside the convex hull.
ID = pointLocation(DT,x,y) and ID =
pointLocation(DT,x,y,z) allow the query point locations to be
specified in column vector format when working in 2-D and 3-D.
[ID,B] = pointLocation(...) returns the barycentric
coordinates BC.