Mercurial Hosting > traffic-intelligence
changeset 1085:7853106677b7
added generate static function for CurvilinearTrajectory and modified how to create them with None list in lanes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 25 Sep 2018 17:08:37 -0400 |
parents | 1a7e0b2c858b |
children | 8734742c08c0 |
files | trafficintelligence/moving.py trafficintelligence/tests/moving.txt |
diffstat | 2 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Tue Jul 24 01:24:42 2018 -0400 +++ b/trafficintelligence/moving.py Tue Sep 25 17:08:37 2018 -0400 @@ -1061,7 +1061,10 @@ class CurvilinearTrajectory(Trajectory): '''Sub class of trajectory for trajectories with curvilinear coordinates and lane assignements longitudinal coordinate is stored as first coordinate (exterior name S) - lateral coordiante is stored as second coordinate''' + lateral coordinate is stored as second coordinate + the third "lane" coordinate is for an alignment id, + whether explicit for a list/dict of alignments, + or implicit for a road with lane numbers''' def __init__(self, S = None, Y = None, lanes = None): if S is None or Y is None or len(S) != len(Y): @@ -1071,10 +1074,22 @@ else: self.positions = [S,Y] if lanes is None or len(lanes) != self.length(): - self.lanes = [] + self.lanes = [None]*int(self.length()) else: self.lanes = lanes + @staticmethod + def generate(s, v, nPoints, lane, y = 0): + '''s is initial position, v is velocity + 0 in lateral coordinate by default + TODO 2D velocity for lane change?''' + S = [s] + for i in range(nPoints-1): + S.append(S[-1]+v) + Y = [y]*nPoints + lanes = [lane]*nPoints + return CurvilinearTrajectory(S, Y, lanes) + def __getitem__(self,i): if isinstance(i, int): return [self.positions[0][i], self.positions[1][i], self.lanes[i]] @@ -1088,7 +1103,7 @@ def getLanes(self): return self.lanes - def addPositionSYL(self, s, y, lane): + def addPositionSYL(self, s, y, lane = None): self.addPositionXY(s,y) self.lanes.append(lane) @@ -1106,7 +1121,7 @@ p1 = self[0] for i in range(1, self.length()): p2 = self[i] - diff.addPositionSYL(p2[0]-p1[0], p2[1]-p1[1], p1[2]) + diff.addPositionSYL(p2[0]-p1[0], p2[1]-p1[1]) p1=p2 if doubleLastPosition and self.length() > 1: diff.addPosition(diff[-1])
--- a/trafficintelligence/tests/moving.txt Tue Jul 24 01:24:42 2018 -0400 +++ b/trafficintelligence/tests/moving.txt Tue Sep 25 17:08:37 2018 -0400 @@ -206,11 +206,20 @@ >>> MovingObject.computePET(o1, o2, 0.1) (15.0, 5, 20) +>>> t = CurvilinearTrajectory.generate(3, 1., 10, 'b') +>>> t.length() +10 +>>> t[3] +[6.0, 0, 'b'] +>>> t = CurvilinearTrajectory.generate(3, 1., 10, 'a', 1.) +>>> t[4] +[7.0, 1.0, 'a'] + >>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4) >>> t.differentiate() # doctest:+ELLIPSIS -[1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] +[1.0, 0.0, None] [1.0, 0.099..., None] [2.0, 0.099..., None] >>> t.differentiate(True) # doctest:+ELLIPSIS -[1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] [2.0, 0.099..., '1'] +[1.0, 0.0, None] [1.0, 0.099..., None] [2.0, 0.099..., None] [2.0, 0.099..., None] >>> t = CurvilinearTrajectory(S = [1.], Y = [0.5], lanes = ['1']) >>> t.differentiate().empty() True