I have the following problem.
I have a large region filled with a random number of circles of different sizes. If a new circle of random radius is inserted in a random place, I would like to find the closest position for it so that it does not intersect with any of the others. Optimal if the circles remain closed.
The number of circles and their size are limited, but random. The region will be quite large (2500x2500 maybe), so the array of pixels proposed here is out of the question. The person who answered the same question proposed a grid in which cells are the sizes of circles. This would solve my problem using cells the size of the largest possible circle, but I would like the circles to stay as close as possible, so that would not completely satisfy my needs.
The easiest approach is to detect collisions when placing a new circle and moving it away from the circle that it collides with. After that, check for conflicts and repeat the process. This is obviously not very elegant, and it is subject to endless cycles (more often than you might think).
The goal is to find the closest possible position for the newly inserted circle so that it does not intersect with anyone else.
PD
A very nice thing, but another question, and not my main goal, would be to rearrange as many circles as necessary, instead of moving only one, as if they were "pushing" each other. I would prefer a distance over the number of circles moved. That is, I would prefer that many circles move a little than one circle to move very far from its original position.
source share