def seg_intersect(a1,a2, b1,b2):
    da = a2-a1
    db = b2-b1
    dp = a1-b1
    
    dap = numpy.copy(da)
    dap[0] = -da[1]
    dap[1] = da[0]
    
    denom = numpy.dot(dap, db)
    num = numpy.dot(dap, dp)
    intersect = (num / denom)*db + b1
    if intersect[0] > max(a1[0], a2[0]) or intersect[0] < min(a1[0], a2[0]) or \
        intersect[1] > max(a1[1], a2[1]) or intersect[1] < min(a1[1], a2[1]):
        return None
    return intersect
line segment intersection using vectors
dataset/ETHPy150Open pycollada/meshtool/meshtool/filters/simplify_filters/sander_simplify.py/seg_intersect