Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 284:f2cf16ad798f
added LCSS for trajectories
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 21 Dec 2012 18:33:36 -0500 |
| parents | 8d44fb1756bc |
| children | e0d41c7f53d4 |
comparison
equal
deleted
inserted
replaced
| 283:dbe7e53334d7 | 284:f2cf16ad798f |
|---|---|
| 168 return self.x*self.x+self.y*self.y | 168 return self.x*self.x+self.y*self.y |
| 169 | 169 |
| 170 def norm2(self): | 170 def norm2(self): |
| 171 '2-norm distance (Euclidean distance)' | 171 '2-norm distance (Euclidean distance)' |
| 172 return sqrt(self.norm2Squared()) | 172 return sqrt(self.norm2Squared()) |
| 173 | |
| 174 def norm1(self): | |
| 175 return abs(self.x)+abs(self.y) | |
| 176 | |
| 177 def normMax(self): | |
| 178 return max(abs(self.x),abs(self.y)) | |
| 173 | 179 |
| 174 def aslist(self): | 180 def aslist(self): |
| 175 return [self.x, self.y] | 181 return [self.x, self.y] |
| 176 | 182 |
| 177 def astuple(self): | 183 def astuple(self): |
| 365 self.iterInstantNum += 1 | 371 self.iterInstantNum += 1 |
| 366 return self[self.iterInstantNum-1] | 372 return self[self.iterInstantNum-1] |
| 367 | 373 |
| 368 def length(self): | 374 def length(self): |
| 369 return len(self.positions[0]) | 375 return len(self.positions[0]) |
| 376 | |
| 377 def __len__(self): | |
| 378 return self.length() | |
| 370 | 379 |
| 371 def addPositionXY(self, x, y): | 380 def addPositionXY(self, x, y): |
| 372 self.positions[0].append(x) | 381 self.positions[0].append(x) |
| 373 self.positions[1].append(y) | 382 self.positions[1].append(y) |
| 374 | 383 |
| 494 traj.addPositionXY(self.positions[0][i], self.positions[1][i]) | 503 traj.addPositionXY(self.positions[0][i], self.positions[1][i]) |
| 495 return traj | 504 return traj |
| 496 | 505 |
| 497 # version 2: use shapely polygon contains | 506 # version 2: use shapely polygon contains |
| 498 | 507 |
| 508 @staticmethod | |
| 509 def norm2LCSS(t1, t2, threshold): | |
| 510 return utils.LCSS(t1, t2, threshold, Point.distanceNorm2) | |
| 511 | |
| 512 @staticmethod | |
| 513 def normMaxLCSS(t1, t2, threshold): | |
| 514 return utils.LCSS(t1, t2, threshold, lambda p1, p2: (p1-p2).normMax()) | |
| 515 | |
| 499 ################## | 516 ################## |
| 500 # Moving Objects | 517 # Moving Objects |
| 501 ################## | 518 ################## |
| 502 | 519 |
| 503 userTypeNames = ['car', | 520 userTypeNames = ['car', |
