-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlineIntersect.py
52 lines (51 loc) · 1.82 KB
/
lineIntersect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def ccw(A,B,C):
return (C[1]-A[1]) * (B[0]-A[0]) > (B[1]-A[1]) * (C[0]-A[0])
# Return true if line segments AB and CD intersect
def checkIntersect(nodeA,nodeB,OBS):
A=(nodeA.x,nodeA.y)
B=(nodeB.x,nodeB.y)
for o in OBS:
obs=(o[0],o[1],o[0]+o[2],o[1]+o[3])
C1=(obs[0],obs[1])
D1=(obs[0],obs[3])
C2=(obs[0],obs[1])
D2=(obs[2],obs[1])
C3=(obs[2],obs[3])
D3=(obs[2],obs[1])
C4=(obs[2],obs[3])
D4=(obs[0],obs[3])
inst1= ccw(A,C1,D1) != ccw(B,C1,D1) and ccw(A,B,C1) != ccw(A,B,D1)
inst2= ccw(A,C2,D2) != ccw(B,C2,D2) and ccw(A,B,C2) != ccw(A,B,D2)
inst3= ccw(A,C3,D3) != ccw(B,C3,D3) and ccw(A,B,C3) != ccw(A,B,D3)
inst4= ccw(A,C4,D4) != ccw(B,C4,D4) and ccw(A,B,C4) != ccw(A,B,D4)
if inst1==False and inst2==False and inst3==False and inst4==False:
#print(A,B)
#input("Press Enter to continue...")
continue
else:
return False
return True
def checkIntersectPoints(x,y,a,b,OBS):
A=(x,y)
B=(a,b)
for o in OBS:
obs=(o[0],o[1],o[0]+o[2],o[1]+o[3])
C1=(obs[0],obs[1])
D1=(obs[0],obs[3])
C2=(obs[0],obs[1])
D2=(obs[2],obs[1])
C3=(obs[2],obs[3])
D3=(obs[2],obs[1])
C4=(obs[2],obs[3])
D4=(obs[0],obs[3])
inst1= ccw(A,C1,D1) != ccw(B,C1,D1) and ccw(A,B,C1) != ccw(A,B,D1)
inst2= ccw(A,C2,D2) != ccw(B,C2,D2) and ccw(A,B,C2) != ccw(A,B,D2)
inst3= ccw(A,C3,D3) != ccw(B,C3,D3) and ccw(A,B,C3) != ccw(A,B,D3)
inst4= ccw(A,C4,D4) != ccw(B,C4,D4) and ccw(A,B,C4) != ccw(A,B,D4)
if inst1==False and inst2==False and inst3==False and inst4==False:
#print(A,B)
#input("Press Enter to continue...")
continue
else:
return False
return True