Find if a point is within a triangle.



Task

   Assume points are on a plane defined by (x, y) real number coordinates.
   Given a point P(x, y) and a triangle formed by points A, B, and C, determine if P is within triangle ABC. 
   You may use any algorithm. 
   Bonus: explain why the algorithm you chose works.


Related tasks

   Determine_if_two_triangles_overlap


Also see

 Discussion of several methods. [[1]]
 Determine if a point is in a polygon [[2]]
 Triangle based coordinate systems [[3]]
 Wolfram entry [[4]]


with javascript_semantics
constant p0 = {0,0},
         p1 = {0,1},    
         p2 = {3,1},    
         triangle = {{3/2, 12/5}, {51/10, -31/10}, {-19/5, 1/2}}
function inside(sequence p)
    return sort(convex_hull({p}&triangle))==sort(deep_copy(triangle))
end function
printf(1,"Point %v is with triangle %v?:%t\n",{p0,triangle,inside(p0)})
printf(1,"Point %v is with triangle %v?:%t\n",{p1,triangle,inside(p1)})
printf(1,"Point %v is with triangle %v?:%t\n",{p2,triangle,inside(p2)})
