%% Vertex Mapping
% Create two polygons, and compute and plot their exclusive OR. Display the vertex coordinates of the exclusive OR and the corresponding vertex mapping information.

poly1 = polyshape([0 0 1 1],[1 0 0 1]);
poly2 = translate(poly1,[0.5 0]);
[polyout,shapeID,vertexID] = xor(poly1,poly2);
plot(polyout)
[polyout.Vertices shapeID vertexID]

% There are two boundaries in the exclusive OR, separated by a row of NaN values in the Vertices property. For example, consider the first boundary in the array. The first and last vertices of the exclusive OR originated in poly1, since the corresponding values in shapeID are 1. These vertices are the first and fourth vertices in the property poly1.Vertices, respectively, since the corresponding values in vertexID are 1 and 4. Similarly, the second and third vertices of the exclusive OR originated in poly2, and they are also the first and fourth vertices in the property poly2.Vertices, respectively.
% Copyright 2012 The MathWorks, Inc.