0
votes

Problem

I have a case where I generate axis aligned rectangles that may or may not overlap each other - they often will. Ultimately, I need a set of rectangles that do not overlap, but cover (at least) the same regions. I'm looking for algorithms to accomplish this efficiently online (at run-time) in a real-time setting. I have some ideas, but they may be naive or brutal and I'd like to avoid reinventing the wheel if this is a well studied and resolved problem.

I'm having difficulty thinking of other applications or metaphors that might clue me in to a name. Is there a specific name for this kind of problem/algorithmic solution? Kind of like, say, the "four color theorem" in trying to color maps with no adjacent regions of the same color. "Four Color Theorem" being, in a sense, the algorithm with "coloring regions of a map such that no adjacent region share a color" being the problem instance.

Context

The specific application is to generate rectangular height fields for collision purposes around objects, but objects in close proximity will cause overlapping height fields, which will cause collision artifacts. Preserving existing rectangles and favoring those with a larger area is preferable to minimize the amount of memory that needs to be moved/copied into a new rectangle height field.

Example Images

Red, Green, and Blue Rectangles Overlapping with Encompassing RectangleRed, Green, and Blue Rectangles Overlapping with Dashed Potential Subdividing Lines

1
"I need a set of rectangles that do not overlap, but cover (at least) the same regions." Does that set have to be a a subset of the input set? Otherwise you can just take a single rectangle that is large enough to cover the whole input. I don't understand the example images. I think the problem as such is a bit underspecified and it would help to hear your thoughts about algorithms that might work and maybe even source code so that we will be convinced that you put your own effort into the problem and don't just dump it here for someone else to solve :)Niklas B.
Probably not, as I'd have to then generate a lot of unnecessary data - but that's not part of my question, really. I'm looking for a name or problems much like this that I can study, say in rendering code that tries to only repaint dirty regions or some such. Kind of like, say, the "four color theorem" in trying to color maps with no adjacent regions of the same color. I'll add that clarification to the question.Sion Sheevok
Thing is, this website is about programming questions, not algorithm questions. If you don't have source code, it's more of a design question which would be a better fit for Software Engineering or CompSci SENiklas B.
Actually I'm flagging this to be moved to CompSci, seems to fit there a lot better.Niklas B.
Thanks. I use Stackoverflow plenty and a few other Stackexchange sites and I did my best to make it fit, thinking this was a best fit for the SOs I know.Sion Sheevok

1 Answers

0
votes

one class of algorithms you may find useful is called 'plane sweep' or 'line sweep' algorithms. basically you sort your object by one of the axis and then you process them in that order to discover all significant points/events like start, end, intersection