%% Vertex Mapping
% Create two polygons, and compute and plot their union. Display the vertex coordinates of the union 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] = union(poly1,poly2);
plot(polyout)
axis equal
[polyout.Vertices shapeID vertexID]

% The first and last vertices of the union 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 union originated in poly2, and they are the second and third vertices in the property poly2.Vertices, respectively.
% Copyright 2012 The MathWorks, Inc.