Advertisement
pablo7890

wewnatrz trojkata

Mar 19th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4. typedef struct { double x; double y; } Point;
  5. bool isPointInsideTriangle(const Point triangle[3], const Point &b)
  6. {
  7.     int notPlus(0), notMinus(0);
  8.     for (int i=0; i<=3; i++) {
  9.         const Point &a= triangle[i%3];
  10.         const Point &c= triangle[i-1];
  11.         double x = (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
  12.         if (x<=0) notPlus++;
  13.         if (x>=0) notMinus++;
  14.     }
  15.     return (notPlus==3) || (notMinus==3);
  16. }
  17. int main()
  18. {
  19.         double xa, ya, xb, yb, xc, yc;
  20.         cin >> xa >> ya >> xb >> yb >> xc >> yc;
  21.        
  22.         Point a;
  23.         a.x = xa; a.y = ya;
  24.         Point b;
  25.         b.x = xb; b.y = yb;
  26.         Point c;
  27.         c.x = xc; c.y = yc;
  28.         Point triangle[3] = {a, b, c};
  29.        
  30.         int n;
  31.         cin >> n;
  32.         for (int i = 0; i < n; i++)
  33.         {
  34.         double xa2, ya2, xb2, yb2, xc2, yc2;
  35.             cin >> xa2 >> ya2 >> xb2 >> yb2 >> xc2 >> yc2;
  36.             Point aa;
  37.             aa.x = xa2; aa.y = ya2;
  38.             Point bb;
  39.             bb.x = xb2; bb.y = yb2;
  40.             Point cc;
  41.             cc.x = xc2; cc.y = yc2;
  42.             if (isPointInsideTriangle(triangle, aa)==true && isPointInsideTriangle(triangle, bb)==true && isPointInsideTriangle(triangle, cc)==true)
  43.             {
  44.                 cout << "tak\n";
  45.             }
  46.             else
  47.             {
  48.                 cout << "nie\n";
  49.             }
  50.         }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement