+
+ def det(a, b, c):
+ return ((b[0] - a[0]) * (c[1] - a[1]) -
+ (b[1] - a[1]) * (c[0] - a[0]) )
+
+ det = staticmethod(det)
+
+ def pointInPolygon(q, P):
+ is_in = False
+
+ point_at_infinity = NMesh.Vert(-INF, q.co[1], -INF)
+
+ det = HSR.det
+
+ for i in range(len(P.v)):
+ p0 = P.v[i-1]
+ p1 = P.v[i]
+ if (det(q.co, point_at_infinity.co, p0.co)<0) != (det(q.co, point_at_infinity.co, p1.co)<0):
+ if det(p0.co, p1.co, q.co) == 0 :
+ #print "On Boundary"
+ return False
+ elif (det(p0.co, p1.co, q.co)<0) != (det(p0.co, p1.co, point_at_infinity.co)<0):
+ is_in = not is_in
+
+ return is_in
+
+ pointInPolygon = staticmethod(pointInPolygon)
+