0

I have n rectangles and I need to find how many of them overlap. Which I have done and created an intersection matrix which looks like this Intersection Matrix for the below JSON where each entry presents a rectangle and 1 represents there is an overlap. It is a symmetric matrix and i have assumed that a rectangle overlaps itself.

{
 "rects": [
          {"x": 100, "y": 100, "w": 250, "h": 80 },
          {"x": 120, "y": 200, "w": 250, "h": 150 },
          {"x": 140, "y": 160, "w": 250, "h": 100 },
          {"x": 160, "y": 140, "w": 350, "h": 190 }
          ]
 }

Now I know that there can be 2 or more rectangles overlapping each other. How can I find them using this intersection matrix? Or is there any other approach for this?

e.g 1,3,4 and 2,3,4

Jarod42
  • 203,559
  • 14
  • 181
  • 302
DevMac
  • 131
  • 1
  • 2
  • 9
  • 1
    If rectangle *a* overlaps with *b*, and *b* overlaps with *c*, and *a* overlaps with *c*, then due to the geometry of a rectangle, we know that *a*, *b* and *c* have a common "subspace". – Willem Van Onsem Jan 24 '19 at 15:51
  • 1
    Unclear what you want. Do you want to find all triplets overlapping, all groups (with more than 2 rectangles) overlapping, biggest group, size of biggest group ? – Jarod42 Jan 24 '19 at 16:03
  • all groups with more than 2 rectangles – DevMac Jan 24 '19 at 16:04
  • 3
    If you interpret your matrix as an adjacency matrix of a graph, you are trying to find [cliques](https://en.wikipedia.org/wiki/Clique_problem) of this graph. Check the linked Wikipedia article for some algorithms. – Nico Schertler Jan 24 '19 at 16:11
  • @WillemVanOnsem That's good for finding the triplets but whats with the quads? – DevMac Jan 24 '19 at 17:18
  • @WillemVanOnsem What do you mean by "common subspace"? – DevMac Jan 24 '19 at 17:31
  • @DevMac: the fact that is one (or more) 2d coordinates that are elements of the three rectangles. – Willem Van Onsem Jan 24 '19 at 18:41

0 Answers0