old inside triangle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def inside_tri(tri, p):
a = tri[0]
b = tri[1]
c = tri[2]
m = (a[0] - p[0]) * (b[1] - a[1]) - (b[0] - a[0]) * (a[1] - p[1])
n = (b[0] - p[0]) * (c[1] - b[1]) - (c[0] - b[0]) * (b[1] - p[1])
k = (c[0] - p[0]) * (a[1] - c[1]) - (a[0] - c[0]) * (c[1] - p[1])
if ((m > 0) and (n > 0) and (k > 0)) or ((m < 0) and (n < 0) and (k < 0)) or (m == 0) or (n == 0) or (k == 0):
return True
else:
return False
def in_tri(tri, p):
if inside_tri(tri, p):
print "triag:", tri, "point:", p;
return True
else:
return False