FastPrepFastPrep
Problem Brief

Triangle and Points

OA

You are given the coordinates of a triangle with three vertices:

  • (x1, y1)
  • (x2, y2)
  • (x3, y3)

Additionally, you are provided the coordinates of two points:

  • Point p: (xp, yp)
  • Point q: (xq, yq)

Your task is to determine the following:

  1. Print '1' if the triangle cannot be formed.
  2. Print '2' if both p and q lie inside the triangle.
  3. Print '3' if only point p lies within the triangle.
  4. Print '4' if only point q lies within the triangle.
  5. Print '5' if neither point lies inside the triangle.

Input Format:

- Coordinates of the triangle vertices: x1, y1, x2, y2, x3, y3

- Coordinates of the points p and q: p(xp, yp), q(xq, yq)

1Example 1

Input
x1 = 0, y1 = 0, x2 = 5, y2 = 0, x3 = 0, y3 = 5, xp = 1, yp = 1, xq = 6, yq = 6
Output
3
Explanation

Only point p lies inside the triangle.

public int triangleAndPoints(int x1, int y1, int x2, int y2, int x3, int y3, int xp, int yp, int xq, int yq) {
  // write your code here
}
Input

x1

0

y1

0

x2

5

y2

0

x3

0

y3

5

xp

1

yp

1

xq

6

yq

6

Output

3

Sign in to submit your solution.