Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14040

Algorithm for generating a non-overlapping rectangles

$
0
0

I'm working on a problem where I need to generate a rectangle (let's call it 'box') within a larger rectangle ('field'), ensuring that the box doesn't overlap with a smaller rectangle ('window') contained within the field. For simplicity, all the coordinates are integers greater or equal to 0.

Here's the specific problem:

  • I have the coordinates of the lower left corner (LL) and upper rightcorner (UR) of both the field (light blue) and the window (white).
  • The randomly generated box (dark blue) needs to be completely within the field but should have no common points and no overlaps with the window.

enter image description here

I've managed to solve the problem in the 2D case. However, my solution involved tedious consideration of all possible relations between the random coordinates of the box with respect to the field and the window.

Now, I'm looking for a more generalized and robust algorithm (if any) that can handle dimensions larger than 2. For instance, considering all possibilities in 3D would be extremely complex.

Could someone provide guidance or an algorithm for this generalized case? I'm implementing this in Python and using NumPy for numerical operations. Any insights or code snippets would be highly appreciated. Thank you!


Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>