Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
1147:8c0ec7e1eb8e | 1148:eb88d2984637 |
---|---|
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): |
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 | |
226 velocityAngleTolerance: indicates the angle between velocity vector (average for parallel) and position vector''' | |
225 parallelAngleToleranceCosine = np.cos(parallelAngleTolerance) | 227 parallelAngleToleranceCosine = np.cos(parallelAngleTolerance) |
226 self.categories = {} | 228 self.categories = {} |
227 collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0]) | 229 collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0]) |
230 collisionCourseAngles = self.getIndicator(Interaction.indicatorNames[1]) | |
228 velocityAngles = self.getIndicator(Interaction.indicatorNames[4]) | 231 velocityAngles = self.getIndicator(Interaction.indicatorNames[4]) |
229 for instant in self.timeInterval: | 232 for instant in self.timeInterval: |
230 if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end | 233 if velocityAngles[instant] < velocityAngleTolerance: # parallel or rear end |
231 midVelocity = self.roadUser1.getVelocityAtInstant(instant) + self.roadUser2.getVelocityAtInstant(instant) | 234 midVelocity = self.roadUser1.getVelocityAtInstant(instant) + self.roadUser2.getVelocityAtInstant(instant) |
232 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant) | 235 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant) |
233 if moving.Point.dot(midVelocity, deltap) < parallelAngleToleranceCosine: | 236 if moving.Point.dot(midVelocity, deltap) < parallelAngleToleranceCosine: |
234 self.categories[instant] = Interaction.categories["parallel"] | 237 self.categories[instant] = Interaction.categories["parallel"] |
235 else: | 238 else: |
236 self.categories[instant] = Interaction.categories["rearend"] | 239 self.categories[instant] = Interaction.categories["rearend"] |
237 elif velocityAngles[instant] > np.pi - velocityAngleTolerance: # head on | 240 elif velocityAngles[instant] > np.pi - velocityAngleTolerance and collisionCourseAngles[instant] < velocityAngleTolerance: # head on |
238 if collisionCourseDotProducts[instant] > 0: | 241 self.categories[instant] = Interaction.categories["headon"] |
239 self.categories[instant] = Interaction.categories["headon"] | 242 elif collisionCourseDotProducts[instant] > 0: |
240 else: | 243 self.categories[instant] = Interaction.categories["side"] |
241 if collisionCourseDotProducts[instant] > 0: | |
242 self.categories[instant] = Interaction.categories["side"] | |
243 | 244 |
244 def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None): | 245 def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None): |
245 '''Computes all crossing and collision points at each common instant for two road users. ''' | 246 '''Computes all crossing and collision points at each common instant for two road users. ''' |
246 TTCs = {} | 247 TTCs = {} |
247 collisionProbabilities = {} | 248 collisionProbabilities = {} |