Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 993:e8eabef7857c | 994:8118c6b77d7c |
|---|---|
| 1138 return MovingObject(num = num, timeInterval = timeInterval, positions = positions, velocities = velocities) | 1138 return MovingObject(num = num, timeInterval = timeInterval, positions = positions, velocities = velocities) |
| 1139 | 1139 |
| 1140 @staticmethod | 1140 @staticmethod |
| 1141 def concatenate(obj1, obj2, num = None): | 1141 def concatenate(obj1, obj2, num = None): |
| 1142 '''Concatenates two objects supposed to overlap temporally ''' | 1142 '''Concatenates two objects supposed to overlap temporally ''' |
| 1143 if num is None: | |
| 1144 newNum = obj1.getNum() | |
| 1145 else: | |
| 1146 newNum = num | |
| 1143 commonTimeInterval = obj1.commonTimeInterval(obj2) | 1147 commonTimeInterval = obj1.commonTimeInterval(obj2) |
| 1144 if commonTimeInterval.empty(): | 1148 if commonTimeInterval.empty(): |
| 1145 print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) | 1149 print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) |
| 1146 return None | 1150 emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()) , max(obj1.getFirstInstant(),obj2.getFirstInstant())) |
| 1147 else: | 1151 positions = Trajectory() |
| 1148 if num is None: | 1152 if obj1.existsAtInstant(emptyInterval.last): |
| 1149 newNum = obj1.getNum() | 1153 vitessex=(obj1.getPositionAtInstant(emptyInterval.last).x-obj2.getPositionAtInstant(emptyInterval.first).x)/(emptyInterval.last-emptyInterval.first) |
| 1150 else: | 1154 vitessey=(obj1.getPositionAtInstant(emptyInterval.last).y-obj2.getPositionAtInstant(emptyInterval.first).y)/(emptyInterval.last-emptyInterval.first) |
| 1151 newNum = num | 1155 px,py=obj2.getPositionAtInstant(emptyInterval.first) |
| 1156 else : | |
| 1157 vitessex=(obj2.getPositionAtInstant(emptyInterval.last).x-obj1.getPositionAtInstant(emptyInterval.first).x)/(emptyInterval.last-emptyInterval.first) | |
| 1158 vitessey=(obj2.getPositionAtInstant(emptyInterval.last).y-obj1.getPositionAtInstant(emptyInterval.first).y)/(emptyInterval.last-emptyInterval.first) | |
| 1159 px,py=obj1.getPositionAtInstant(emptyInterval.first) | |
| 1160 positions = Trajectory() | |
| 1161 velocities = Trajectory() | |
| 1162 for t in emptyInterval: | |
| 1163 positions.addPositionXY(px,py) | |
| 1164 velocities.addPositionXY(vitessex,vitessey) | |
| 1165 px+=vitessex | |
| 1166 py+=vitessey | |
| 1167 | |
| 1168 newObject = MovingObject(newNum, emptyInterval, positions, velocities, userType = obj1.getUserType()) | |
| 1169 return MovingObject.concatenate(MovingObject.concatenate(obj1, newObject),obj2) | |
| 1170 | |
| 1171 | |
| 1172 else: | |
| 1152 newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) | 1173 newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval()) |
| 1153 # positions | 1174 # positions |
| 1154 positions = Trajectory() | 1175 positions = Trajectory() |
| 1155 for t in newTimeInterval: | 1176 for t in newTimeInterval: |
| 1156 nTotal = 0. | 1177 nTotal = 0. |
