www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/InteriorOf2DAlphaShapeExample.m
%% Query Points Inside and Outside of 2-D Alpha Shape % Create 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]; %% % Create and plot an alpha shape using an alpha radius of 2.5. shp = alphaShape(x,y,2.5); plot(shp) %% % Create a Cartesian grid of query points near the alpha shape. [qx, qy] = meshgrid(-10:2:25, -10:2:10); %% % Check if the query points are inside of the alpha shape, and if so, plot % them red. Plot the query points that lie outside of the alpha shape in blue. in = inShape(shp,qx,qy); plot(shp) hold on plot(qx(in),qy(in),'r.') plot(qx(~in),qy(~in),'b.')