%% Fill Holes in 2-D Alpha Shape
% Create an alpha shape by specifying its alpha radius, and fill the holes in an alpha shape.
%
% Create and plot a 2-D set of points.

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

%
% Compute an alpha shape for the point set using an alpha radius of 1.

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

% An alpha radius of 1 results in an alpha shape with two regions containing holes. To suppress the small holes in the alpha shape, you can specify a HoleThreshold by estimating the area of the largest hole to fill. To fill all holes in the shape, you can assign an arbitrarily large value to HoleThreshold.
%
% Create a new alpha shape that suppresses the holes by specifying a HoleThreshold of 15.

shp = alphaShape(x,y,1,'HoleThreshold',15);
plot(shp)

% Copyright 2012 The MathWorks, Inc.