int find_intersect_area(Rect a, Rect b)
{
//(x11,y11)(x12,y12)为矩形a对角线上的端点
//(x21,y21)(x22,y22)为矩形b对角线上的端点
int x11 = a.x;
int x12 = a.x + a.width;
int y11 = a.y;
int y12 = a.y + a.height;
int x21 = b.x;
int x22 = b.x + b.width;
int y21 = b.y;
int y22 = b.y + b.height;
//相交图形为矩形,x方向长度为min(x12,x22) - max(x11,x21)
//y方向长度为min(y12,y22) - max(y11,y21)
//若为负值则不相交
int Lx = max(0, min(x12, x22) - max(x11, x21));
int Ly = max(0, min(y12, y22) - max(y11, y21));
return Lx * Ly;
}
计算未旋转2矩形相交面积
最新推荐文章于 2023-12-29 14:33:27 发布