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


 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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM