- zh_CN 简体中文
This project implements a polygon pairwise clustering algorithm based on the No-Fit Polygon (NFP) concept, as described in the paper "A new approach for sheet nesting problem using guided cuckoo search and pairwise clustering" by Ahmed Elkeran (2013). The algorithm computes the optimal placement of two polygons by considering their rotations and translations to maximize clustering efficiency, focusing on concave NFPs. It uses the shapely library for geometric operations and is designed for applications in sheet nesting and computational geometry.
- Computes No-Fit Polygons (NFPs) for two polygons.
- Supports multiple rotation angles for both polygons.
- Calculates cluster values based on convex hull differences and union areas.
- Visualizes the resulting polygon placements using a plotting utility.
- Clone the repository:
git clone https://github.com/la667-j/PolygonPairwise.git cd PolygonPairwise git clone https://github.com/la667-j/SimpleNFP.git - Install the required dependencies:
Note: The
pip install shapely
utils.Point,utils.Geometry,utils.Plot, andnfpmodules are assumed to be custom implementations. Ensure these are available in your project directory or implement them as needed.
- Define two polygons using the
Pointclass and createPwPolygonobjects. - Specify allowed rotation angles for each polygon.
- Run the clustering algorithm to obtain the optimal placement.
- Visualize the results using the
Plotutility.
from Pairwise.polygon_pairwise import PolygonPairwise
from Pairwise.PwPolygon import PwPolygon
from utils.Point import Point
from utils import Plot
pointsA = [Point(0, 0), Point(10, -5), Point(20, 2), Point(30, -10), Point(44, 5),
Point(25, 20), Point(15, 20), Point(10, 10), Point(0, 10), Point(0, 0)]
pointsB = [Point(0, 0), Point(10, -5), Point(20, 10), Point(15, 5), Point(0, 0)]
pwPolygonA = PwPolygon(pointsB)
rotsA = [0, 45, 90, 135, 180] # A allowed angles
pwPolygonB = PwPolygon(pointsB)
rotsB = [0, 45, 90, 135, 180] # B allowed angles
result = PolygonPairwise.cluster(pwPolygonA, pwPolygonB, rotsA, rotsB)
if len(result) == 0:
print("No concave NFP found")
else:
Plot.plot_polygons_with_shifted_pair(pwPolygonA.points, pwPolygonB.points, result[0].points, result[1].points)-
Example1: The final placement of the polygons after clustering.

-
Example2: The final placement of the polygons after clustering.

-
Example3: The final placement of the polygons after clustering.

This implementation is based on the following paper:
Elkeran, A. (2013). A new approach for sheet nesting problem using guided cuckoo search and pairwise clustering. Engineering Optimization, 45(6), 739–756. DOI: 10.1080/0305215X.2012.709517.
This project is licensed under the MIT License - see the LICENSE file for details.