找到图中标星号的两个点,如果x2-x3>0 && y2-y3>0 则两个矩形相交,否则不相交。
#include <bits/stdc++.h>
using namespace std;
int main()
{
double x1, x2, x3, x4, y1, y2, y3, y4;
double x_min, x_max, y_min, y_max;
double l, w;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
x_min = min(max(x1, x2), max(x3, x4));
x_max = max(min(x1, x2), min(x3, x4));
l = x_min - x_max;
y_min = min(max(y1, y2), max(y3, y4));
y_max = max(min(y1, y2), min(y3, y4));
w = y_min - y_max;
if (l > 0 && w > 0)
{
printf("%.2lf", l * w);
}
else
{
printf("0.00\n");
}
return 0;
}
评论区