%% Nearest Alpha Shape Boundary Point
% Create a set of 2-D points.

th = (pi/12:pi/12:2*pi)';
x1 = [reshape(cos(th)*(1:5), numel(cos(th)*(1:5)),1); 0];
y1 = [reshape(sin(th)*(1:5), numel(sin(th)*(1:5)),1); 0];
x = [x1; x1+15];
y = [y1; y1];

%
% Create and plot an alpha shape with alpha radius equal to 1.

shp = alphaShape(x,y,1);
plot(shp)
hold on

%
% Compute the nearest shp boundary point to the query point QP. Plot the query point in blue and the nearest boundary neighbor in red.

QP = [6 3];
plot(QP(1),QP(2),'b.','MarkerSize',10)
hold on
I = nearestNeighbor(shp, QP);
plot(shp.Points(I,1),shp.Points(I,2),'r.','MarkerSize',10)

% Copyright 2015 The MathWorks, Inc.