tamasmeszaros / libnest2d

2D irregular bin packaging and nesting library written in modern C++
GNU Lesser General Public License v3.0
315 stars 104 forks source link

Multiple random results? #22

Open noamgat opened 4 years ago

noamgat commented 4 years ago

Hi, For my use case, I would like to get multiple (hopefully significantly different) nestings of polygons in a certain space. Is this possible / documented somewhere?

tamasmeszaros commented 4 years ago

Hello! This is not easy but you can change the object function of the NfpPlacer. It takes an item as the argument and you can evaluate its transformation. The default object function simply calculates the distance between the bin center and the item's bounding box center and chooses the placement where its the shortest. A normalized distance is returned as the score.

You could use different object functions like the smallest area of the convex hull of all the items in the bin (including the one received as argument). You can try to mix different measures to create some sort of score, or repeat the arrangement and choose the one which suits your purpose the most.

Currently there is one major difficulty which is to keep the items in the bin. Normally that should be taken care of the framework but currently you need to reject out-of-bin positions in the object function with some penalty to the returned score.