Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square intersection solver

I'm looking for an efficient way to move hundreds of uniform, possibly intersecting squares away from each other, so they no longer intersect. The resulting new positions should be as close as possible to the original coordinates.

Is there such an algorithm?

like image 279
quano Avatar asked Apr 08 '26 07:04

quano


1 Answers

Introduce the shift variables Xi+, Xi-, Yi-, Yi- and solve the linear problem that minimizes the sum of the variables under constraints that express the non-overlap like (Ui + Xi+) - (Uj - Xj-) >= S, (Vi + Yi+) - (Vj - Yj-) >= S or similar.

If you are not familiar with linear programming, you should read about: http://en.wikipedia.org/wiki/Linear_programming