Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 381:387cc0142211
script to replay event annotations
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 19 Jul 2013 11:58:35 -0400 |
| parents | f1a1923ddff9 |
| children | 0ce2210790b1 |
comparison
equal
deleted
inserted
replaced
| 380:adfd4f70ee1d | 381:387cc0142211 |
|---|---|
| 518 displacement = 0 | 518 displacement = 0 |
| 519 for i in xrange(self.length()-1): | 519 for i in xrange(self.length()-1): |
| 520 displacement += Point.distanceNorm2(self.__getitem__(i),self.__getitem__(i+1)) | 520 displacement += Point.distanceNorm2(self.__getitem__(i),self.__getitem__(i+1)) |
| 521 return displacement | 521 return displacement |
| 522 | 522 |
| 523 def similarOrientation(self, refDirection, cosineThreshold): | 523 def similarOrientation(self, refDirection, cosineThreshold, minProportion = 0.5): |
| 524 '''Indicates whether the majority of the trajectory elements (vectors for velocity) | 524 '''Indicates whether the minProportion (<=1.) (eg half) of the trajectory elements (vectors for velocity) |
| 525 have a cosine with refDirection is smaller than cosineThreshold''' | 525 have a cosine with refDirection is smaller than cosineThreshold''' |
| 526 count = 0 | 526 count = 0 |
| 527 halfLength = float(self.length())/2 | 527 lengthTreshold = float(self.length())*minProportion |
| 528 for p in self: | 528 for p in self: |
| 529 if p.similarOrientation(refDirection, cosineThreshold): | 529 if p.similarOrientation(refDirection, cosineThreshold): |
| 530 count += 1 | 530 count += 1 |
| 531 if count > halfLength: | 531 if count > lengthThreshold: |
| 532 return True | 532 return True |
| 533 return False | 533 return False |
| 534 | 534 |
| 535 | 535 |
| 536 def wiggliness(self): | 536 def wiggliness(self): |
