def point_relative(p1, p2, p): assert len(p) == 2 assert len(p1) == 2 assert len(p2) == 2 """ p1p2 (l) - line p - point :param p1: :param p2: :param p: :return: -1 if P left to l 1 if P right to l 0 if P on the l """ d = dt(p1, p2, p) if d == 0: return 0 else: if d > 0: return 1 else: return -1
def octano_test(p, p0): assert len(p) > 2 assert len(p0) == 2 """ :param p: :param p0: :return: true if p0 in p false if not """ if gaborit_test(p, p0) is False: return False big_delta = [0 for _ in range(len(p))] v1 = [vector1(x, p0) for x in p] v2 = v1.copy() v2.pop(0) v2.append(v1[0]) s = 0 for i in range(len(p)): delta1 = oct(v1[i - 1]) delta2 = oct(v2[i - 1]) big_delta[i] = delta2 - delta1 if big_delta[i] > 4: big_delta[i] = big_delta[i] - 8 elif big_delta[i] < -4: big_delta[i] = big_delta[i] + 8 elif big_delta[i] == 4 or big_delta[i] == -4: d = dt(p[i - 1], p[i], p0) if d < 0: big_delta[i] = -4 elif d > 0: big_delta[i] = 4 s = s + big_delta[i] if s == 8 or s == -8: return True elif s == 0: return False
def is_intersect(p1, p2, p3, p4): assert len(p1) == 2 assert len(p2) == 2 assert len(p3) == 2 assert len(p4) == 2 """ p1p2 (l1) - line p3p4 (l2) - line :param p1: :param p2: :param p3: :param p4: :return: True if l1 and l2 have same point(points) False if not """ d1 = dt(p3, p4, p1) d2 = dt(p3, p4, p2) d3 = dt(p1, p2, p3) d4 = dt(p1, p2, p4) p = [p1, p2, p3, p4] tmp1 = [] x = [p[i][0] for i in range(4)] y = [p[i][1] for i in range(4)] if d1 != 0 or d2 != 0 or d3 != 0 or d4 != 0: if d1 * d2 <= 0 and d3 * d4 <= 0: return True else: return False else: if is_same(p): # line and point return True elif p1[0] == p2[0] and p1[0] == p3[0] and p1[0] == p4[0]: # x equals for i in range(len(y)): tmp1 = [] tmp2 = y.copy() min_y_p = min(y) tmp1.append(min_y_p) tmp2.remove(min_y_p) min_y_p = min(tmp2) tmp1.append(min_y_p) if [p1[1], p2[1]].sort() == tmp1.sort() or [p3[1], p4[1]].sort() == tmp1.sort(): return False else: return True elif p1[1] == p2[1] and p1[1] == p3[1] and p1[1] == p4[1]: # y equals for i in range(len(x)): tmp2 = x.copy() min_x_p = min(x) tmp1.append(min_x_p) tmp2.remove(min_x_p) min_x_p = min(tmp2) tmp1.append(min_x_p) if [p1[0], p2[0]].sort() == tmp1.sort() or [p3[0], p4[0]].sort() == tmp1.sort(): return False else: return True else: # in formula l: y = k*x + b; k equals for i in range(len(y)): tmp1 = [] tmp2 = y.copy() min_y_p = min(y) tmp1.append(min_y_p) tmp2.remove(min_y_p) min_y_p = min(tmp2) tmp1.append(min_y_p) if [p1[1], p2[1]].sort() == tmp1.sort() or [p3[1], p4[1]].sort() == tmp1.sort(): return False else: return True
def on_line(line, point): assert len(line) == 2 assert len(point) == 2 return dt(line[0], line[1], point) == 0
def is_right(point1, point2, point): assert len(point) == 2 assert len(point1) == 2 assert len(point2) == 2 return dt(point1, point2, point) > 0
def is_left(line, point): assert len(line) == 2 assert len(point) == 2 return dt(line[0], line[1], point) < 0
def on_line(point1, point2, point): assert len(point) == 2 assert len(point1) == 2 assert len(point2) == 2 return dt(point1, point2, point) == 0
def is_left(point1, point2, point): assert len(point) == 2 assert len(point1) == 2 assert len(point2) == 2 return dt(point1, point2, point) < 0
def is_right(line, point): assert len(line) == 2 assert len(point) == 2 return dt(line[0], line[1], point) > 0