Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/moving.py @ 1116:a3982d591a61
placeholder implementation for interpolateCurvilinearPositions
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 24 Jun 2019 22:34:36 -0400 |
| parents | cef7aa2f9931 |
| children | bb58506c1bfd |
comparison
equal
deleted
inserted
replaced
| 1115:cef7aa2f9931 | 1116:a3982d591a61 |
|---|---|
| 1445 if withOrigin and len(instants)>0: | 1445 if withOrigin and len(instants)>0: |
| 1446 plot([instants[0]], [coords[0]], 'ro', **kwargs) | 1446 plot([instants[0]], [coords[0]], 'ro', **kwargs) |
| 1447 else: | 1447 else: |
| 1448 print('Object {} has no curvilinear positions'.format(self.getNum())) | 1448 print('Object {} has no curvilinear positions'.format(self.getNum())) |
| 1449 | 1449 |
| 1450 def interpolateCurvilinearPositions(self, t): | 1450 def interpolateCurvilinearPositions(self, t, alignments = None): |
| 1451 '''Linear interpolation of curvilinear positions, t being a float''' | 1451 '''Linear interpolation of curvilinear positions, t being a float''' |
| 1452 if hasattr(self, 'curvilinearPositions'): | 1452 if hasattr(self, 'curvilinearPositions'): |
| 1453 if self.existsAtInstant(t): | 1453 if self.existsAtInstant(t): |
| 1454 i = int(floor(t)) | 1454 i = int(floor(t)) |
| 1455 p1 = self.getCurvilinearPositionAtInstant(i) | 1455 p1 = self.getCurvilinearPositionAtInstant(i) |
| 1456 p2 = self.getCurvilinearPositionAtInstant(i+1) | 1456 p2 = self.getCurvilinearPositionAtInstant(i+1) |
| 1457 if p1[2] == p2[2]: | 1457 if p1[2] == p2[2]: |
| 1458 alpha = t-float(i) | 1458 alpha = t-float(i) |
| 1459 # if alpha < 0.5: | |
| 1460 # lane = p1[2] | |
| 1461 # else: | |
| 1462 # lane = p2[2] | |
| 1463 return [(1-alpha)*p1[0]+alpha*p2[0], (1-alpha)*p1[1]+alpha*p2[1], p1[2]] | 1459 return [(1-alpha)*p1[0]+alpha*p2[0], (1-alpha)*p1[1]+alpha*p2[1], p1[2]] |
| 1460 elif alignments is not None: | |
| 1461 pass # TODO | |
| 1464 else: | 1462 else: |
| 1465 print('Object {} changes lane at {}'.format(self.getNum(), t)) | 1463 print('Object {} changes lane at {} and alignments are not provided'.format(self.getNum(), t)) |
| 1466 else: | 1464 else: |
| 1467 print('Object {} does not exist at {}'.format(self.getNum(), t)) | 1465 print('Object {} does not exist at {}'.format(self.getNum(), t)) |
| 1468 else: | 1466 else: |
| 1469 print('Object {} has no curvilinear positions'.format(self.getNum())) | 1467 print('Object {} has no curvilinear positions'.format(self.getNum())) |
| 1470 | 1468 |
