pointLocation
Triangle or tetrahedron enclosing point
Syntax
Description
Examples
Find the triangles of a triangulation that enclose a set of query points.
Define the points and connectivity of a triangulation.
TP = [2.5 8.0;
6.5 8.0;
2.5 5.0;
6.5 5.0;
1.0 6.5;
8.0 6.5];
C = [5 3 1;
3 2 1;
3 4 2;
4 6 2];
TR = triangulation(C,TP);Define two query points.
P = [2.25 7; 6 6.5];
Plot the triangulation and the query points.
triplot(TR) hold on plot(P(:,1),P(:,2),"k*") ylim([4 9]) xlim([0 9])

Determine the IDs of the triangles that enclose each query point.
ID = pointLocation(TR,P)
ID = 2×1
1
3
Highlight the triangles that enclose the query points in red.
triplot(TR.ConnectivityList(ID,:),TP(:,1),TP(:,2),"r")
Find the tetrahedra of a 3-D triangulation that enclose a set of query points.
Create a Delaunay triangulation from a set of 3-D points.
rng default
x = rand([20 1]);
y = rand([20 1]);
z = rand([20 1]);
TR = delaunayTriangulation(x,y,z);Find the IDs of the tetrahedra that enclose the query points, and compute the barycentric coordinates of the query points.
P = [0.7 0.6 0.3;
0.5 0.5 0.5];
[ID,B] = pointLocation(TR,P)ID = 2×1
9
8
B = 2×4
0.2046 0.0893 0.5721 0.1340
0.1900 0.1495 0.6422 0.0183
Determine which query points are located on edges and vertices of the triangles of a 2-D triangulation.
Define the points and connectivity of a triangulation.
TP = [2.5 8.0;
6.5 8.0;
2.5 5.0;
6.5 5.0;
1.0 6.5;
8.0 6.5];
C = [5 3 1;
3 2 1;
3 4 2;
4 6 2];
TR = triangulation(C,TP);Define the query points.
P = [2.25 7;
6 6.5;
2.5 8.0;
4.5 5.0;
8 6.5
7.5 7.5];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.0000
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"; end end loc
loc=6×2 cell array
{[ 2.2500 7]} {["Triangle"]}
{[ 6 6.5000]} {["Triangle"]}
{[ 2.5000 8]} {["Vertex" ]}
{[ 4.5000 5]} {["Edge" ]}
{[ 8 6.5000]} {["Vertex" ]}
{[7.5000 7.5000]} {["Outside" ]}
Plot the triangulation and the query points.
triplot(TR) hold on plot(P(:,1),P(:,2),'k*')

Input Arguments
Triangulation representation, specified as a scalar triangulation or delaunayTriangulation
object.
Data Types: triangulation | delaunayTriangulation
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.
Data Types: double
Output Arguments
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.
Data Types: double
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.
Version History
Introduced in R2013aThese syntaxes using DelaunayTri objects as Delaunay
triangulation representations DT are not recommended:
ID = pointLocation(DT,P)returns the indicesIDof the enclosing simplex (triangle/tetrahedron) for each query point location in matrixP. The enclosing simplex for pointP(k,:)isID(k).pointLocationreturnsNaNfor all points outside the convex hull.ID = pointLocation(DT,x,y)andID = 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 coordinatesBC.
Use delaunayTriangulation instead.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)