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

    %% Alpha Shapes
% The alpha shape of a set of points is a _generalization_ of the convex
% hull and a subgraph of the Delaunay triangulation. That is, the convex
% hull is just one type of alpha shape, and the full family of alpha shapes
% can be derived from the Delaunay triangulation of a given point set.

% Copyright 2015 The MathWorks, Inc.


x = gallery('uniformdata',20,1,10);
y = gallery('uniformdata',20,1,20);
plot(x,y,'r.','MarkerSize',20)
hold on
shp = alphaShape(x,y,100);
plot(shp)
title('Convex Alpha Shape')
hold off

%%
% Unlike the convex hull, alpha shapes have a parameter that controls the
% level of detail, or how tightly the boundary fits around the point set.
% The parameter is called _alpha_ or the _alpha radius_. Varying the alpha
% radius from 0 to |Inf| produces a set of different alpha shapes unique
% for that point set.

plot(x,y,'r.','MarkerSize',20)
hold on
shp = alphaShape(x,y,.5);
plot(shp)
title('Nonconvex Alpha Shape')
hold off

%%
% Varying the alpha radius can sometimes result in an alpha shape with
% multiple regions, which might or might not contain holes. However, the
% |alphaShape| function in MATLAB(R) always returns regularized alpha
% shapes, which prevents isolated or dangling points, edges, or faces.

plot(x,y,'r.','MarkerSize',20)
hold on
shp = alphaShape(x,y);
plot(shp)
title('Alpha Shape with Multiple Regions')
hold off