I'm wondering if there is an "optimal" solution for this problem:
I have a n x m (pixel) sized space with p preexisting rectangled - objects in various sizes on it. Now I want to place q (same sized) new objects in this space without any overlapping.
The algorithm I came up with:
- Create array A[][] with the size
[(n)/(size_of_object_from_q)]x[(n)/(size_of_object_from_q)]
Iterate all Elements from p and for each:
mark all fields in A[][] as occupied, where the element "lies"
Place all elements from q in the according places where the fields in A[][] are not marked
(Boy, I hope I could make that understandable...)
Is there any better way to do this? Any help would really be appreciated!