def in_triangle(point, triangle): """Checks if a specified point is inside a triangle using the barycenter technique. :param point: The point to be checked :type point: list :param triangle: The triangle :type triangle: list :returns: True if the point is inside the triangle. :rtype: bool """ A, B, C = map(lambda t: Vec(*t), triangle) P = Vec(*point) u = B - A v = C - A w = P - A vxw = v.cross(w) vxu = v.cross(u) if vxw.dot(vxu) < 0: return False uxw = u.cross(w) uxv = u.cross(v) if uxw.dot(uxv) < 0: return False denom = uxv.mag() r = vxw.mag() / denom t = uxw.mag() / denom return (r + t <= 1)
def is_degenerate(triangle): """Checks if the triangle is degenerate. :param triangle: The triangle to be checked. :type triangle: list :returns: Wether the triangle is degenerate or not :rtype: bool """ A, B, C = map(lambda t: Vec(*t), triangle) u = B - A v = C - A uxv = u.cross(v) return uxv.mag() == 0