Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/events.py @ 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 |
comparison
equal
deleted
inserted
replaced
1148:eb88d2984637 | 1149:392db62ea1da |
---|---|
217 minDistances={} | 217 minDistances={} |
218 for instant in self.timeInterval: | 218 for instant in self.timeInterval: |
219 minDistances[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) | 219 minDistances[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) |
220 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistances, mostSevereIsMax = False)) | 220 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistances, mostSevereIsMax = False)) |
221 | 221 |
222 def categorize(self, velocityAngleTolerance, parallelAngleTolerance): | 222 def categorize(self, velocityAngleTolerance, parallelAngleTolerance, headonCollisionCourseAngleTolerance = None): |
223 '''Computes the interaction category by instant | 223 '''Computes the interaction category by instant |
224 velocityAngleTolerance and parallelAngleTolerance in radian | 224 velocityAngleTolerance and parallelAngleTolerance in radian |
225 velocityAngleTolerance: indicates the angle threshold for rear and head on (180-velocityAngleTolerance), as well as the maximum collision course angle for head on | 225 velocityAngleTolerance: indicates the angle threshold for rear and head on (180-velocityAngleTolerance), as well as the maximum collision course angle for head on |
226 velocityAngleTolerance: indicates the angle between velocity vector (average for parallel) and position vector''' | 226 velocityAngleTolerance: indicates the angle between velocity vector (average for parallel) and position vector''' |
227 parallelAngleToleranceCosine = np.cos(parallelAngleTolerance) | 227 parallelAngleToleranceCosine = np.cos(parallelAngleTolerance) |
228 if headonCollisionCourseAngleTolerance is None: | |
229 headonCollisionCourseAngleTolerance = velocityAngleTolerance | |
230 | |
228 self.categories = {} | 231 self.categories = {} |
229 collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0]) | 232 collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0]) |
230 collisionCourseAngles = self.getIndicator(Interaction.indicatorNames[1]) | 233 collisionCourseAngles = self.getIndicator(Interaction.indicatorNames[1]) |
234 distances = self.getIndicator(Interaction.indicatorNames[2]) | |
231 velocityAngles = self.getIndicator(Interaction.indicatorNames[4]) | 235 velocityAngles = self.getIndicator(Interaction.indicatorNames[4]) |
232 for instant in self.timeInterval: | 236 for instant in self.timeInterval: |
233 if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end | 237 if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end |
234 midVelocity = self.roadUser1.getVelocityAtInstant(instant) + self.roadUser2.getVelocityAtInstant(instant) | 238 midVelocity = self.roadUser1.getVelocityAtInstant(instant) + self.roadUser2.getVelocityAtInstant(instant) |
235 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant) | 239 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant) |
236 if moving.Point.dot(midVelocity, deltap) < parallelAngleToleranceCosine: | 240 if abs(moving.Point.dot(midVelocity, deltap)/(midVelocity.norm2()*distances[instant])) < parallelAngleToleranceCosine: |
237 self.categories[instant] = Interaction.categories["parallel"] | 241 self.categories[instant] = Interaction.categories["parallel"] |
238 else: | 242 else: |
239 self.categories[instant] = Interaction.categories["rearend"] | 243 self.categories[instant] = Interaction.categories["rearend"] |
240 elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < velocityAngleTolerance: # head on | 244 elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < headonCollisionCourseAngleTolerance: # head on |
241 self.categories[instant] = Interaction.categories["headon"] | 245 self.categories[instant] = Interaction.categories["headon"] |
242 elif collisionCourseDotProducts[instant] > 0: | 246 elif collisionCourseDotProducts[instant] > 0: |
243 self.categories[instant] = Interaction.categories["side"] | 247 self.categories[instant] = Interaction.categories["side"] |
244 | 248 |
245 def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None): | 249 def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None): |