task1.3.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. const double EPS = 1e-9;
  5. string xuo3(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
  6. auto dist = [](double x1, double y1, double x2, double y2) {
  7. return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  8. };
  9. auto isParallel = [](double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
  10. return abs((y2 - y1) * (x4 - x3) - (x2 - x1) * (y4 - y3)) < EPS;
  11. };
  12. auto isPerpendicular = [](double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
  13. return abs((x2 - x1) * (x4 - x3) + (y2 - y1) * (y4 - y3)) < EPS;
  14. };
  15. bool ab_parallel_cd = isParallel(x1, y1, x2, y2, x4, y4, x3, y3);
  16. bool bc_parallel_da = isParallel(x2, y2, x3, y3, x1, y1, x4, y4);
  17. bool ab_perpendicular_bc = isPerpendicular(x1, y1, x2, y2, x2, y2, x3, y3);
  18. bool bc_perpendicular_cd = isPerpendicular(x2, y2, x3, y3, x3, y3, x4, y4);
  19. if (ab_parallel_cd && bc_parallel_da) {
  20. if (ab_perpendicular_bc && bc_perpendicular_cd) {
  21. return "Прямоугольник";
  22. }
  23. return "Параллелограмм";
  24. }
  25. if (ab_parallel_cd || bc_parallel_da) {
  26. return "Трапеция";
  27. }
  28. return "Произвольный четырехугольник";
  29. }
  30. int main() {
  31. double x1, y1, x2, y2, x3, y3, x4, y4;
  32. cout << "Введите координаты точек A, B, C, D (x1 y1 x2 y2 x3 y3 x4 y4): ";
  33. cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  34. string type = xuo3(x1, y1, x2, y2, x3, y3, x4, y4);
  35. cout << "Тип четырехугольника: " << type << endl;
  36. return 0;
  37. }