Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cmath>
- using namespace std;
- typedef struct { double x; double y; } Point;
- double Heron(double a, double b, double c){
- double p=(a+b+c)/2;
- return sqrt(p*(p-a)*(p-b)*(p-c));
- }
- double distance(int x1, int x2, int y1, int y2)
- {
- return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
- }
- double GetTriangle()
- {
- double Ax,Ay,Bx,By,Cx,Cy;
- cin>>Ax>>Ay>>Bx>>By>>Cx>>Cy;
- double a = distance(Ax, Bx, Ay, By);
- double b = distance(Ax, Cx, Ay, Cy);
- double c = distance(Bx, Cx, By, Cy);
- return Heron(a, b, c);
- }
- bool isPointInsideTriangle(const Point triangle[3], const Point &b)
- {
- int notPlus(0), notMinus(0);
- for (int i=0; i<=3; i++) {
- const Point &a= triangle[i%3];
- const Point &c= triangle[i-1];
- double x = (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
- if (x<=0) notPlus++;
- if (x>=0) notMinus++;
- }
- return (notPlus==3) || (notMinus==3);
- }
- int main()
- {
- cout << fixed;
- double Ax,Ay,Bx,By,Cx,Cy;
- cin>>Ax>>Ay>>Bx>>By>>Cx>>Cy;
- Point aa;
- aa.x = Ax; aa.y = Ay;
- Point bb;
- bb.x = Bx; bb.y = By;
- Point cc;
- cc.x = Cx; cc.y = Cy;
- Point triangle[3] = {aa, bb, cc};
- double a = distance(Ax, Bx, Ay, By);
- double b = distance(Ax, Cx, Ay, Cy);
- double c = distance(Bx, Cx, By, Cy);
- double FirstTriangleField = Heron(a, b, c);
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- double Ax2,Ay2,Bx2,By2,Cx2,Cy2;
- cin>>Ax2>>Ay2>>Bx2>>By2>>Cx2>>Cy2;
- Point X;
- X.x = Ax2; X.y = Ay2;
- Point Y;
- Y.x = Bx2; Y.y = By2;
- Point Z;
- Z.x = Cx2; Z.y = Cy2;
- double a2 = distance(Ax2, Bx2, Ay2, By2);
- double b2 = distance(Ax2, Cx2, Ay2, Cy2);
- double c2 = distance(Bx2, Cx2, By2, Cy2);
- double TriangleField = Heron(a2, b2, c2);
- if (TriangleField <= FirstTriangleField)
- {
- if (isPointInsideTriangle(triangle, X)==true && isPointInsideTriangle(triangle, Y)==true && isPointInsideTriangle(triangle, Z)==true)
- {
- cout << "tak" << endl;
- }
- cout << "nie" << endl;
- }
- else
- {
- cout << "nie" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement