Mercurial > hg > nsaunier > traffic-intelligence
comparison python/events.py @ 306:93d851d0d21e
bug correction, minor work on indicators
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 02 Apr 2013 15:27:42 -0400 |
| parents | 7e5fb4abd070 |
| children | f7ca78a11ea6 |
comparison
equal
deleted
inserted
replaced
| 305:ca9131968bce | 306:93d851d0d21e |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 '''Libraries for events | 2 '''Libraries for events |
| 3 Interactions, pedestrian crossing...''' | 3 Interactions, pedestrian crossing...''' |
| 4 | 4 |
| 5 import numpy as np | 5 import numpy as np |
| 6 from numpy import arccos | |
| 6 | 7 |
| 7 import multiprocessing | 8 import multiprocessing |
| 8 import itertools | 9 import itertools |
| 9 | 10 |
| 10 import moving | 11 import moving |
| 48 speedDifferentials = {} | 49 speedDifferentials = {} |
| 49 for instant in self.timeInterval: | 50 for instant in self.timeInterval: |
| 50 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) | 51 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) |
| 51 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) | 52 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) |
| 52 collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) | 53 collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) |
| 53 distances[instant] = deltap.norm2() | 54 distances[instant] = deltap.norm2() # todo compute closest feature distance, if features |
| 54 speedDifferentials[instant] = deltav.norm2() | 55 speedDifferentials[instant] = deltav.norm2() |
| 55 if collisionCourseDotProducts[instant] > 0: | 56 if collisionCourseDotProducts[instant] > 0: |
| 56 collisionCourseCosines[instant] = collisionCourseDotProducts[instant]/(distances[instant]*speedDifferentials[instant]) | 57 collisionCourseCosines[instant] = arccos(collisionCourseDotProducts[instant]/(distances[instant]*speedDifferentials[instant])) |
| 58 | |
| 57 # todo shorten the time intervals based on the interaction definition | 59 # todo shorten the time intervals based on the interaction definition |
| 58 # todos change cosines to angles | |
| 59 self.addIndicator(indicators.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts)) | 60 self.addIndicator(indicators.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts)) |
| 60 self.addIndicator(indicators.SeverityIndicator('Distance', distances)) | 61 self.addIndicator(indicators.SeverityIndicator('Distance', distances)) |
| 61 self.addIndicator(indicators.SeverityIndicator('Speed Differential', speedDifferentials)) | 62 self.addIndicator(indicators.SeverityIndicator('Speed Differential', speedDifferentials)) |
| 62 self.addIndicator(indicators.SeverityIndicator('Collision Course Cosine', collisionCourseCosines)) | 63 self.addIndicator(indicators.SeverityIndicator('Collision Course Cosine', collisionCourseCosines)) |
| 64 | |
| 65 # todo test for interaction instants and interval, compute indicators | |
| 63 | 66 |
| 64 | 67 |
| 65 def createInteractions(objects): | 68 def createInteractions(objects): |
| 66 '''Create all interactions of two co-existing road users | 69 '''Create all interactions of two co-existing road users |
| 67 | 70 |
