diff python/moving.py @ 484:6464e4f0cc26

integrated Sohail direct computation of TTC (need to add pPET)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 02 Apr 2014 17:45:18 -0400
parents dcc821b98efc
children c81cbd6953fb
line wrap: on
line diff
--- a/python/moving.py	Wed Apr 02 17:25:50 2014 -0400
+++ b/python/moving.py	Wed Apr 02 17:45:18 2014 -0400
@@ -267,23 +267,23 @@
         return Point.cosine(self, refDirection) >= cosineThreshold
 
     @staticmethod
-    def timeToCollision(p1, p2, v1, v2):
+    def timeToCollision(p1, p2, v1, v2, collisionThreshold):
         from math import sqrt
-        a = pow(v1.x-v2.x,2) + pow(v1.y-v2.y,2)
+        a = (v1.x-v2.x)**2 + (v1.y-v2.y)**2
         b = 2 * ((p1.x-p2.x) * (v1.x-v2.x) + (p1.y-p2.y) * (v1.y-v2.y))
-        c = pow(p1.x-p2.x,2) + pow(p1.y-p2.y,2) - pow(l,2)
+        c = (p1.x-p2.x)**2 + (p1.y-p2.y)**2 - collisionThreshold**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 b**2 >= 4*a*c:
+            ttc1 = (-b + sqrt(b**2 - 4*a*c)) / (2*a)
+            ttc2 = (-b - sqrt(b**2 - 4*a*c)) / (2*a)
             if ttc1 >= 0 and ttc2 >= 0:
                 ttc = min(ttc1,ttc2)
             else:
                 if ttc1 < 0:
                     ttc = ttc2
-                if ttc2 < 0:
+                elif ttc2 < 0:
                     ttc = ttc1
-                if ttc1 < 0 and ttc2 < 0:
+                else: # ttc1 < 0 and ttc2 < 0:
                     ttc = None
         else:
             ttc = None