一、 判断两个矩形是否相交
当矩形1的最大值比矩形2的最小值都小,那矩形1和矩形2一定不相交,其他同理。
struct Point {
double x;
double y;
};
struct Rec {
Point min;
Point max;
};
bool is_rec_overlap(const Rec& r1, const Rec& r2) {
if(r1.max.x < r2.min.x
|| r1.max.y < r2.min.y
|| r2.max.x < r1.min.x
|| r2.max.y < r1.min.y) {
return false;
} else {
return true;
}
}
二、 判断三角形
参考
https://www.cnblogs.com/tgycoder/p/4901600.html
三、 判断两条线段是否相交
参考
https://www.cnblogs.com/TangMoon/p/7611115.html