diff trafficintelligence/events.py @ 1148:eb88d2984637

corrected interaction classification
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 12 May 2020 01:16:54 -0400
parents 8c0ec7e1eb8e
children 392db62ea1da
line wrap: on
line diff
--- a/trafficintelligence/events.py	Wed May 06 00:58:21 2020 -0400
+++ b/trafficintelligence/events.py	Tue May 12 01:16:54 2020 -0400
@@ -221,10 +221,13 @@
 
     def categorize(self, velocityAngleTolerance, parallelAngleTolerance):
         '''Computes the interaction category by instant
-        velocityAngleTolerance and parallelAngleTolerance in radian'''
+        velocityAngleTolerance and parallelAngleTolerance in radian
+        velocityAngleTolerance: indicates the angle threshold for rear and head on (180-velocityAngleTolerance), as well as the maximum collision course angle for head on
+        velocityAngleTolerance: indicates the angle between velocity vector (average for parallel) and position vector'''
         parallelAngleToleranceCosine = np.cos(parallelAngleTolerance)
         self.categories = {}
         collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0])
+        collisionCourseAngles = self.getIndicator(Interaction.indicatorNames[1])
         velocityAngles = self.getIndicator(Interaction.indicatorNames[4])
         for instant in self.timeInterval:
             if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end
@@ -234,12 +237,10 @@
                     self.categories[instant] = Interaction.categories["parallel"]
                 else:
                     self.categories[instant] = Interaction.categories["rearend"]
-            elif velocityAngles[instant] > np.pi - velocityAngleTolerance: # head on
-                if collisionCourseDotProducts[instant] > 0:
-                    self.categories[instant] = Interaction.categories["headon"]
-            else:
-                if collisionCourseDotProducts[instant] > 0:
-                    self.categories[instant] = Interaction.categories["side"]
+            elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < velocityAngleTolerance: # head on
+                self.categories[instant] = Interaction.categories["headon"]
+            elif collisionCourseDotProducts[instant] > 0:
+                self.categories[instant] = Interaction.categories["side"]
 
     def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None):
         '''Computes all crossing and collision points at each common instant for two road users. '''