理论推导:https://www.zhihu.com/question/381406535/answer/1095948349
def calc_abc_from_line_2d(x0, y0, x1, y1):
a = y0-y1
b = x1-x0
c = x0*y1-x1*y0
return a, b, c
def get_line_cross_point(line1, line2):
a0, b0, c0 = calc_abc_from_line_2d(*line1)
a1, b1, c1 = calc_abc_from_line_2d(*line2)
D = a0*b1-a1*b0
if D==0:
return None
x = (b0*c1-b1*c0)/D
y = (a1*c0-a0*c1)/D
return x, y
line1 = [0, 0, 1, 1]
line2 = [0, 1, 1, 0]
print(get_line_cross_point(line1, line2))
(0.5, 0.5)
Process finished with exit code 0