%% Find Alpha Spectrum for 2-D Point Cloud
% Create and plot 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];
plot(x,y,'.')
axis equal

%
% Create an alpha shape for the point cloud using the default alpha radius.

shp = alphaShape(x,y);

%
% Find the spectrum of critical alpha values that produces unique alpha shapes for the point cloud.

alphaspec = alphaSpectrum(shp);

%
% Plot the alpha shape corresponding to the smallest alpha value in the spectrum.

shp.Alpha = alphaspec(length(alphaspec));
plot(shp)

%
% Compare this alpha shape to the one produced by the next smallest critical alpha value. The alpha shapes are unique.

shp.Alpha = alphaspec(length(alphaspec)-1);
plot(shp)

% Copyright 2015 The MathWorks, Inc.