Length of intersecting part i . e start from max ( l1 [ x ] , l2 [ x ] ) of x - coordinate and end at min ( r1 [ x ] , r2 [ x ] ) x - coordinate by subtracting start from end we get required lengths
x_dist = ( min ( r1 [ x ] , r2 [ x ] ) - max ( l1 [ x ] , l2 [ x ] ) ) NEW_LINE y_dist = ( min ( r1 [ y ] , r2 [ y ] ) - max ( l1 [ y ] , l2 [ y ] ) ) NEW_LINE areaI = 0 NEW_LINE if x_dist > 0 and y_dist > 0 : NEW_LINE INDENT areaI = x_dist * y_dist NEW_LINE DEDENT return ( area1 + area2 - areaI ) NEW_LINE