Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 945:05d4302bf67e
working motion pattern prediction with rotation and features
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 20 Jul 2017 14:29:46 -0400 |
parents | b1e8453c207c |
children | d6c1c05d11f5 |
comparison
equal
deleted
inserted
replaced
944:84ebe1b031f1 | 945:05d4302bf67e |
---|---|
217 def orthogonal(self, clockwise = True): | 217 def orthogonal(self, clockwise = True): |
218 'Returns the orthogonal vector' | 218 'Returns the orthogonal vector' |
219 if clockwise: | 219 if clockwise: |
220 return Point(self.y, -self.x) | 220 return Point(self.y, -self.x) |
221 else: | 221 else: |
222 return Point(-self.y, self.x) | 222 return Point(-self.y, self.x) |
223 | 223 |
224 def projectLocal(self, v, clockwise = True): | |
225 'Projects point projected on v, v.orthogonal()' | |
226 e1 = v/v.norm2() | |
227 e2 = e1.orthogonal(clockwise) | |
228 return Point(Point.dot(self, e1), Point.doc(self, e2)) | |
229 | |
230 def rotate(self, theta): | |
231 return Point(self.x*cos(theta)-self.y*sin(theta), self.x*sin(theta)+self.y*cos(theta)) | |
232 | |
224 def __mul__(self, alpha): | 233 def __mul__(self, alpha): |
225 'Warning, returns a new Point' | 234 'Warning, returns a new Point' |
226 return Point(self.x*alpha, self.y*alpha) | 235 return Point(self.x*alpha, self.y*alpha) |
227 | 236 |
228 def divide(self, alpha): | 237 def divide(self, alpha): |
234 | 243 |
235 @staticmethod | 244 @staticmethod |
236 def plotSegment(p1, p2, options = 'o', **kwargs): | 245 def plotSegment(p1, p2, options = 'o', **kwargs): |
237 plot([p1.x, p2.x], [p1.y, p2.y], options, **kwargs) | 246 plot([p1.x, p2.x], [p1.y, p2.y], options, **kwargs) |
238 | 247 |
248 def angle(self): | |
249 return atan2(self.y, self.x) | |
250 | |
239 def norm2Squared(self): | 251 def norm2Squared(self): |
240 '''2-norm distance (Euclidean distance)''' | 252 '''2-norm distance (Euclidean distance)''' |
241 return self.x**2+self.y**2 | 253 return self.x**2+self.y**2 |
242 | 254 |
243 def norm2(self): | 255 def norm2(self): |
527 | 539 |
528 @staticmethod | 540 @staticmethod |
529 def fromPoint(p): | 541 def fromPoint(p): |
530 norm = p.norm2() | 542 norm = p.norm2() |
531 if norm > 0: | 543 if norm > 0: |
532 angle = atan2(p.y, p.x) | 544 angle = p.angle() |
533 else: | 545 else: |
534 angle = 0. | 546 angle = 0. |
535 return NormAngle(norm, angle) | 547 return NormAngle(norm, angle) |
536 | 548 |
537 def __add__(self, other): | 549 def __add__(self, other): |