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

    %% Find Number of Regions in 2-D Alpha Shape
% Create and plot 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];
plot(x,y,'.')
axis equal 

%%
% Create an alpha shape using an alpha radius of 7 and query the
% number of distinct regions in the shape.
shp = alphaShape(x,y,7);
nregions = numRegions(shp)

%%
% Use a smaller alpha radius of 2.5 to better capture the boundary and then retrieve the new
% number of distinct regions.
shp.Alpha = 2.5;
nregions = numRegions(shp)

%%
% Plot the alpha shape to check the boundary quality. 
plot(shp)