def line_intersection_2D(abarg, cdarg):
((x1,y1),(x2,y2)) = abarg<EOL>((x3,y3),(x4,y4)) = cdarg<EOL>dx12 = (x1 - x2)<EOL>dx34 = (x3 - x4)<EOL>dy12 = (y1 - y2)<EOL>dy34 = (y3 - y4)<EOL>denom = dx12*dy34 - dy12*dx34<EOL>unit = np.isclose(denom, <NUM_LIT:0>)<EOL>if unit is True: return (np.nan, np.nan)<EOL>denom = unit + denom<EOL>q12 = (x1*y2 - y1*x2) / denom<EOL>q34 = (x3*y4 - y3*x4) / denom<EOL>xi = q12*dx34 - q34*dx12<EOL>yi = q12*dy34 - q34*dy12<EOL>if   unit is False: return (xi, yi)<EOL>elif unit is True:  return (np.nan, np.nan)<EOL>else:<EOL><INDENT>xi = np.asarray(xi)<EOL>yi = np.asarray(yi)<EOL>xi[unit] = np.nan<EOL>yi[unit] = np.nan<EOL>return (xi, yi)<EOL><DEDENT>
line_intersection((a, b), (c, d)) yields the intersection point between the lines that pass
through the given pairs of points. If any lines are parallel, (numpy.nan, numpy.nan) is
returned; note that a, b, c, and d can all be 2 x n matrices of x and y coordinate row-vectors.