Two-dimensional special-shaped boxing, typesetting and nesting system and method
By developing a two-dimensional irregular box packing and nesting algorithm, the problem of efficient nesting of irregular objects in two-dimensional space was solved, realizing intuitive import and export of DXF files and automated cutting of CNC lathes, thus improving space utilization and cutting efficiency.
Patent Information
- Application Number
- CN202511180589.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-22
- Publication Date
- 2025-12-02
AI Technical Summary
Existing technologies struggle to efficiently solve the problem of packing irregularly shaped objects in two-dimensional space, especially lacking intuitiveness and consistency when importing and exporting DXF files, and making it difficult to achieve automated cutting and processing on CNC lathes.
A two-dimensional irregular box layout and nesting algorithm was developed, which can read and parse the graphic coordinates of irregular components and original plates from DXF files, obtain the minimum outer rectangle, perform layout cutting and merging, and generate DXF files and G-code files, supporting automated machining on CNC lathes.
It enables clear and intuitive layout within a given two-dimensional space, maximizes space utilization, reduces waste, and supports consistent import and export of DXF files and automated cutting on CNC lathes.
Smart Images

Figure CN121052232A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical fields of two-dimensional irregular box layout and visualization, DXF file reading, parsing and generation, G-code generation and CNC lathe automated processing, specifically to a system and method for two-dimensional irregular box layout and nesting based on irregular components and irregular original plates. Background Technology
[0002] Packing issues are widespread in logistics transportation, including truck loading, container loading, pallet loading, as well as in factory and enterprise processes such as material cutting, finished product packaging, and facility layout planning. In the current economic environment, inventory and logistics activities are increasingly demonstrating their importance, making the reduction of inventory and logistics costs a crucial and pressing issue.
[0003] The 2D rectangular packing problem (2DRP) is a common optimization problem widely used in logistics, material cutting, and other fields. The goal of this problem is to arrange a series of rectangular and irregularly shaped objects in a given two-dimensional space as efficiently as possible to maximize space utilization or minimize waste. This is a typical NP-hard problem, meaning that finding a fast and accurate solution is difficult.
[0004] Implementing 2D irregular packing technology is even more challenging. There are generally two main strategies: feasible solution-based packing and overlap removal-based packing. Feasible solution-based packing ensures that parts never overlap during the packing process, while overlap removal-based packing allows overlap between parts, employing strategies to reduce the degree of overlap during the search process until a feasible solution is found.
[0005] For two-dimensional packing problems, a dimensional approach is typically used, which involves providing the dimensional parameters of the original board and components for layout. Industrial applications usually use DXF format files for both the original board and the components. If it were possible to directly import, read, and parse DXF files, and then directly export the DXF file after generating the layout result, maintaining consistent input and output file formats, the process would be much more convenient and efficient.
[0006] If the results of two-dimensional packing and nesting can be exported as DXF files simultaneously with the G-code files required for automated CNC lathe machining, they can be directly applied to CNC lathe cutting processes, thus broadening their application scope. Summary of the Invention
[0007] The purpose of this invention is to achieve two-dimensional irregular-shaped box layout and nesting. It realizes layout and nesting based on irregular-shaped components and original plates. It reads and parses the graphic coordinate series (including lines, arcs, circles, and component numbers) of each component from the component DXF file; it reads and parses the graphic coordinate series (including closed shapes composed of lines and arcs) of the original plate from the original plate DXF file; it obtains the minimum outer rectangle of each component, and within the closed graphic outline of the original plate, firstly, it achieves two-dimensional box layout based on the minimum outer rectangle of each component; then, it cuts the irregular-shaped original plate area. It combines and merges components to achieve packing and layout based on irregularly shaped original plates; further, it performs graphic operations such as movement and rotation to nest the graphic coordinates of each component into the smallest outer rectangle of the previously laid-out components, achieving nesting based on irregularly shaped components; all nesting results can be exported as DXF files or G-code files for automated cutting and processing on CNC lathes; it realizes clear, intuitive, and space-maximizing nesting based on irregularly shaped original plates and components within a given two-dimensional space, maximizing space utilization or minimizing waste.
[0008] To achieve this objective, this invention has carried out a complete set of research and development processes, including the development of a two-dimensional irregular box packing and nesting algorithm, DLL encapsulation, web service interface development and release, web-side calling and web-based application system development, and desktop-side calling and desktop-based application system development.
[0009] The process involves reading and parsing the graphic coordinate series (including straight lines, arcs, circles, and component numbers) of each component from the component DXF file. Each component is a closed shape whose outline is composed of straight lines, arcs, etc., and whose interior may contain closed shapes such as circles and rectangles. Each component has a unique ID number, which is used to quickly locate and identify each component in the DXF file exported from the layout and nesting results. The graphic of each component can be a regular rectangle or any irregular shape.
[0010] The process involves reading and parsing the graphic coordinate series (including closed graphics composed of straight lines, arcs, etc.) from the original DXF file; the graphic of the original board can be a regular rectangle or an arbitrary irregular shape.
[0011] In the above technical solution, after obtaining the minimum outer rectangle of each component from the component's graphic coordinate series (including closed graphics composed of straight lines, arcs, etc.), binning and layout based on the component's outer rectangle is implemented. The specific method is as follows:
[0012] Process 1: Initialize an area space with an area equal to that of the original plate's outer rectangle, which is used to arrange the outer rectangle targets of each component;
[0013] Step 2: For the minimum enclosing rectangle of all components, sort them in descending order of area to generate a rectangular queue of components.
[0014] Step 3: Pop the largest rectangle from the queue and arrange it in the space of the original plate rectangle. Place it in the lower left corner of the rectangle. There are two arrangement directions: horizontal and vertical. Choose the appropriate direction according to the length-width ratio of the component rectangle and the original plate rectangle.
[0015] Step 4: After the rectangular components are arranged, the original rectangular area of the board is divided into three areas. This system adopts a "one-cut" technical solution, which can minimize the number of times the original board is cut and rotated, and maximize the space utilization of the original board.
[0016] Step 5: The original board is cut into three areas: horizontally: lower left area (cut area), lower right area (uncut area), and the entire upper area (uncut area); or vertically: lower left area (cut area), upper left area (uncut area), and the entire right side area (uncut area).
[0017] Step 6: Sort the uncut areas from largest to smallest area, and take the largest area as the new original board area; pop the new largest rectangle from the component rectangle queue as the rectangle to be laid out; repeat the above process recursively until all component rectangles are laid out; at this point, the boxing layout based on the component outer rectangle is realized.
[0018] In the above technical solution, after completing the box layout based on the outer rectangle of the component, the box layout based on the irregular graphic outline of the original board is realized. The specific method is as follows:
[0019] Process 1: Based on the original board's own graphic outline, extract the horizontal and vertical lines, and divide the original board's outer rectangular area into a series of small rectangular areas according to rows and columns;
[0020] Step 2: Remove the small rectangular areas that are not within the outline of the original graphic from the series of small rectangular areas;
[0021] Step 3: Merge the remaining series of small rectangular areas according to the principle of being adjacent and having the same width or length, to generate a series of merged rectangular areas;
[0022] Step 4: Sort the merged series of rectangular areas in descending order of area to generate a queue, and then pack and arrange the components within the rectangular areas in sequence until all components are packed; thus, the packing and arrangement based on the irregular-shaped original plate is realized.
[0023] In the above technical solution, after completing the packing and layout based on the irregularly shaped original plate, the nesting and layout based on the irregularly shaped graphic outline of each component is realized. The specific method is as follows:
[0024] Process 1: Based on the outer rectangular position area of the arranged components, translate the center point of the graphic coordinate outline of the component read from the dxf file to the center point of the arranged outer rectangle.
[0025] Step 2: Based on the aspect ratio of the outer rectangle of the arranged components, compare it with the aspect ratio of the smallest outer rectangle of the component's graphic coordinate outline to determine whether the components are arranged horizontally or vertically, and rotate the component's graphic outline accordingly based on the center point of the rectangle.
[0026] Step 3: After the above translation and rotation, the outline coordinates of the components are arranged in the minimum outer rectangle of the original plate area, thus realizing the layout and nesting of the outline of each irregular component. At this point, the layout and nesting based on the irregular original plate and irregular components is realized.
[0027] In the above technical solution, all the results of typesetting and nesting can be exported as a DXF file, maintaining the consistency of input and output file formats and making it convenient for users.
[0028] In the above technical solution, all the results of the layout and nesting can also be exported as G-code files for automated cutting processing on CNC lathes, realizing cutting on the entire irregular original plate according to the layout coordinates of each irregular component.
[0029] The beneficial effects of this invention are:
[0030] This invention enables nesting and layout based on conventional rectangles, as well as irregularly shaped components and original plates; it allows direct input of original plate DXF files and component DXF files, followed by nesting and layout, and direct output of DXF files and CNC lathe G-code files; it enables clear, intuitive, and space-maximizing nesting and layout based on irregularly shaped original plates and components within a given two-dimensional space, maximizing space utilization or minimizing waste.
[0031] This invention is highly practical and realizes the entire process of R&D, including the development of a two-dimensional irregular box packing and nesting algorithm, DLL encapsulation, web service interface development and release, web-side call and web-version system development, desktop-side call and desktop-version system development. Attached Figure Description
[0032] Figure 1 This is a schematic diagram of the structure of the present invention;
[0033] Figure 2 This invention provides a two-dimensional packing layout based on the minimum outer rectangle of the components.
[0034] Figure 3This invention enables the packaging and layout based on irregularly shaped original plates.
[0035] Figure 4 This invention enables the nesting and layout of irregularly shaped components.
[0036] Figure 5 This invention relates to the encapsulation of the algorithm DLL and the development and release of the web service interface.
[0037] Figure 6 For the development of the desktop client call and desktop application system described in this invention;
[0038] Figure 7 This invention relates to the development of web-based call and web-based application systems.
[0039] Figure 8 This invention describes the export of layout and nesting results to DXF and G-code files; Detailed Implementation
[0040] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.
[0041] Example 1:
[0042] The two-dimensional irregular-shaped box packing nesting system is characterized by the following: it realizes nesting based on irregular-shaped components and original plates; it allows direct input of original plate DXF files and component DXF files, and direct output of DXF files and CNC lathe G-code files after nesting; it achieves clear, intuitive nesting with maximum space utilization; and it realizes the complete R&D process, including the development of two-dimensional irregular-shaped box packing nesting algorithms, DLL encapsulation, web service interface development and release, web-based calls and web-based system development, and desktop-based calls and desktop-based system development (e.g., Figure 1 (As shown).
[0043] The process involves reading and parsing the graphic coordinate series (including straight lines, arcs, circles, and component numbers) of each component from the component DXF file. Each component is a closed shape whose outline is composed of straight lines, arcs, etc., and whose interior may contain closed shapes such as circles and rectangles. Each component has a unique ID number, which is used to quickly locate and identify each component in the DXF file exported from the layout and nesting results. The graphic of each component can be a regular rectangle or any irregular shape.
[0044] The process involves reading and parsing the graphic coordinate series (including closed graphics composed of straight lines, arcs, etc.) from the original DXF file; the graphic of the original board can be a regular rectangle or an arbitrary irregular shape.
[0045] In the above technical solution, after obtaining the minimum outer rectangle of each component from the component's graphic coordinate series (including closed graphics composed of straight lines, arcs, etc.), the nesting of materials based on the component's outer rectangle is realized. The specific method is as follows:
[0046] Process 1: Initialize an area space with an area equal to that of the original plate's outer rectangle, which is used to arrange the outer rectangle targets of each component;
[0047] Step 2: For the minimum enclosing rectangle of all components, sort them in descending order of area to generate a rectangular queue of components.
[0048] Step 3: Pop the largest rectangle from the queue and arrange it in the space of the original plate rectangle. Place it in the lower left corner of the rectangle. There are two arrangement directions: horizontal and vertical. Choose the appropriate direction according to the length-width ratio of the component rectangle and the original plate rectangle.
[0049] Step 4: After the rectangular components are arranged, the original rectangular area of the board is divided into three areas. This system adopts a "one-cut" technical solution, which can minimize the number of times the original board is cut and rotated, and maximize the space utilization of the original board.
[0050] Step 5: The original board is cut into three areas: horizontally: lower left area (cut area), lower right area (uncut area), and the entire upper area (uncut area); or vertically: lower left area (cut area), upper left area (uncut area), and the entire right side area (uncut area).
[0051] Step 6: Sort the uncut areas in descending order of area, and select the largest area as the new original board area; pop the new largest rectangle from the component rectangle queue as the rectangle to be arranged; repeat the above steps recursively until all component rectangles are arranged; thus, the box arrangement based on the component outer rectangle is realized (e.g., ... Figure 2 (As shown).
[0052] In the above technical solution, after completing the box layout based on the outer rectangle of the component, the box layout based on the irregular graphic outline of the original board is realized. The specific method is as follows:
[0053] Process 1: Based on the original board's own graphic outline, extract the horizontal and vertical lines, and divide the original board's outer rectangular area into a series of small rectangular areas according to rows and columns;
[0054] Step 2: Remove the small rectangular areas that are not within the outline of the original graphic from the series of small rectangular areas;
[0055] Step 3: Merge the remaining series of small rectangular areas according to the principle of being adjacent and having the same width or length, to generate a series of merged rectangular areas;
[0056] Step 4: Sort the merged series of rectangular areas in descending order of area to create a queue. Then, sequentially pack and arrange the components within each rectangular area until all components are packed. This completes the packing and arrangement based on irregularly shaped original plates (e.g., ...). Figure 3 (As shown).
[0057] In the above technical solution, after completing the packing and layout based on the irregularly shaped original plate, the nesting and layout based on the irregularly shaped graphic outline of each component is realized. The specific method is as follows:
[0058] Process 1: Based on the outer rectangular position area of the arranged components, translate the center point of the graphic coordinate outline of the component read from the dxf file to the center point of the arranged outer rectangle.
[0059] Step 2: Based on the aspect ratio of the outer rectangle of the arranged components, compare it with the aspect ratio of the smallest outer rectangle of the component's graphic coordinate outline to determine whether the components are arranged horizontally or vertically, and rotate the component's graphic outline accordingly based on the center point of the rectangle.
[0060] Step 3: After the above translation and rotation, the coordinates of the component's graphic outline are used to achieve the nesting of each irregular component's outline within the smallest outer rectangle area of the original plate region; thus, the nesting based on the irregular original plate and irregular components is achieved (e.g., Figure 4 (As shown).
[0061] The above technical solution includes the development of a two-dimensional irregular-shaped box packing and nesting algorithm, DLL encapsulation, and web service interface development (such as...). Figure 5 (as shown) and publishing, desktop client calls and desktop version system development (such as Figure 6 As shown), web-side calls and web-based system development (such as...) Figure 7 (as shown) and other complete development processes.
[0062] In the above technical solution, all the results of typesetting and nesting can be exported as a DXF file, maintaining consistency between the input and output file formats for user convenience. Alternatively, they can be exported as a G-code file (e.g.,...). Figure 8 As shown, it is used for automated cutting and processing on CNC lathes to achieve cutting on the entire irregular-shaped original plate according to the layout coordinates of each irregular component.
[0063] Example 2
[0064] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method as described in Embodiment 1.
[0065] Example 3
[0066] A computer program product includes a computer program that, when executed by a processor, implements the steps of the method as described in Example 1.
[0067] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of each module can be referred to the corresponding process in the aforementioned Embodiment 1, and will not be repeated here.
[0068] The preferred embodiments of the present invention have been described in detail above. Contents not described in detail belong to the prior art, which is well known to those skilled in the art. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of the prior art should be within the scope of protection defined by the claims.
Claims
1. A two-dimensional irregular-shaped box layout and nesting system and method, characterized in that: It implements nesting and layout based on irregularly shaped components and original plates; it reads and parses the graphic coordinate series (including lines, arcs, circles, and component numbers) of each component from the component DXF file; it reads and parses the graphic coordinate series (including closed shapes composed of lines and arcs) of the original plate from the original plate DXF file; it obtains the minimum bounding rectangle of each component, and within the closed graphic outline of the original plate, it first implements two-dimensional boxing and layout based on the minimum bounding rectangle of each component; then it cuts and merges the irregularly shaped original plate area to achieve boxing and layout based on the irregularly shaped original plate; and further... This system enables nesting of the graphic coordinates of each component into the minimum bounding rectangle of the previously laid-out component through graphic operations such as movement and rotation, achieving nesting based on irregularly shaped components. The complete nesting results can be exported as DXF files or G-code files for automated cutting and processing on CNC lathes. It implements a complete process including the development of a 2D irregularly shaped box nesting algorithm, DLL encapsulation, web service interface development and release, web-based call and web-based application system development, and desktop-based call and desktop-based application system development.
2. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: It reads and parses the graphic coordinate series (including lines, arcs, circles, and component numbers) of each component from the component dxf file; each component is a closed shape, whose outline is composed of lines, arcs, etc., and whose interior may contain closed shapes such as circles and rectangles. Each component has a unique ID, which is used to quickly locate and identify each component in the DXF file exported from the layout and nesting results; the graphic of each component can be a regular rectangle or any irregular shape.
3. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: Read and parse the graphic coordinate series (including closed graphics composed of lines, arcs, etc.) from the original DXF file; the graphic of the original board can be a regular rectangle or an arbitrary irregular shape.
4. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: After obtaining the minimum bounding rectangle of each component from its graphical coordinate series (including closed shapes composed of straight lines, arcs, etc.), nesting and layout based on the bounding rectangle of the component are performed. The specific method is as follows: Process 1: Initialize an area space with an area equal to that of the original plate's outer rectangle, which is used to arrange the outer rectangle targets of each component; Step 2: For the minimum enclosing rectangle of all components, sort them in descending order of area to generate a rectangular queue of components. Step 3: Pop the largest rectangle from the queue and arrange it in the space of the original plate rectangle. Place it in the lower left corner of the rectangle. There are two arrangement directions: horizontal and vertical. Choose the appropriate direction according to the length-width ratio of the component rectangle and the original plate rectangle. Step 4: After the rectangular components are arranged, the original rectangular area of the board is divided into three areas. This system adopts a "one-cut" technical solution, which can minimize the number of times the original board is cut and turn, and maximize the space utilization of the original board. Step 5: The original board is cut into three areas: horizontally: lower left area (cut area), lower right area (uncut area), and the entire upper area (uncut area); or vertically: lower left area (cut area), upper left area (uncut area), and the entire right side area (uncut area). Step 6: Sort the uncut areas from largest to smallest area, take the largest area as the new original board area; pop the new largest rectangle from the component rectangle queue as the rectangle to be laid out; repeat the above process recursively until all component rectangles are laid out.
5. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: After completing the binning layout based on the rectangular region enclosing the component, the binning layout based on the irregular graphic outline of the original board is implemented. The specific method is as follows: Process 1: Based on the original board's own graphic outline, extract the horizontal and vertical lines, and divide the original board's outer rectangular area into a series of small rectangular areas according to rows and columns; Step 2: Remove the small rectangular regions that are not within the outline of the original plate image from the series of small rectangular regions; Step 3: Merge the remaining series of small rectangular areas according to the principle of being adjacent and having the same width or length, to generate a series of merged rectangular areas; Step 4: Sort the merged series of rectangular areas in descending order of area to generate a queue, and then perform the nesting of components within the rectangular areas in sequence until all components are nested; thus, nesting based on irregularly shaped original plates is realized.
6. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: After completing the layout and nesting based on the irregularly shaped original plate, the layout and nesting based on the irregularly shaped outline of each component is realized. The specific method is as follows: Process 1: Based on the outer rectangular position area of the arranged components, translate the center point of the graphic coordinate outline of the component read from the dxf file to the center point of the arranged outer rectangle. Step 2: Based on the aspect ratio of the outer rectangle of the arranged components, compare it with the aspect ratio of the smallest outer rectangle of the component's graphic coordinate outline to determine whether the components are arranged horizontally or vertically, and rotate the component's graphic outline accordingly based on the center point of the rectangle. Step 3: After the above translation and rotation, the outline coordinates of the components are arranged in the minimum outer rectangle of the original plate area, thus realizing the layout and nesting of the outline of each irregular component. At this point, the layout and nesting based on the irregular original plate and irregular components is realized.
7. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: All layout and nesting results can be exported as a DXF file, maintaining consistency between input and output file formats for user convenience.
8. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: The complete nesting results can also be exported as G-code files for automated cutting on CNC lathes, enabling cutting on the entire irregular-shaped original plate according to the nesting coordinates of each irregular component.
9. The two-dimensional irregular-shaped box layout and nesting system and method according to claim 1, characterized in that: It has implemented a complete process including the development of two-dimensional irregular box packing and nesting algorithms, DLL encapsulation, web service interface development and release, web-side calling and web-version system development, desktop-side calling and desktop-version system development.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the method as described in any one of claims 1-9.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-9.