Mercurial Hosting > traffic-intelligence
changeset 994:8118c6b77d7c
update for objects that do not co-exist (work by https://bitbucket.org/Wendlasida/)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 20 May 2018 10:56:24 -0400 |
parents | e8eabef7857c |
children | 349cd5e73f79 |
files | python/moving.py |
diffstat | 1 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Wed May 16 21:06:52 2018 -0400 +++ b/python/moving.py Sun May 20 10:56:24 2018 -0400 @@ -1140,15 +1140,36 @@ @staticmethod def concatenate(obj1, obj2, num = None): '''Concatenates two objects supposed to overlap temporally ''' + if num is None: + newNum = obj1.getNum() + else: + newNum = num commonTimeInterval = obj1.commonTimeInterval(obj2) if commonTimeInterval.empty(): print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) - return None + emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()) , max(obj1.getFirstInstant(),obj2.getFirstInstant())) + positions = Trajectory() + if obj1.existsAtInstant(emptyInterval.last): + vitessex=(obj1.getPositionAtInstant(emptyInterval.last).x-obj2.getPositionAtInstant(emptyInterval.first).x)/(emptyInterval.last-emptyInterval.first) + vitessey=(obj1.getPositionAtInstant(emptyInterval.last).y-obj2.getPositionAtInstant(emptyInterval.first).y)/(emptyInterval.last-emptyInterval.first) + px,py=obj2.getPositionAtInstant(emptyInterval.first) + else : + vitessex=(obj2.getPositionAtInstant(emptyInterval.last).x-obj1.getPositionAtInstant(emptyInterval.first).x)/(emptyInterval.last-emptyInterval.first) + vitessey=(obj2.getPositionAtInstant(emptyInterval.last).y-obj1.getPositionAtInstant(emptyInterval.first).y)/(emptyInterval.last-emptyInterval.first) + px,py=obj1.getPositionAtInstant(emptyInterval.first) + positions = Trajectory() + velocities = Trajectory() + for t in emptyInterval: + positions.addPositionXY(px,py) + velocities.addPositionXY(vitessex,vitessey) + px+=vitessex + py+=vitessey + + newObject = MovingObject(newNum, emptyInterval, positions, velocities, userType = obj1.getUserType()) + return MovingObject.concatenate(MovingObject.concatenate(obj1, newObject),obj2) + + else: - if num is None: - newNum = obj1.getNum() - else: - newNum = num newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) # positions positions = Trajectory()