geometry.py

changeset 30
0d9ca37901ed
parent 28
5933250813a3
child 31
02e7e1d73ebb
equal deleted inserted replaced
29:db6ca177c6c4 30:0d9ca37901ed
440 intersection = line_intersection_xy(line_1, line_2) 440 intersection = line_intersection_xy(line_1, line_2)
441 if intersection: 441 if intersection:
442 a, b = line_1.vertices 442 a, b = line_1.vertices
443 c, d = line_2.vertices 443 c, d = line_2.vertices
444 try: 444 try:
445 t = (intersection.x - a.x) / (b.x - a.x) 445 t1 = (intersection.x - a.x) / (b.x - a.x)
446 except ZeroDivisionError: 446 except ZeroDivisionError:
447 t = inf 447 t1 = inf
448 try: 448 try:
449 u = (intersection.y - a.y) / (b.y - a.y) 449 t2 = (intersection.x - c.x) / (d.x - c.x)
450 except ZeroDivisionError: 450 except ZeroDivisionError:
451 u = inf 451 t2 = inf
452 if 0 < t < 1 or 0 < u < 1: 452 try:
453 u1 = (intersection.y - a.y) / (b.y - a.y)
454 except ZeroDivisionError:
455 u1 = inf
456 try:
457 u2 = (intersection.y - c.y) / (d.y - c.y)
458 except ZeroDivisionError:
459 u2 = inf
460 if (0 < t1 < 1 and 0 < t2 < 1) or (0 < u1 < 1 and 0 < u2 < 1):
453 return intersection 461 return intersection
454 else: 462 else:
455 return None 463 return None
456 else: 464 else:
457 return None 465 return None

mercurial