Point Inside a Triangle
Problem statement
Given three non-collinear integer triangle vertices and one integer point, return whether the point lies inside the triangle.
A point on an edge or vertex counts as inside. The vertices may be clockwise or counterclockwise.
Function
isPointInsideTriangle(triangle: int[][], point: int[]) → booleanExamples
Example 1
triangle = [[0,0],[5,0],[0,5]]point = [1,1]return = trueThe point lies strictly inside.
Example 2
triangle = [[0,0],[5,0],[0,5]]point = [3,3]return = falseThe point lies beyond the hypotenuse.
Example 3
triangle = [[0,0],[5,0],[0,5]]point = [0,2]return = trueAn edge point counts as inside.
Constraints
triangle.length == 3, every coordinate row has length 2, andpoint.length == 2.- Coordinates are between -10^9 and 10^9.
- The triangle has nonzero area.