Good evening.
I’m writing a program in VBA (inside AutoCAD) and am struggling with a specific part which I’m hoping somebody better at maths than me (which wouldn’t be hard!) can help with.
Essentially, I need to calculate the quantity and size of the largest rectangles inside a polygon. The polygon can contain any number of vertices from 4 and upwards, and will *always *consist of 90deg angles.
The image below demonstrates an example showing the bottom left and top right corners of the rectangles that will fit in a sample polygon.
The purpose of this exercise is to calculate the maximum size & number of areas in a sheet of material left after a rectangular piece has been cut from it. From with other parts can then be cut.
So far my code handles all the necessary checks and loops to ensure the largest part is cut from the largest offcut, but I’m struggling with calculating those remaining areas after a piece is cut. Yes, I know this may not be the most efficient method for minimising wastage, but it’s the most simple I can come up with, and bit of left over won’t be a major issue.
First part cut will *always *be from bottom left corner, which in CAD terms will be 0,0. The image below is an example of the order in which parts could be cut from a single sheet. Lengths and widths of each part being cut will naturally be known.
I’m able to calculate the BL and TR coordinates of each part and in the correct place, but *only *for the first and second iterations. Once the size of the third part is known, I can’t come up with the function necessary to allow for the removing of segments from the originally calculated remaining areas. The first cut leaving two possible rectangualr areas is fine, after that it gets too complex. I don’t know if I should be calculating what’s been taken away from one or more of the remaining areas, or looking at the remaining polygon afresh each iteration and recalculating what rectangles fit within it each time.
I’m much obliged to any assistance in resolving this. As mentioned above, I’m using VB code (not vb.net) to solve this (as it’s the only code I know) but if that’s unfamiliar to anyone, a steer on the correct maths to solve this would be must appreciated.
Many thanks.
Graham
Graham Caspall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.