changeset 1149:392db62ea1da

major bug in categorization, added option for method
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 13 May 2020 00:29:34 -0400
parents eb88d2984637
children 14140b55e580
files trafficintelligence/events.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/trafficintelligence/events.py	Tue May 12 01:16:54 2020 -0400
+++ b/trafficintelligence/events.py	Wed May 13 00:29:34 2020 -0400
@@ -219,25 +219,29 @@
                 minDistances[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant)
             self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistances, mostSevereIsMax = False))
 
-    def categorize(self, velocityAngleTolerance, parallelAngleTolerance):
+    def categorize(self, velocityAngleTolerance, parallelAngleTolerance, headonCollisionCourseAngleTolerance = None):
         '''Computes the interaction category by instant
         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)
+        if headonCollisionCourseAngleTolerance is None:
+            headonCollisionCourseAngleTolerance = velocityAngleTolerance
+            
         self.categories = {}
         collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0])
         collisionCourseAngles = self.getIndicator(Interaction.indicatorNames[1])
+        distances = self.getIndicator(Interaction.indicatorNames[2])
         velocityAngles = self.getIndicator(Interaction.indicatorNames[4])
         for instant in self.timeInterval:
             if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end
                 midVelocity = self.roadUser1.getVelocityAtInstant(instant) + self.roadUser2.getVelocityAtInstant(instant)
                 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant)
-                if moving.Point.dot(midVelocity, deltap) < parallelAngleToleranceCosine:
+                if abs(moving.Point.dot(midVelocity, deltap)/(midVelocity.norm2()*distances[instant])) < parallelAngleToleranceCosine:
                     self.categories[instant] = Interaction.categories["parallel"]
                 else:
                     self.categories[instant] = Interaction.categories["rearend"]
-            elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < velocityAngleTolerance: # head on
+            elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < headonCollisionCourseAngleTolerance: # head on
                 self.categories[instant] = Interaction.categories["headon"]
             elif collisionCourseDotProducts[instant] > 0:
                 self.categories[instant] = Interaction.categories["side"]