All pastes #180905 Raw Edit

madewokherd

public python v1 · immutable
#180905 ·published 2006-09-24 09:06 UTC
rendered paste body
def segments_intersect(a1, a2, b1, b2):    return _intersection_helper(a1, a2, b1, b2) and _intersection_helper(b1, b2, a1, a2)def _intersection_helper(a1, a2, b1, b2):    dy = a2[1]-a1[1]    dx = a1[0]-a2[0]    c = a1[1]*a2[0]-a2[1]*a1[0]    side1 = dy*b1[0]+dx*b1[1]+c    if side1 == 0:        return True    side2 = dy*b2[0]+dx*b2[1]+c    if side2 == 0:        return True    if side2 > 0:        return side1 < 0    else:        return side1 > 0