1 rectint函数
A 和 B 是一个思维向量 [x,y,width,height]
area = rectint(A,B)
class Rectangle:
def __init__(self, x, y,w,h):
self.x = x
self.y = y
self.width = w
self.height = h
ra = Rectangle(3., 3., 5., 5.)
rb = Rectangle(1., 1., 4., 4.)
# intersection here is (3, 3, 4, 3.5), or an area of 1*.5=.5
def calc_area(rect1, rect2):
xl1, yb1, xr1, yt1 = rect1.x,rect1.y,rect1.x+rect1.width,rect1.y+rect1.height
# (xl1, yb1)为矩形左下角坐标, (xr1, yt1)为右上角坐标
xl2, yb2, xr2, yt2 = rect2.x,rect2.y,rect2.x+rect2.width,rect2.y+rect2.height
# (xl2, yb2)为矩形左下角坐标, (xr2, yt2)为右上角坐标
xmin = max(xl1, xl2)
ymin = max(yb1, yb2)
xmax = min(xr1, xr2)
ymax = min(yt1, yt2)
width = xmax - xmin
height = ymax - ymin
if width
关注
打赏
热门博文
- 【文献汇总】2019-2021最新应用深度学习到OFDM通信系统中的论文汇总(实时更新)
- 【金融量化】电话口试-智力题
- 【数据挖掘】2022年2023届秋招爱玩特智能量化研究员岗 笔试题
- 【Leetcode刷题Python】1467. 两个盒子中球的颜色数相同的概率
- 【Leetcode刷题Python】50. Pow(x, n)
- 【Leetcode刷题Python】牛客. 数组中未出现的最小正整数
- 【Leetcode刷题Python】73. 矩阵置零
- 【Leetcode刷题Python】LeetCode 478. 在圆内随机生成点
- 【Leetcode刷题Python】 LeetCode 2038. 如果相邻两个颜色均相同则删除当前颜色
- 【数据挖掘】2022年2023届秋招Kanaries雾角科技算法岗 笔试题