from itertools import izip
def find_intersection(lineA, lineB):
for pos, (A0, B0, A1, B1) in enumerate(izip(lineA, lineB, lineA[1:], lineB[1:])):
#check integer intersections
if A0 == B0: #check required if the intersection is at position 0
return pos
if A1 == B1: #check required if the intersection is at last position
return pos + 1
#check for intersection between points
if (A0 > B0 and A1 < B1) or
(A0 < B0 and A1 > B1):
#intersection between pos and pos+1!
return pos + solve_linear_equation(A0,A1,B0,B1)
#no intersection
return None
...solve_linear_equationセグメント(0,A0)→(1,A1)との交点を見つけ(0,B0)→(1,B1)ます。