条件:必须是整点矩形
思路:两个矩形左下点中的右上点,必须在两个矩形右上点中的左下点的左下侧。
class Solution {
public:
bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
int x1 = max(rec1[0],rec2[0]);
int y1 = max(rec1[1],rec2[1]);
int x2 = min(rec1[2],rec2[2]);
int y2 = min(rec1[3],rec2[3]);
return x1 < x2 && y1 < y2;
}
};

本文介绍了一种用于判断两个整点矩形是否重叠的算法。通过比较两个矩形的左下点和右上点,可以高效地确定它们是否相交。此算法在计算机图形学和游戏开发中非常实用。
1651

被折叠的 条评论
为什么被折叠?



