Skip to content

Provide a simple method for calculating no-fit polygon,not support concavities, holes, interlocks.简单计算nofit-polygon

Notifications You must be signed in to change notification settings

la667-j/SimpleNFP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

No-Fit Polygon (NFP) Computation and Visualization

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.

Features

  • 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.

Installation

  1. Clone the repository:
    git clone https://github.com/la667-j/SimpleNFP.git
    cd SimpleNFP
  2. Install required Python packages:
    pip install plotly shapely
  3. Ensure the utils.Geometry and nfp.Point modules are available, providing the Point class and functions like monotone_chain_convex_hull and remove_duplicate_points.

Usage

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.

Example

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)

Visualizations

Self-NFP of Polygon A

Self-NFP of Polygon A

  • Blue: Original polygon A
  • Red: NFP result
  • Green/Purple/Orange: Translated versions of polygon A based on 3-4 NFP points

NFP of Polygon B around Polygon A

NFP of B around A

  • Blue: Polygon A
  • Green: Polygon B
  • Red: NFP result
  • Purple/Orange/Cyan/Magenta: Translated versions of polygon B based on 3-4 NFP points

NFP of Polygon A around Polygon B

NFP of A around B

  • Blue: Polygon B
  • Green: Polygon A
  • Red: NFP result
  • Purple/Orange/Cyan/Magenta: Translated versions of polygon A based on 3-4 NFP points

Reference

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.

About

Provide a simple method for calculating no-fit polygon,not support concavities, holes, interlocks.简单计算nofit-polygon

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages