'amount of rectangles intersections
Task: we have set of n rectangles (coordinates of left bottom point and right top point) and we want to compute amount of intersections of each rectangle with other rectangles in this set. I did it in n^2 time complexity with comparing every rectangle with other rectangles in this set but this time complexity is too big. How I can optimize algorithm? I heard about R-trees but I don't know how to realize it. Thank you. For example if we have set (2, 1, 8, 10), (3, 2, 5, 5), (4, 3, 7, 9) in order x_leftlow, y_leftlow, x_righttop, y_righttop answer will be 2, 1, 1 because (2, 1, 8, 10) intersect both rectangles, (3, 2, 5, 5) intersect (4, 3, 7, 9)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
