Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 71:45e958ccd9bd
added new addPosition method to Trajectory
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 14 Jan 2011 19:34:00 -0500 |
| parents | cc192d0450b3 |
| children | d3e1a7cf3375 |
comparison
equal
deleted
inserted
replaced
| 70:a52653dca25d | 71:45e958ccd9bd |
|---|---|
| 50 '''Largest interval comprising self and interval2''' | 50 '''Largest interval comprising self and interval2''' |
| 51 return TimeInterval(max(self.first, interval2.first), min(self.last, interval2.last)) | 51 return TimeInterval(max(self.first, interval2.first), min(self.last, interval2.last)) |
| 52 | 52 |
| 53 | 53 |
| 54 class TimeInterval(Interval): | 54 class TimeInterval(Interval): |
| 55 '''Temporal interval''' | 55 '''Temporal interval |
| 56 may be modified directly by setting first and last''' | |
| 56 | 57 |
| 57 def __init__(self, first=0, last=-1): | 58 def __init__(self, first=0, last=-1): |
| 58 Interval.__init__(self, first, last, False) | 59 Interval.__init__(self, first, last, False) |
| 59 | 60 |
| 60 def __getitem__(self, i): | 61 def __getitem__(self, i): |
| 183 raise StopIteration | 184 raise StopIteration |
| 184 else: | 185 else: |
| 185 self.iterInstantNum += 1 | 186 self.iterInstantNum += 1 |
| 186 return self[self.iterInstantNum-1] | 187 return self[self.iterInstantNum-1] |
| 187 | 188 |
| 189 def addPositionXY(self, x, y): | |
| 190 if not self.positions: | |
| 191 self.positions = [[x],[y]] | |
| 192 else: | |
| 193 self.positions[0].append(x) | |
| 194 self.positions[1].append(y) | |
| 195 | |
| 188 def addPosition(self, p): | 196 def addPosition(self, p): |
| 189 if not self.positions: | 197 self.addPosition(p.x, p.y) |
| 190 self.positions = [[p.x],[p.y]] | 198 |
| 191 else: | |
| 192 self.positions[0].append(p.x) | |
| 193 self.positions[1].append(p.y) | |
| 194 | |
| 195 def draw(self, options = ''): | 199 def draw(self, options = ''): |
| 196 from matplotlib.pylab import plot | 200 from matplotlib.pylab import plot |
| 197 plot(self.positions[0], self.positions[1], options) | 201 plot(self.positions[0], self.positions[1], options) |
| 198 | 202 |
| 199 def length(self): | 203 def length(self): |
