Advertisement
allia

точка и квадрат

Dec 10th, 2020
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct otrezok
  9. {
  10.   public:
  11.   double x1, y1, x2, y2, x, y;
  12.   double length;
  13.  
  14.   otrezok(double x1, double x2,double  y1,double y2)
  15.   {
  16.    length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
  17.   }
  18. };
  19.  
  20. struct direct
  21. {
  22.  double a = 0, b = 0, c = 0;
  23.  double parametr = INT16_MAX;
  24. };
  25.  
  26. struct vershina
  27. {
  28.   double x, y;
  29. };
  30.  
  31. direct storona (vershina first, vershina second)
  32. {
  33.   direct stright;
  34.     stright.a = (first.y - second.y);
  35.     stright.b = (second.x - first.x);
  36.     stright.c =  first.x*second.y - second.x*first.y;
  37.   return stright;
  38. }
  39.  
  40. int main ()
  41. {
  42.   vershina A, B, C, D, X;
  43.   cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y;
  44.   cin >> X.x >> X.y;
  45.  
  46.   direct AB = storona (A, B);
  47.   direct BC = storona (B, C);
  48.   direct CD = storona (D, C);
  49.   direct DA = storona (A, D);
  50.   // cout << BC.a << " " << BC.b << " " << BC.c << " ";
  51.   double znach_1 = AB.a*X.x + AB.b*X.y + AB.c;
  52.   double znach_2 = BC.a*X.x + BC.b*X.y + BC.c;
  53.   double znach_3 = CD.a*X.x + CD.b*X.y + CD.c;
  54.   double znach_4 = DA.a*X.x + DA.b*X.y + DA.c;
  55.    //cout << znach_1 << znach_2 << znach_3 << znach_4;
  56.   if (znach_1 <= 0 && znach_2 <= 0 && znach_3 >= 0 && znach_4 >= 0)
  57.     cout << "Yes";
  58.   else cout << "No";
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement