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

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

% The first, fifth, and sixth vertices of the difference originated in poly1, since the corresponding values in shapeID are 1. These vertices are the first, third, and fourth vertices in the property poly1.Vertices, respectively, since the corresponding values in vertexID are 1, 3, and 4. Similarly, the third vertex of the difference originated in poly2, and is the fourth vertex in the property poly2.Vertices. The second and fourth vertices of the difference were created from the subtraction computation because the corresponding values of shapeID and vertexID are 0.
% Copyright 2012 The MathWorks, Inc.