changeset 441:ea907ae19d8c

new TTC added
author Sohail Zangenehpour <sohail.zangenehpour@mail.mcgill.ca>
date Thu, 30 Jan 2014 16:35:17 -0500
parents b5cc6b001ae6
children f0ce17ea9273 cb41f9a4652b
files scripts/TTCcomputation.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/TTCcomputation.py	Thu Jan 30 16:35:17 2014 -0500
@@ -0,0 +1,22 @@
+def TTC(x1,y1,x2,y2,v1x,v1y,v2x,v2y,l):
+
+    a = pow(v1x-v2x,2) + pow(v1y-v2y,2)
+    b = 2 * ((x1-x2) * (v1x-v2x) + (y1-y2) * (v1y-v2y))
+    c = pow(x1-x2,2) + pow(y1-y2,2) - pow(l,2)
+    
+    if pow(b,2) >= 4*a*c:
+        ttc1 = (-b + sqrt(pow(b,2) - 4*a*c)) / (2*a)
+        ttc2 = (-b - sqrt(pow(b,2) - 4*a*c)) / (2*a)
+        if ttc1 >= 0 and ttc2 >= 0:
+            ttc = min(ttc1,ttc2)
+        else:
+            if ttc1 < 0:
+                ttc = ttc
+            if ttc2 < 0:
+                ttc = ttc1
+            if ttc1 < 0 and ttc2 < 0:
+                ttc = []
+    else:
+        ttc = []
+
+    return ttc