Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. void Options::Compare(Shape* s1, Shape* s2)
  2. {
  3.     double ar1, ar2;
  4.     ar1 = s1->getArea();
  5.     ar2 = s2->getArea();
  6.     if (ar1 > ar2)
  7.     {
  8.         cout << "Площадь треугольника больше площади квадрата" << endl;
  9.     }
  10.     else if (ar1 == ar2)
  11.     {
  12.         cout << "Площади фигур равны" << endl;
  13.     }
  14.     else cout << "Площадь квадрата больше площади треугольника" << endl;
  15. }
  16. void Options::IsIntersect(Shape* s1, Shape* s2)
  17. {
  18.     Point *masT, *masS;
  19.     masT = new  Point[1];
  20.     masS = new Point[1];
  21.     masT[0] = s1->getCenter();
  22.     masS[0] = s2->getCenter();
  23.     double fs, ss, ts;
  24.     fs = sqrt(pow((s1->arc[0].x - s1->arc[1].x), 2) + pow((s1->arc[0].y - s1->arc[1].y), 2));
  25.     ss = sqrt(pow((s1->arc[0].x - s1->arc[2].x), 2) + pow((s1->arc[0].y - s1->arc[2].y), 2));
  26.     ts = sqrt(pow((s1->arc[1].x - s1->arc[2].x), 2) + pow((s1->arc[1].y + s1->arc[2].y), 2));
  27.     double pr = (fs + ss + ts) / 2;
  28.     double RTri;
  29.     RTri = (fs * ss * ts) / (4 * sqrt(pr*(pr - fs) * (pr - ss) * (pr - ts))); // радиус треугольника
  30.     double RSq;
  31.     RSq = sqrt(pow((s2->arc[0].x - s2->arc[1].x), 2) + pow((s2->arc[0].y - s2->arc[1].y), 2)) * sqrt(2) / 2; // радиус квадрата
  32.     double side;
  33.     side = sqrt(pow((masT->x - masS->x),2) + pow((masT->y - masS->y),2));
  34.     if (side <= RTri + RSq)
  35.     {
  36.         cout << "Вхождение есть" << endl;
  37.         return;
  38.     }
  39.     else cout << "Вхождения нет" << endl;
  40. }
  41. void Options::IsInclude(Shape* s1, Shape* s2)
  42. {
  43.     Point *masT, *masS;
  44.     masT = new  Point[1];
  45.     masS = new Point[1];
  46.     masT[0] = s1->getCenter();
  47.     masS[0] = s2->getCenter();
  48.     double fs, ss, ts;
  49.     fs = sqrt(pow((s1->arc[0].x - s1->arc[1].x), 2) + pow((s1->arc[0].y - s1->arc[1].y), 2));
  50.     ss = sqrt(pow((s1->arc[0].x - s1->arc[2].x), 2) + pow((s1->arc[0].y - s1->arc[2].y), 2));
  51.     ts = sqrt(pow((s1->arc[1].x - s1->arc[2].x), 2) + pow((s1->arc[1].y + s1->arc[2].y), 2));
  52.     double pr = (fs + ss + ts) / 2;
  53.     double RTri;
  54.     RTri = (fs * ss * ts) / (4 * sqrt(pr*(pr - fs) * (pr - ss) * (pr - ts))); // радиус треугольника
  55.     double RSq;
  56.     RSq = sqrt(pow((s2->arc[0].x - s2->arc[1].x), 2) + pow((s2->arc[0].y - s2->arc[1].y), 2)) * sqrt(2) / 2; // радиус квадрата
  57.     double side;
  58.     side = sqrt(pow((masT->x - masS->x), 2) + pow((masT->y - masS->y), 2)); // длина от центра масс
  59.     if (RTri >= RSq)
  60.     {
  61.         if (side + RSq <= RTri)
  62.         {
  63.             cout << "Полное вхождение" << endl;
  64.         }
  65.         else cout << "Нет полного вхождения " << endl;
  66.     }
  67.     else
  68.     {
  69.         if (side + RTri <= RSq)
  70.         {
  71.             cout << "Полное вхождения" << endl;
  72.  
  73.         }
  74.         else cout << "Нет полного вхождения" << endl;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement