How many times can a shape fit in an area

I'm trying to write a software to calculate how many sheets i need based on size and qty of a shape placed on it.

example: i have a sheet that is 10 x 20. if i want 5 pcs of 5x7 how many sheets do i need? i know i can't just use total area as there will be waste.

Then i want to figure out if i ass another shape on the sheet or sheets how many i can get before i need another sheet.

what is the mathematical procedure and formula to find this out? (i know by logic this requires 2 sheets with some waste)

Assuming the calculation above requires 2 sheets with waste. now i want to try other shapes against the leftover area in waste on either sheet. like maybe 4pcs of 5x3 would still fit on the first sheet and the second sheet would still have room for 5x3 and 15x10 for other shapes.

what is the mathematical procedure and formula to find out the second part?

• You can look at this and this – John Glenn Oct 24 '18 at 12:19