Main Content

Polygon Set Logic

Polygon set operations are used to answer a variety of questions about logical relationships of vector data polygon objects. Standard set operations include intersection, union, subtraction, and an exclusive OR operation. The polybool function performs these operations on two sets of vectors, which can represent x-y or latitude-longitude coordinate pairs. In computing points where boundaries intersect, interpolations are carried out on the coordinates as if they were planar. Here is an example that shows all the available operations.

Intersection, union, subtraction, and exclusive OR operations on two polygons. The intersection contains the polygon regions that overlap. The union contains the combined polygon regions. The exclusive OR contains the regions of the polygons that do not overlap. The subtraction contains the first polygon minus any part of the second polygon that overlaps the first polygon.

The result is returned as NaN-clipped vectors by default. In cases where it is important to distinguish outer contours of polygons from interior holes, polybool can also accept inputs and return outputs as cell arrays. In the cell array format, a cell array entry starts with the list of points making up the outer contour. Subsequent NaN-clipped faces within the cell entry are interpreted as interior holes.