Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 555:f13220f765e0
added static methods to create trajectories and moving objects
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sun, 13 Jul 2014 23:34:00 -0400 |
| parents | ca6bded754ac |
| children | 259ccb3dd962 |
comparison
equal
deleted
inserted
replaced
| 554:7d051afcb22d | 555:f13220f765e0 |
|---|---|
| 418 self.positions = positions | 418 self.positions = positions |
| 419 else: | 419 else: |
| 420 self.positions = [[],[]] | 420 self.positions = [[],[]] |
| 421 | 421 |
| 422 @staticmethod | 422 @staticmethod |
| 423 def generate(p, v, nPoints): | |
| 424 t = Trajectory() | |
| 425 p0 = Point(p.x, p.y) | |
| 426 t.addPosition(p0) | |
| 427 for i in xrange(nPoints-1): | |
| 428 p0 += v | |
| 429 t.addPosition(p0) | |
| 430 return t, Trajectory([[v.x]*nPoints, [v.y]*nPoints]) | |
| 431 | |
| 432 @staticmethod | |
| 423 def load(line1, line2): | 433 def load(line1, line2): |
| 424 return Trajectory([[float(n) for n in line1.split(' ')], | 434 return Trajectory([[float(n) for n in line1.split(' ')], |
| 425 [float(n) for n in line2.split(' ')]]) | 435 [float(n) for n in line2.split(' ')]]) |
| 426 | 436 |
| 427 @staticmethod | 437 @staticmethod |
| 722 self.geometry = geometry | 732 self.geometry = geometry |
| 723 self.userType = userType | 733 self.userType = userType |
| 724 self.features = [] | 734 self.features = [] |
| 725 # compute bounding polygon from trajectory | 735 # compute bounding polygon from trajectory |
| 726 | 736 |
| 737 @staticmethod | |
| 738 def generate(p, v, timeInterval): | |
| 739 positions, velocities = Trajectory.generate(p, v, int(timeInterval.length())) | |
| 740 return MovingObject(timeInterval = timeInterval, positions = positions, velocities = velocities) | |
| 741 | |
| 727 def getObjectInTimeInterval(self, inter): | 742 def getObjectInTimeInterval(self, inter): |
| 728 '''Returns a new object extracted from self, | 743 '''Returns a new object extracted from self, |
| 729 restricted to time interval inter''' | 744 restricted to time interval inter''' |
| 730 intersection = TimeInterval.intersection(inter, self.getTimeInterval()) | 745 intersection = TimeInterval.intersection(inter, self.getTimeInterval()) |
| 731 if not intersection.empty(): | 746 if not intersection.empty(): |
