1st question





solution
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
return fabs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0;
}
bool isInside(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y) {
double A = area(x1, y1, x2, y2, x3, y3);
double A1 = area(x, y, x2, y2, x3, y3);
double A2 = area(x1, y1, x, y, x3, y3);
double A3 = area(x1, y1, x2, y2, x, y);
return (A == A1 + A2 + A3);
}
int pointsBelong(int x1, int y1, int x2, int y2, int x3, int y3, int xp, int yp, int xq, int yq) {
double ab = hypot(x2 - x1, y2 - y1);
double bc = hypot(x3 - x2, y3 - y2);
double ac = hypot(x3 - x1, y3 - y1);
if (!(ab + bc > ac && bc + ac > ab && ab + ac > bc)) {
return 0;
}
bool pInside = isInside(x1, y1, x2, y2, x3, y3, xp, yp);
bool qInside = isInside(x1, y1, x2, y2, x3, y3, xq, yq);
if (pInside && qInside) return 3;
if (pInside && !qInside) return 1;
if (!pInside && qInside) return 2;
return 4;
}
Another slot 1st question

Another slot 1st question

Another slot 1st question


Another slot 1st question



another slot
1st question


