#K51402. Determine Point Position Relative to a Triangle
Determine Point Position Relative to a Triangle
Determine Point Position Relative to a Triangle
Given the coordinates of three vertices of a triangle: \( (x_1, y_1) \), \( (x_2, y_2) \), \( (x_3, y_3) \), and a point \( (x, y) \), determine whether the point lies inside the triangle, on its boundary, or outside the triangle.
To solve this problem, you can use the concept of the signed area (determinant) of triangles. A helper function to compute the sign of the area formed by three points can be given by:
\( sign = (x - x_3)(y_1 - y_3) - (x_1 - x_3)(y - y_3) \)
If the signs for the three triangle areas (formed by the point and two triangle vertices) are all non-negative or all non-positive, the point is either inside or on the boundary. If any of the areas is zero, it lies on the boundary.
inputFormat
The input consists of a single line with eight space-separated numbers: \( x_1 \) \( y_1 \) \( x_2 \) \( y_2 \) \( x_3 \) \( y_3 \) \( x \) \( y \), where the first six numbers represent the coordinates of the triangle's vertices and the last two represent the point to be tested.
outputFormat
Output a single word: Inside
, Boundary
, or Outside
based on whether the given point is inside the triangle, lies on its boundary, or is outside.
0 0 4 0 2 3 2 2
Inside