1def line_intersection(line1, line2):
2 xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
3 ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])
4
5 def det(a, b):
6 return a[0] * b[1] - a[1] * b[0]
7
8 div = det(xdiff, ydiff)
9 if div == 0:
10 raise Exception('lines do not intersect')
11
12 d = (det(*line1), det(*line2))
13 x = det(d, xdiff) / div
14 y = det(d, ydiff) / div
15 return x, y
16
17print (line_intersection((A, B), (C, D)))
18
19# And FYI, I would use tuples instead of lists for your points. E.g.
20# A = (X, Y)