Points Inside or Outside a Triangle

Problem Given 5 points in the plane, take any 3 of them as the vertices of a triangle and decide, for each of the remaining 2 points, whether it lies inside or outside that triangle.

Input / Output

  • Input: five (x, y) coordinate pairs, three of them designated as vertices A, B, C.
  • Output: for each of the other two points, "inside" or "outside", with the on-edge case handled explicitly.

Constraints

  • The test must be robust — a floating-point area comparison misclassifies points sitting on or near an edge.
  • Coordinates may be integers, and the method should stay exact when they are.
  • Degenerate case: the three chosen vertices may be collinear, giving a zero-area triangle with nothing strictly inside.
  • Agree up front whether a point exactly on an edge or vertex counts as inside.

Example

  • A=(0,0), B=(4,0), C=(0,4). D=(1,1) → inside. E=(2,2) → lies exactly on edge BC, so one cross product is zero — precisely the case a float-based area test gets wrong.
asked …
LeaderboardSalaryAccount