Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- typedef struct { double x; double y; } Point;
- 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()
- {
- double xa, ya, xb, yb, xc, yc;
- cin >> xa >> ya >> xb >> yb >> xc >> yc;
- Point a;
- a.x = xa; a.y = ya;
- Point b;
- b.x = xb; b.y = yb;
- Point c;
- c.x = xc; c.y = yc;
- Point triangle[3] = {a, b, c};
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- double xa2, ya2, xb2, yb2, xc2, yc2;
- cin >> xa2 >> ya2 >> xb2 >> yb2 >> xc2 >> yc2;
- Point aa;
- aa.x = xa2; aa.y = ya2;
- Point bb;
- bb.x = xb2; bb.y = yb2;
- Point cc;
- cc.x = xc2; cc.y = yc2;
- if (isPointInsideTriangle(triangle, aa)==true && isPointInsideTriangle(triangle, bb)==true && isPointInsideTriangle(triangle, cc)==true)
- {
- cout << "tak\n";
- }
- else
- {
- cout << "nie\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement