Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/TTCcomputation.py @ 445:f0ce17ea9273
merge done with Sohail s code
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 31 Jan 2014 00:10:31 -0500 |
| parents | ea907ae19d8c |
| children |
comparison
equal
deleted
inserted
replaced
| 444:4a62c3b1eb3a | 445:f0ce17ea9273 |
|---|---|
| 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 |
