I'm working on a script that will generate num_cubes
number of cubes in a pre-defined 3D space. The cube dimensions will be random, using random.choice(cubeLengths)
, where cubeLengths = [1,2,4]
(I will play with weights afterwards to make it more interesting).
I'd like to have it so that the cubes are as close together as possible without overlap, instead of having a lot of space in between them. I'd looked through this answer dealing with overlapping cubes that has a similar concept, and I was able to make that work, but I'm looking to make mine more compact, to achieve a specific look like this:
From the looks of things, it does not seem like his cubes overlap. Currently, I'm able to generate a single row of randomly sized cubes back-to-back, but then once I need to go to a second row, I get stuck. My code is obviously not optimized, nor is it the best, but here's what I have so far:
What could be the right approach to tackling this problem? Am I overthinking this? Or is this specific problem require a lot more math than it seems?