%% 3-D Query
% Compute the nearest neighbors in a 3-D triangulation.
% Create a 3-D Delaunay triangulation.

P = [1 1 0; -1 1 0; -1 -1 0; 1 -1 0; 0 0 2; 0 0 0];
TR = delaunayTriangulation(P);

%
% Plot the triangulation and a query point.

tri = TR(:,:);
trisurf(tri,P(:,1),P(:,2),P(:,3),'FaceAlpha',0.5)
hold on
x = 0;
y = -0.5;
z = 2;
plot3(x,y,z,'k*')

%
% Find the coordinates of the nearest neighbor to the query point.

ID = nearestNeighbor(TR,x,y,z);
C = TR.Points(ID,:)

% Copyright 2015 The MathWorks, Inc.