diff python/event.py @ 67:ded58c424783

added indicator computation and modified severity indicator constructor
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 07 Nov 2010 04:21:26 -0500
parents f955e83da499
children 19603b5fa578
line wrap: on
line diff
--- a/python/event.py	Sun Nov 07 01:34:43 2010 -0500
+++ b/python/event.py	Sun Nov 07 04:21:26 2010 -0500
@@ -35,6 +35,21 @@
         else:
             return None
 
+    def computeIndicators(self):
+        collisionCourseDotProduct = [0]*self.timeInterval.length()
+        collisionCourseCosine = {}
+        distances = [0]*self.timeInterval.length()
+        for i,instant in enumerate(self.timeInterval):
+            deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant)
+            deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant)
+            collisionCourseDotProduct[i] = moving.Point.dot(deltap, deltav)
+            distances[i] = deltap.norm2()
+            if collisionCourseDotProduct[i] > 0:
+                collisionCourseCosine[instant] = collisionCourseDotProduct[i]/(distances[i]*deltav.norm2())
+        self.indicators = [moving.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProduct, self.timeInterval),
+                           moving.SeverityIndicator('Distances', distances, self.timeInterval),
+                           moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)]
+
 class Crossing(moving.STObject):
     '''Class for the event of a street crossing