计算两个矩形的重叠面积(均平行于坐标轴)

 1 '''
 2 input: rect1, rect2, 均为list,其分别为
 3 xl(left),yb(bottom),xr(right),yt(top)
 4 '''
 5 def calc_area(rect1, rect2):
 6     xl1, yb1, xr1, yt1 = rect1
 7     xl2, yb2, xr2, yt2 = rect2
 8     xmin = max(xl1, xl2)
 9     ymin = max(yb1, yb2)
10     xmax = min(xr1, xr2)
11     ymax = min(yt1, yt2)
12     width = xmax - xmin
13     height = ymax - ymin
14     if width <= 0 or height <= 0:
15         return 0
16     cross_square = width * height
17     return cross_square
原文地址:https://www.cnblogs.com/laresh/p/7955164.html