# HG changeset patch # User Nicolas Saunier # Date 1589344174 14400 # Node ID 392db62ea1da0863140aab414be0756f00c6576e # Parent eb88d2984637932127f43cff4e8c485b19b6a26a major bug in categorization, added option for method diff -r eb88d2984637 -r 392db62ea1da trafficintelligence/events.py --- 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"]