www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/NearestAlphaShapeBoundaryPointExample.m

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

% Copyright 2015 The MathWorks, Inc.

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)