1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <iostream>
- #include <cmath>
- using namespace std;
- const double EPS = 1e-9;
- string xuo3(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
- auto dist = [](double x1, double y1, double x2, double y2) {
- return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- };
- auto isParallel = [](double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
- return abs((y2 - y1) * (x4 - x3) - (x2 - x1) * (y4 - y3)) < EPS;
- };
- auto isPerpendicular = [](double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
- return abs((x2 - x1) * (x4 - x3) + (y2 - y1) * (y4 - y3)) < EPS;
- };
- bool ab_parallel_cd = isParallel(x1, y1, x2, y2, x4, y4, x3, y3);
- bool bc_parallel_da = isParallel(x2, y2, x3, y3, x1, y1, x4, y4);
- bool ab_perpendicular_bc = isPerpendicular(x1, y1, x2, y2, x2, y2, x3, y3);
- bool bc_perpendicular_cd = isPerpendicular(x2, y2, x3, y3, x3, y3, x4, y4);
- if (ab_parallel_cd && bc_parallel_da) {
- if (ab_perpendicular_bc && bc_perpendicular_cd) {
- return "Прямоугольник";
- }
- return "Параллелограмм";
- }
- if (ab_parallel_cd || bc_parallel_da) {
- return "Трапеция";
- }
- return "Произвольный четырехугольник";
- }
- int main() {
- double x1, y1, x2, y2, x3, y3, x4, y4;
- cout << "Введите координаты точек A, B, C, D (x1 y1 x2 y2 x3 y3 x4 y4): ";
- cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
- string type = xuo3(x1, y1, x2, y2, x3, y3, x4, y4);
- cout << "Тип четырехугольника: " << type << endl;
- return 0;
- }
|