%% Remove Polygon Boundary
% Create a polygon made up of two triangles, and then remove the triangle whose centroid is nearer to the point (4,2). You can use the sortboundaries function to access the boundary index corresponding to the triangle closer to the reference point, which is 1 after sorting.

x1 = [0 1 2];
y1 = [0 1 0];
x2 = [2 3 4];
y2 = [1 2 1];
polyin = polyshape({x1,x2},{y1,y2});
plot(polyin)
polysort = sortboundaries(polyin,'centroid','ascend','ReferencePoint',[4 2]);
polyout = rmboundary(polysort,1);
plot(polyout)

% Copyright 2012 The MathWorks, Inc.