%% Enclosing Triangles
% 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)

%
% Highlight the triangles that enclose the query points in red.

triplot(TR.ConnectivityList(ID,:),TP(:,1),TP(:,2),'r')

% Copyright 2015 The MathWorks, Inc.