判断两矩形关系
#include<iostream>
#include<algorithm>
#include<string>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<iomanip>
#include<typeinfo>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
/*void Switch(int a1, int a2)
{
int temp;
temp = a1;
a1 = a2;
a2 = temp;
}
void BubbleSort(int a[])
{
int Number = 3;
for (int i = 0; i < Number; i++)
for (int j = i; j < Number; j++)
if (a[i] > a[j])
{
int temp;
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}*/
int main(char argc)
{
class angle
{
public:
double x;
double y;
};
cout << "Enter r1's center x-,y-coordinates, width, and height: ";
double x1, y1, w1, h1;
cin >> x1 >> y1 >> w1 >> h1;
cout << "Enter r2's center x-,y-coordinates, width, and height: ";
double x2, y2, w2, h2;
cin >> x2 >> y2 >> w2 >> h2;
angle angle11, angle12, angle21, angle22;
angle11.x = x1 + w1;
angle11.y = y1 + h1;
angle12.x = x1 - w1;
angle12.y = y1 - h1;
angle21.x = x2 + w2;
angle21.y = y2 + h2;
angle22.x = x2 - w2;
angle22.y = y2 - h2;
if (min(angle11.x, angle21.x) < max(angle12.x, angle22.x))
cout << "r2 does not overlap r1";
else
{
if (min(angle11.x, angle21.x) == angle21.x&&
min(angle11.y, angle21.y) == angle21.y&&
max(angle12.x, angle22.x) == angle22.x&&
max(angle12.y, angle22.y) == angle22.y)
cout << "r2 is inside r1";
else
cout << "r2 overlaps r1";
}
return 0;
}