%% Area of Bow Tie
% Analyze a polygon with intersecting boundaries.
% Create a polygon whose boundary contains a self-intersection. By default, the polyshape function splits the boundary into two distinct boundaries in order to create a well-defined polygon.

P = [0 0; 1 1; 1 0; 0 1; 0 0];
pgon = polyshape(P)

%
% Plot the polygon and compute its area.

plot(pgon)
A = area(pgon)

%
% If you do not simplify the original input vertices, the areas of the two triangular regions of the polygon cancel each other out.
%

pgon2 = polyshape(P,'Simplify',false)
A2 = area(pgon2)

% Copyright 2012 The MathWorks, Inc.