Mercurial Hosting > traffic-intelligence
changeset 16:9d6831cfe675
added tools for speed
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Wed, 18 Nov 2009 18:36:52 -0500 |
parents | e7bbe8465591 |
children | 9403759cf2c1 |
files | python/moving.py python/ubc_utils.py python/utils.py |
diffstat | 3 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Sat Nov 14 19:02:46 2009 -0500 +++ b/python/moving.py Wed Nov 18 18:36:52 2009 -0500 @@ -3,6 +3,8 @@ import utils; +from math import sqrt, hypot; + from shapely.geometry import Polygon __metaclass__ = type @@ -90,6 +92,9 @@ def __init__(self, positions = None): self.positions = positions + def __str__(self): + return ' '.join(map(utils.printPoint, self.positions[0], self.positions[1])) + def addPosition(self, point): if not self.positions: self.positions = [[point[0]],[point[1]]] @@ -108,7 +113,13 @@ def yBounds(self): # look for function that does min and max in one pass return [min(self.positions[1]), max(self.positions[1])] - + + def norm(self): + '''Returns the list of the norms at each instant''' +# def add(x, y): return x+y +# sq = map(add, [x*x for x in self.positions[0]], [y*y for y in self.positions[1]]) +# return sqrt(sq) + return [hypot(x,y) for x,y in zip(self.positions[0], self.positions[1])] class MovingObject(STObject): '''Class for moving objects @@ -116,9 +127,9 @@ and a type (e.g. road user) ''' - def __init__(self, num = None, timeInterval = None, trajectory = None, geometry = None, type = None): + def __init__(self, num = None, timeInterval = None, positions = None, geometry = None, type = None): STObject.__init__(self, num, timeInterval) - self.trajectory = trajectory + self.positions = positions self.geometry = geometry self.type = type # compute bounding polygon from trajectory
--- a/python/ubc_utils.py Sat Nov 14 19:02:46 2009 -0500 +++ b/python/ubc_utils.py Wed Nov 18 18:36:52 2009 -0500 @@ -36,7 +36,7 @@ obj.positions = Trajectory([[float(n) for n in lines[1].split(' ')], [float(n) for n in lines[2].split(' ')]]) if (len(lines) >= 5): - obj.velocity = Trajectory([[float(n) for n in lines[3].split(' ')], + obj.velocities = Trajectory([[float(n) for n in lines[3].split(' ')], [float(n) for n in lines[4].split(' ')]]) if len(lines) != 2: