def segment_intersection_2D(p12arg, p34arg):
(p1,p2) = p12arg<EOL>(p3,p4) = p34arg<EOL>pi = np.asarray(line_intersection_2D(p12arg, p34arg))<EOL>p1 = np.asarray(p1)<EOL>p2 = np.asarray(p2)<EOL>p3 = np.asarray(p3)<EOL>p4 = np.asarray(p4)<EOL>u12 = p2 - p1<EOL>u34 = p4 - p3<EOL>cfn = lambda px,iis: (px if iis is None or len(px.shape) == <NUM_LIT:1> or px.shape[<NUM_LIT:1>] == len(iis) else<EOL>px[:,iis])<EOL>dfn = lambda a,b:     a[<NUM_LIT:0>]*b[<NUM_LIT:0>] + a[<NUM_LIT:1>]*b[<NUM_LIT:1>]<EOL>sfn = lambda a,b:     ((a-b)                 if len(a.shape) == len(b.shape) else<EOL>(np.transpose([a])-b) if len(a.shape) <  len(b.shape) else<EOL>(a - np.transpose([b])))<EOL>fn  = lambda px,iis:  (<NUM_LIT:1> - ((dfn(cfn(u12,iis), sfn(         px, cfn(p1,iis))) > <NUM_LIT:0>) *<EOL>(dfn(cfn(u34,iis), sfn(         px, cfn(p3,iis))) > <NUM_LIT:0>) *<EOL>(dfn(cfn(u12,iis), sfn(cfn(p2,iis),          px)) > <NUM_LIT:0>) *<EOL>(dfn(cfn(u34,iis), sfn(cfn(p4,iis),          px)) > <NUM_LIT:0>)))<EOL>if len(pi.shape) == <NUM_LIT:1>:<EOL><INDENT>if not np.isfinite(pi[<NUM_LIT:0>]): return (np.nan, np.nan)<EOL>bad = fn(pi, None)<EOL>return (np.nan, np.nan) if bad else pi<EOL><DEDENT>else:<EOL><INDENT>nonpar = np.where(np.isfinite(pi[<NUM_LIT:0>]))[<NUM_LIT:0>]<EOL>bad = fn(cfn(pi, nonpar), nonpar)<EOL>(xi,yi) = pi<EOL>bad = nonpar[np.where(bad)[<NUM_LIT:0>]]<EOL>xi[bad] = np.nan<EOL>yi[bad] = np.nan<EOL>return (xi,yi)<EOL><DEDENT>
segment_intersection((a, b), (c, d)) yields the intersection point between the line segments
that pass from point a to point b and from point c to point d. If there is no intersection
point, then (numpy.nan, numpy.nan) is returned.