function pointInTriangle(P, A, B, C) v = B.x - A.x q = B.y - A.y r = C.x - B.x t = C.y - B.y rem if vertices are clockwise if (v*t - q*r) < 0 if v*(P.y-A.y) >= q*(P.x-A.x) then exitfunction 0 if r*(P.y-B.y) >= t*(P.x-B.x) then exitfunction 0 if (A.x-C.x)*(P.y-C.y) >= (A.y-C.y)*(P.x-C.x) then exitfunction 0 rem vertices are counter-clockwise else if v*(P.y-A.y) < q*(P.x-A.x) then exitfunction 0 if r*(P.y-B.y) < t*(P.x-B.x) then exitfunction 0 if (A.x-C.x)*(P.y-C.y) < (A.y-C.y)*(P.x-C.x) then exitfunction 0 endif endfunction 1