Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 67:ded58c424783
added indicator computation and modified severity indicator constructor
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 07 Nov 2010 04:21:26 -0500 |
parents | 56fe4ef1377e |
children | 846fa9dc47de |
line wrap: on
line diff
--- a/python/moving.py Sun Nov 07 01:34:43 2010 -0500 +++ b/python/moving.py Sun Nov 07 04:21:26 2010 -0500 @@ -66,7 +66,7 @@ return self def next(self): - if self.iterInstantNum >= self.length(): + if self.iterInstantNum >= self.length()-1: raise StopIteration else: self.iterInstantNum += 1 @@ -139,6 +139,10 @@ return [self.x, self.y] @staticmethod + def dot(p1, p2): + return p1.x*p2.x+p1.y*p2.y + + @staticmethod def distanceNorm2(p1, p2): return (p1-p2).norm2() @@ -307,6 +311,12 @@ def getVelocityAt(self, i): return self.velocities[i] + def getPositionAtInstant(self, i): + return self.positions[i-self.getFirstInstant()] + + def getVelocityAtInstant(self, i): + return self.velocities[i-self.getFirstInstant()] + def getXCoordinates(self): return self.positions.getXCoordinates() @@ -334,7 +344,19 @@ instants.append(self.timeInterval[i]*(1-ratio)+ratio*self.timeInterval[i+1]) return instants - # def computeVelocities(self): + @staticmethod + def collisionCourseDotProduct(movingObject1, movingObject2, instant): + 'A positive result indicates that the road users are getting closer' + deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) + deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) + return moving.Point.dot(deltap, deltav) + + @staticmethod + def collisionCourseCosine(movingObject1, movingObject2, instant): + 'A positive result indicates that the road users are getting closer' + deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) + deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) + return moving.Point.dot(deltap, deltav)/(deltap.norm2()*deltav.norm2()) def plotRoadUsers(objects, colors): '''Colors is a PlottingPropertyValues instance''' @@ -366,9 +388,8 @@ field mostSevereIsMax is True if the most severe value taken by the indicator is the maximum''' - def __init__(self, name, values, mostSevereIsMax=True, ignoredValue = None): - # , timeInterval=None # implement later - TemporalIndicator.__init__(self, name, values, timeInterval=None) + def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, ignoredValue = None): + TemporalIndicator.__init__(self, name, values, timeInterval) self.mostSevereIsMax = mostSevereIsMax self.ignoredValue = ignoredValue