Efficient way to find overlapping of N rectangles
I am trying to find an efficient solution for finding overlapping of n rectangles where rectangles are stored in two separate lists. We are looking for all rectangles in listA that overlap with...
View ArticleAnswer by Blckknght for Efficient way to find overlapping of N rectangles
The exception you're getting comes from the last line of the code you show. The expression list[rect] is not valid, since list is a class, and the [] syntax in that context is trying to index it. You...
View ArticleAnswer by greybeard for Efficient way to find overlapping of N rectangles
First off: As with many a problem from computational geometry, specifying the parameters for order-of-growth analysis needs care: calling the lengths of the lists m and n, the worst case in just those...
View ArticleAnswer by otmar for Efficient way to find overlapping of N rectangles
I think you have to setup an additional data structure (spatial index) in order to have fast access to nearby rectangles that potentially overlap in order to reduce the time complexity from quadratic...
View ArticleAnswer by cdlane for Efficient way to find overlapping of N rectangles
A couple of potential minor efficiency improvements. First, fix your overlap() function, it potentially does calculations it needn't:def overlap(r1, r2): if r1.left > r2.right or r1.right <...
View ArticleAnswer by OMRY VOLK for Efficient way to find overlapping of N rectangles
This implementation using numpy is about 35-40 times faster according to a test I did. For 2 lists each with 10000 random rectangles this method took 2.5 secs and the method in the question took ~90...
View ArticleAnswer by Ripi2 for Efficient way to find overlapping of N rectangles
Obviously, if your list (at least listB) is sorted by r2.xmin, you can search for r1.xmax in listB and stop testing overlap of r1 in this listB (the rest will be to the right). This will be...
View ArticleAnswer by user1023602 for Efficient way to find overlapping of N rectangles
If you know the upper and lower limits for coordinates, you can narrow the search by partitioning the coordinate space into squares e.g. 100x100. Make one "set" per coordinate square.Go through all...
View ArticleAnswer by M.Racko for Efficient way to find overlapping of N rectangles
Here is what I use to calculate overlap areas of many candidate rectangles (with candidate_coords [[l, t, r, b], ...]) with a target one (target_coords [l, t, r, b]):comb_tensor = np.zeros((2,...
View ArticleAnswer by Nagaraj Rangan for Efficient way to find overlapping of N rectangles
I think the below code will be useful.print("Identifying Overlap between n number of rectangle")#List to be used in set and get_coordinate_checked_listcoordinate_checked_list = []def...
View ArticleAnswer by user1196549 for Efficient way to find overlapping of N rectangles
For a simple solution that improves on pure brute force if the rectangles are relatively sparse:sort all Y ordinates in a single list, and for every ordinate store the index of the rectangle, the...
View ArticleAnswer by Hans for Efficient way to find overlapping of N rectangles
I had the same problem, and I came up with this solution. The function does the calculation in about 11 seconds (Intel i5 - 50,000 random rectangles). It uses numexpr instead of numpy which is about 5...
View Article