# Polygons¶

`scikit-geometry` can handle polygons, as well as polygons with holes. Polygons can be created from lists of points.

```:
```
```import skgeom as sg
from skgeom.draw import draw
```
```:
```
```poly = sg.Polygon([sg.Point2(0, 0), sg.Point2(0, 3), sg.Point2(3, 3)])
```
```:
```
```draw(poly)
``` You may also use lists of coordinates or numpy arrays to construct polygons:

```:
```
```sg.Polygon([[0, 0], [0, 3], [3, 3]])
``` Likewise, you can access a Polygon’s vertices as either a list of `Point2`s or as a numpy array:

```:
```
```list(poly.vertices)
```
```:
```
```[PointC2(0, 0), PointC2(0, 3), PointC2(3, 3)]
```
```:
```
```poly.coords
```
```:
```
```array([[0., 0.],
[0., 3.],
[3., 3.]])
```

We can check wether a given point is inside the polygon (a negative sign means outside, positive means inside):

```:
```
```poly.oriented_side(sg.Point2(1, 2))
```
```:
```
```Sign.NEGATIVE
```
```:
```
```poly.oriented_side(sg.Point2(2, 1))
```
```:
```
```Sign.POSITIVE
```

Calculate the bounding box

```:
```
```poly.bbox()
```
```:
```
```Bbox_2(0, 0, 3, 3)
```

Compute the area of the polygon. Note: the sign depends on the order of the polygon (clockwise → negative, counter-clockwise → positive).

```:
```
```poly.area()
```
```:
```
```-4.5
```
```:
```
```poly.orientation() == sg.Sign.CLOCKWISE
```
```:
```
```True
```
```:
```
```poly.is_convex()
```
```:
```
```True
```
```:
```
```poly.is_simple()
```
```:
```
```True
```

## Polygon with Holes¶

We can cut out an area of a Polygon by adding one or multiple holes.

```:
```
```hole = sg.Polygon([
sg.Point2(1.0, 2.0),
sg.Point2(1.0, 2.5),
sg.Point2(0.5, 2.5),
sg.Point2(0.5, 2.0)]
)
poly_with_hole = sg.PolygonWithHoles(poly, [hole])
```
```:
```
```draw(poly_with_hole)
``` ### Boolean operations on Polygons¶

scikit-geometry supports boolean operations on polygons, such as computing the union, difference and intersection between two polygons (or polygons with holes).

```:
```
```poly1 = sg.Polygon([sg.Point2(3, 0), sg.Point2(3, 3), sg.Point2(0, 3), sg.Point2(0, 0)])
poly2 = sg.Polygon([sg.Point2(5, 2), sg.Point2(5, 5), sg.Point2(2, 5), sg.Point2(2, 2)])
```
```:
```
```draw(poly1, facecolor='red')
draw(poly2, facecolor='blue')
``` ```:
```
```from skgeom import boolean_set
```
```:
```
```draw(boolean_set.join(poly1, poly2))
``` ```:
```
```draw(boolean_set.difference(poly1, poly2))
``` ```:
```
```draw(boolean_set.symmetric_difference(poly1, poly2))
``` ```:
```
```draw(boolean_set.intersect(poly1, poly2))
``` ## Minkowski Sum of 2 Polygons¶

We can compute the minkowski sum of two polygons easily (i.e. offsetting a polygon with another polygon).

```:
```
```from skgeom import minkowski
```
```:
```
```p1 = sg.Polygon([sg.Point2(-1, -1), sg.Point2(1, -1), sg.Point2(0, 1)])
p2 = sg.Polygon([sg.Point2(3, -1), sg.Point2(5, -1), sg.Point2(5, 1), sg.Point2(3, 1)])
```
```:
```
```draw(p1, facecolor='red')
draw(p2, facecolor='blue')
``` ```:
```
```result = minkowski.minkowski_sum(p1, p2)
draw(result)
``` 