不知道有没有问题,先贴这
rec1 = [(x1, y1), (x2, y2)] # 左下右上
rec2 = [(x3, y3), (x4, y4)]
def area(rec1, rec2):
if rec1[0][0] > rec2[1][0] or rec1[1][0] < rec2[0][0] or
rec1[0][1] > rec2[1][1] or rec1[1][1] < rec2[0][1]:
return 0
sorted_x = sorted([xy[0] for xy in rec1] + [xy[0] for xy in rec2])
sorted_y = sorted([xy[1] for xy in rec1] + [xy[1] for xy in rec2])
return (sorted_x[2]-sorted_x[1]) * (sorted_y[2]-sorted_y[1])