Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Set operations on polygonal regions

`polybool`

is not recommended. Use `polyshape`

instead.

**To replace calls to polybool, create polyshape
objects to represent the shapes, call the appropriate polyshape
object function for the equivalent Boolean operation, and then call the
polyshape
boundary object function. For example, this call to
polybool specifies the union operation as the first argument.
**

[Cx,Cy] = polybool('union',Ax,Ay,Bx,By)

`polyshape`

objects for each shape
and then use the `union`

object function associated with the
`polyshape`

object. `polyshape`

supports the
Boolean operations supported by `polybool`

: union, intersection,
subtraction, and exclusive OR. Use the `polyshape`

`boundary`

object function to return `Cx`

and
`Cy`

. See `polyshape`

for a complete list of object functions, including `plot`

.
A = polyshape(Ax,Ay,'Simplify',false); B = polyshape(Bx,By,'Simplify',false); C = union(A,B); [Cx,Cy] = boundary(C);

`polybool`

and the output from the call to
`boundary`

, because there is no single right answer. (Even in a
simple one-region polygon, the vertices can be permuted cyclically without affecting the
underlying geometry.) In addition, if the geometries of the inputs are not perfectly
clean (free from self-intersections, etc.), then the `polyshape`

`union`

operation may make small changes that are not necessarily
performed in `polybool`

.```
[x,y] =
polybool(flag,x1,y1,x2,y2)
```

`[`

performs
the polygon set operation identified by `x`

,`y`

] =
polybool(`flag`

,`x1`

,`y1`

,`x2`

,`y2`

)`flag`

.
The result is output using the same format as the input. Geographic
data that encompasses a pole cannot be used directly. Use `flatearthpoly`

to convert polygons that contain
a pole to Cartesian coordinates.

Most Mapping
Toolbox™ functions adhere to the convention
that individual contours with clockwise-ordered vertices are external
contours and individual contours with counterclockwise-ordered vertices
are internal contours. Although the `polybool`

function
ignores vertex order, follow this convention when creating contours
to ensure consistency with other functions.

Numerical problems can occur when the polygons have a large offset from the origin. To avoid this issue, translate the coordinates to a location closer to the origin before performing the operation. Then, undo the translation after completing the operation. For example:

`[x,y] = polybool(flag,x1-xt,y1-yt,x2-xt,y2-yt);`

`x = x+xt;`

`y = y+yt;`

`bufferm`

| `flatearthpoly`

| `ispolycw`

| `poly2ccw`

| `poly2cw`

| `poly2fv`

| `polyjoin`

| `polyshape`

| `polysplit`