%% Discard Small Regions of 3-D Alpha Shape
% Control the number of regions of an alpha shape by setting a region threshold.
% Create and plot a set of 3-D points.

[x1,y1,z1] = sphere(24);
x1 = x1(:);
y1 = y1(:);
z1 = z1(:);
x2 = x1+5;
[x3,y3,z3] = sphere(5);
x3 = x3(:)+5;
y3 = y3(:);
z3 = z3(:)+25;
P = [x1 y1 z1; x2 y1 z1; 0.25*x3 0.25*y3 0.25*z3];
P = unique(P,'rows');
plot3(P(:,1),P(:,2),P(:,3),'.')
axis equal
grid on

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

shp = alphaShape(P,1);
plot(shp)
axis equal

% In this case, the alpha shape produces a small region above the two equal-sized spheres. To suppress this region, you can specify a RegionThreshold by estimating its volume.
%
% Specify a RegionThreshold of 2. The resulting shape contains only the two larger regions.

shp.RegionThreshold = 2;
plot(shp)
axis equal

% Copyright 2015 The MathWorks, Inc.