Problem · Geometry
Triangle and Points
Learn this problemProblem statement
You are given the coordinates of a triangle with three vertices:
(x1, y1)(x2, y2)(x3, y3)
You are also given two points:
- Point
p = (xp, yp) - Point
q = (xq, yq)
Return the following code:
- Return
1if the three vertices cannot form a triangle. - Return
2if bothpandqlie inside the triangle. - Return
3if onlyplies inside the triangle. - Return
4if onlyqlies inside the triangle. - Return
5if neither point lies inside the triangle.
Boundary rule: A point on an edge or exactly on a vertex is considered inside the triangle.
Input: The triangle coordinates x1, y1, x2, y2, x3, y3, followed by the point coordinates xp, yp, xq, yq.
Function
triangleAndPoints(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, xp: int, yp: int, xq: int, yq: int) → intExamples
Example 1
x1 = 0y1 = 0x2 = 5y2 = 0x3 = 0y3 = 5xp = 1yp = 1xq = 6yq = 6return = 3Only point p lies inside the triangle.