Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 551:dc3739ac2371
rearranged all distance computations between points
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 08 Jul 2014 16:59:35 -0400 |
| parents | 5668af2ff515 |
| children | ca6bded754ac |
comparison
equal
deleted
inserted
replaced
| 550:5668af2ff515 | 551:dc3739ac2371 |
|---|---|
| 810 axis('equal') | 810 axis('equal') |
| 811 figure(2) | 811 figure(2) |
| 812 plot(list(self.getTimeInterval()), speeds) | 812 plot(list(self.getTimeInterval()), speeds) |
| 813 | 813 |
| 814 @staticmethod | 814 @staticmethod |
| 815 def distances(obj1, obj2, instant): | 815 def distances(obj1, obj2, instant1, _instant2 = None): |
| 816 from scipy.spatial.distance import cdist | 816 from scipy.spatial.distance import cdist |
| 817 positions1 = [f.getPositionAtInstant(instant).astuple() for f in obj1.features if f.existsAtInstant(instant)] | 817 if _instant2 == None: |
| 818 positions2 = [f.getPositionAtInstant(instant).astuple() for f in obj2.features if f.existsAtInstant(instant)] | 818 instant2 = instant1 |
| 819 return cdist(positions1, positions2, metric = 'euclidean') | 819 else: |
| 820 | 820 instant2 = _instant2 |
| 821 @staticmethod | |
| 822 def minDistance(obj1, obj2, instant): | |
| 823 return MovingObject.distances(obj1, obj2, instant).min() | |
| 824 | |
| 825 @staticmethod | |
| 826 def distances2(obj1, obj2, instant1,instant2): | |
| 827 from scipy.spatial.distance import cdist | |
| 828 positions1 = [f.getPositionAtInstant(instant1).astuple() for f in obj1.features if f.existsAtInstant(instant1)] | 821 positions1 = [f.getPositionAtInstant(instant1).astuple() for f in obj1.features if f.existsAtInstant(instant1)] |
| 829 positions2 = [f.getPositionAtInstant(instant2).astuple() for f in obj2.features if f.existsAtInstant(instant2)] | 822 positions2 = [f.getPositionAtInstant(instant2).astuple() for f in obj2.features if f.existsAtInstant(instant2)] |
| 830 return cdist(positions1, positions2, metric = 'euclidean') | 823 return cdist(positions1, positions2, metric = 'euclidean') |
| 831 | 824 |
| 832 @staticmethod | 825 @staticmethod |
| 833 def minDistance2(obj1, obj2, instant1,instant2): | 826 def minDistance(obj1, obj2, instant1, instant2 = None): |
| 834 return MovingObject.distances2(obj1, obj2, instant1,instant2).min() | 827 return MovingObject.distances(obj1, obj2, instant1, instant2).min() |
| 835 | 828 |
| 836 @staticmethod | 829 @staticmethod |
| 837 def maxDistance(obj1, obj2, instant): | 830 def maxDistance(obj1, obj2, instant, instant2 = None): |
| 838 return MovingObject.distances(obj1, obj2, instant).max() | 831 return MovingObject.distances(obj1, obj2, instant1, instant2).max() |
| 839 | 832 |
| 840 def maxSize(self): | 833 def maxSize(self): |
| 841 '''Returns the max distance between features | 834 '''Returns the max distance between features |
| 842 at instant there are the most features''' | 835 at instant there are the most features''' |
| 843 if hasattr(self, 'features'): | 836 if hasattr(self, 'features'): |
| 975 if areas[userTypename][p.x, p.y] != 0: | 968 if areas[userTypename][p.x, p.y] != 0: |
| 976 possibleUserTypes[userType2Enum[userTypename]] += 1 | 969 possibleUserTypes[userType2Enum[userTypename]] += 1 |
| 977 # what to do: threshold for most common type? self.setUserType() | 970 # what to do: threshold for most common type? self.setUserType() |
| 978 return possibleUserTypes | 971 return possibleUserTypes |
| 979 | 972 |
| 980 | |
| 981 @staticmethod | 973 @staticmethod |
| 982 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | 974 def collisionCourseDotProduct(movingObject1, movingObject2, instant): |
| 983 'A positive result indicates that the road users are getting closer' | 975 'A positive result indicates that the road users are getting closer' |
| 984 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | 976 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) |
| 985 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) | 977 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) |
