- zh_CN 简体中文
This repository provides Python code for computing and visualizing No-Fit Polygons (NFPs) for irregular nesting problems. It includes implementations for calculating the NFP of a single polygon (self-NFP) and the NFP between two polygons, along with Plotly-based visualization functions to display the results.but not support concavities, holes, interlocks.
- Compute the self-NFP of a single polygon using
GetNfp. - Compute the NFP between two polygons (A and B) using
GetNfp2. - Visualize the original polygons, NFP results, and translated polygons using Plotly.
- Clone the repository:
git clone https://github.com/la667-j/SimpleNFP.git cd SimpleNFP - Install required Python packages:
pip install plotly shapely
- Ensure the
utils.Geometryandnfp.Pointmodules are available, providing thePointclass and functions likemonotone_chain_convex_hullandremove_duplicate_points.
The code includes two main functions for NFP computation and two visualization functions:
GetNfp(polygon_points): Computes the self-NFP for a single polygon.GetNfp2(polygon_a, polygon_b): Computes the NFP between two polygons.plot_polygons(original_points, nfp_points): Plots the original polygon and its NFP.plot_polygons_with_translated_b(points_a, points_b, nfp_points): Plots polygons A, B, their NFP, and 3-4 translated versions of polygon B.
from nfp import Nfp
from nfp.Point import Point
from utils import Plot
# Define polygons
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(20, 0), Point(10, 15), Point(0, 0)]
# Compute and plot self-NFP for polygon A
result = Nfp.GetNfp(pointsA)
Plot.plot_polygons(pointsA, result)
# Compute and plot NFP of B around A
result = Nfp.GetNfp2(pointsA, pointsB)
Plot.plot_polygons_with_translated_b(pointsA, pointsB, result)
# Compute and plot NFP of A around B
result = Nfp.GetNfp2(pointsB, pointsA)
Plot.plot_polygons_with_translated_b(pointsB, pointsA, result)- Blue: Original polygon A
- Red: NFP result
- Green/Purple/Orange: Translated versions of polygon A based on 3-4 NFP points
- Blue: Polygon A
- Green: Polygon B
- Red: NFP result
- Purple/Orange/Cyan/Magenta: Translated versions of polygon B based on 3-4 NFP points
- Blue: Polygon B
- Green: Polygon A
- Red: NFP result
- Purple/Orange/Cyan/Magenta: Translated versions of polygon A based on 3-4 NFP points
This implementation is inspired by the following paper:
- L Huyao, H Yuanjun, J A Bennell. The irregular nesting problem: a new approach for nofit polygon calculation.


