CheapSteaks
CheapSteaks

Reputation: 5019

How to distribute a list of rectangles of varying width and height, maximizing distance between items, inside a rectangular container?

I need a function that takes in two inputs:

It would output an array of the same items with an additional position property (can mutate the original items), with x and y such that distances between items are maximized (note - not distance between the points, need to take into consideration of the dimensions of the item).

It doesn't have to be the mathematically proven best solution, a good-enough heuristic is okay

I've looked at bin-packing, but it seems to do the opposite of what I want.

Any language is acceptable, even pseudocode.

I'm not sure where even to start. Right now I'm just randomizing positions and occasionally end up with overlapping items, which is undesirable.

Upvotes: 0

Views: 148

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96286

As you only need a heuristic, and not an optimal solution (which nobody can give you ATM, as "distances between items are maximized" is a vague term):

Though bin-packing seems to be the "opposite", it can be used. Take a smaller (smallest) box that they fit into, and do the packing, then stretch it along with the calculated positions.

Upvotes: 2

Related Questions