Given three points a(x1, y1), b(x2, y2), and c(x3, y3), determine if they form a non-degenerate triangle. Then, check if two points, p(xp, yp) and q(xq, yq), are inside or on the triangle.
Return the corresponding scenario number:
0. The lines do not form a valid non-degenerate triangle.
1. Point p is inside the triangle, but point q is not.
2. Point q is inside the triangle, but point p is not.
3. Both points p and q are inside the triangle.
4. Neither point p nor point q is inside the triangle.
Note: A triangle is considered non-degenerate if it meets the following conditions, where |ab| denotes the length of the line segment between points a and b:
ยท |ab| + |bc| > |ac|
ยท |bc| + |ac| > |ab|
ยท |ab| + |ac| > |bc|
Example
1 = a(x1, y1) : (2, 2)
2 = b(x2, y2) : (7, 2)
3 = c(x3, y3) : (5, 4)
Asked in:
MEESHO