python find two rectangle intersections

Solutions on MaxInterview for python find two rectangle intersections by the best coders in the world

showing results for - "python find two rectangle intersections"
Jérémie
21 Feb 2020
1import math
2class corner:
3    def _init_(self, x, y):
4        self.x = x
5        self.y = y
6def intersection(l1,b1,r1,t1,l2,b2,r2,t2):
7    lb1 = corner(l1,b1)
8    rt1 = corner(r1, t1)
9    lb2 = corner(l2,b2)
10    rt2 = corner(r2, t2)
11    intr1 = min(rt1.x, rt2.x) - max(lb1.x, lb2.x)
12    intr2 = min(rt1.y, rt2.y) - max(lb1.y, lb2.y)
13    if intr1>=0 and intr2>=0:
14        return 2*(intr1*intr2)
15print(intersection(0,0,5,5,3,3,7,7))