Advertisement
pablo7890

Untitled

Mar 25th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. typedef struct { double x; double y; } Point;
  8.  
  9. double Heron(double a, double b, double c){
  10.     double p=(a+b+c)/2;
  11.     return sqrt(p*(p-a)*(p-b)*(p-c));
  12. }
  13.  
  14. double distance(int x1, int x2, int y1, int y2)
  15. {
  16.     return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  17. }
  18.  
  19. double GetTriangle()
  20. {
  21.     double Ax,Ay,Bx,By,Cx,Cy;
  22.     cin>>Ax>>Ay>>Bx>>By>>Cx>>Cy;
  23.     double a = distance(Ax, Bx, Ay, By);
  24.     double b = distance(Ax, Cx, Ay, Cy);
  25.     double c = distance(Bx, Cx, By, Cy);
  26.     return Heron(a, b, c);
  27. }
  28.  
  29. bool isPointInsideTriangle(const Point triangle[3], const Point &b)
  30. {
  31.     int notPlus(0), notMinus(0);
  32.     for (int i=0; i<=3; i++) {
  33.         const Point &a= triangle[i%3];
  34.         const Point &c= triangle[i-1];
  35.         double x = (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
  36.         if (x<=0) notPlus++;
  37.         if (x>=0) notMinus++;
  38.     }
  39.     return (notPlus==3) || (notMinus==3);
  40. }
  41.  
  42. int main()
  43. {
  44.     cout << fixed;
  45.    
  46.         double Ax,Ay,Bx,By,Cx,Cy;
  47.         cin>>Ax>>Ay>>Bx>>By>>Cx>>Cy;
  48.        
  49.         Point aa;
  50.         aa.x = Ax; aa.y = Ay;
  51.         Point bb;
  52.         bb.x = Bx; bb.y = By;
  53.         Point cc;
  54.         cc.x = Cx; cc.y = Cy;
  55.         Point triangle[3] = {aa, bb, cc};
  56.        
  57.         double a = distance(Ax, Bx, Ay, By);
  58.         double b = distance(Ax, Cx, Ay, Cy);
  59.         double c = distance(Bx, Cx, By, Cy);
  60.         double FirstTriangleField = Heron(a, b, c);
  61.    
  62.     int n;
  63.     cin >> n;
  64.     for (int i = 0; i < n; i++)
  65.     {
  66.             double Ax2,Ay2,Bx2,By2,Cx2,Cy2;
  67.             cin>>Ax2>>Ay2>>Bx2>>By2>>Cx2>>Cy2;
  68.             Point X;
  69.             X.x = Ax2; X.y = Ay2;
  70.             Point Y;
  71.             Y.x = Bx2; Y.y = By2;
  72.             Point Z;
  73.             Z.x = Cx2; Z.y = Cy2;
  74.            
  75.            
  76.             double a2 = distance(Ax2, Bx2, Ay2, By2);
  77.             double b2 = distance(Ax2, Cx2, Ay2, Cy2);
  78.             double c2 = distance(Bx2, Cx2, By2, Cy2);
  79.             double TriangleField = Heron(a2, b2, c2);
  80.        
  81.         if (TriangleField <= FirstTriangleField)
  82.         {
  83.             if (isPointInsideTriangle(triangle, X)==true && isPointInsideTriangle(triangle, Y)==true && isPointInsideTriangle(triangle, Z)==true)
  84.             {
  85.                 cout << "tak" << endl;
  86.             }
  87.             cout << "nie" << endl;
  88.         }
  89.         else
  90.         {
  91.             cout << "nie" << endl;
  92.         }
  93.     }
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement