Polygon3
raw JSON → 3.0.9.1 verified Fri May 01 auth: no python
A Python 3 library for handling polygonal shapes in 2D, including intersection, union, and clipping operations. Current version 3.0.9.1, with maintenance updates as needed.
pip install polygon3 Common errors
error ModuleNotFoundError: No module named 'polygon' ↓
cause Installed 'polygon3' but tried to import 'polygon3'.
fix
Use
from polygon import Polygon after installing polygon3. error AttributeError: module 'polygon' has no attribute 'Polygon' ↓
cause Installed the wrong 'polygon' package (from PyPI), which is different.
fix
Uninstall 'polygon' and install 'polygon3' with
pip install polygon3. Warnings
breaking Polygon3 is a fork of the original 'polygon' library (Python 2). Do not confuse with 'polygon' package; import from 'polygon' (not 'polygon3') after installation. ↓
fix Install with `pip install polygon3`, then import as `from polygon import Polygon`.
gotcha Coordinates must be in clockwise or counterclockwise order; self-intersecting or malformed polygons may cause incorrect results or crashes. ↓
fix Ensure polygons are simple and vertices are ordered consistently.
Imports
- Polygon
from polygon import Polygon
Quickstart
from polygon import Polygon
# Create two polygons
poly1 = Polygon([(0,0), (1,0), (1,1), (0,1)])
poly2 = Polygon([(0.5,0.5), (1.5,0.5), (1.5,1.5), (0.5,1.5)])
# Compute intersection
intersection = poly1 & poly2
print(f"Intersection area: {intersection.area()}")
# Compute union
union = poly1 | poly2
print(f"Union area: {union.area()}")