Mercurial Hosting > traffic-intelligence
comparison scripts/TTCcomputation.py @ 441:ea907ae19d8c
new TTC added
author | Sohail Zangenehpour <sohail.zangenehpour@mail.mcgill.ca> |
---|---|
date | Thu, 30 Jan 2014 16:35:17 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
440:b5cc6b001ae6 | 441:ea907ae19d8c |
---|---|
1 def TTC(x1,y1,x2,y2,v1x,v1y,v2x,v2y,l): | |
2 | |
3 a = pow(v1x-v2x,2) + pow(v1y-v2y,2) | |
4 b = 2 * ((x1-x2) * (v1x-v2x) + (y1-y2) * (v1y-v2y)) | |
5 c = pow(x1-x2,2) + pow(y1-y2,2) - pow(l,2) | |
6 | |
7 if pow(b,2) >= 4*a*c: | |
8 ttc1 = (-b + sqrt(pow(b,2) - 4*a*c)) / (2*a) | |
9 ttc2 = (-b - sqrt(pow(b,2) - 4*a*c)) / (2*a) | |
10 if ttc1 >= 0 and ttc2 >= 0: | |
11 ttc = min(ttc1,ttc2) | |
12 else: | |
13 if ttc1 < 0: | |
14 ttc = ttc | |
15 if ttc2 < 0: | |
16 ttc = ttc1 | |
17 if ttc1 < 0 and ttc2 < 0: | |
18 ttc = [] | |
19 else: | |
20 ttc = [] | |
21 | |
22 return ttc |