I've googled all over for algorithms that do this but I can't find a single one that does it the way I need it to. Right now I am basically summing the areas formed by the three internal triangles and seeing if it equals the whole area but somehow it's not working properly, nor do I know if that's rigorous enough and covers all cases.
def isInsideTriangle(P,p1,p2,p3): #is P inside triangle made by p1,p2,p3?
x,x1,x2,x3 = P[0],p1[0],p2[0],p3[0]
y,y1,y2,y3 = P[1],p1[1],p2[1],p3[1]
full = abs (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))
first = abs (x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2))
second = abs (x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y))
third = abs (x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2))
return abs(first + second + third - full) < .0000001
Example:
print isInsideTriangle((-10,0),(-10,-10),(10,-10),(0,10))
should be true, returns false
but
print isInsideTriangle((0,0),(-10,0),(10,0), (0,10))
returns true as it should