diff 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
line wrap: on
line diff
--- a/python/moving.py	Thu Jul 20 12:12:28 2017 -0400
+++ b/python/moving.py	Thu Jul 20 14:29:46 2017 -0400
@@ -219,8 +219,17 @@
         if clockwise:
             return Point(self.y, -self.x)
         else:
-            return Point(-self.y, self.x)            
+            return Point(-self.y, self.x)
 
+    def projectLocal(self, v, clockwise = True):
+        'Projects point projected on v, v.orthogonal()'
+        e1 = v/v.norm2()
+        e2 = e1.orthogonal(clockwise)
+        return Point(Point.dot(self, e1), Point.doc(self, e2))
+
+    def rotate(self, theta):
+        return Point(self.x*cos(theta)-self.y*sin(theta), self.x*sin(theta)+self.y*cos(theta))
+        
     def __mul__(self, alpha):
         'Warning, returns a new Point'
         return Point(self.x*alpha, self.y*alpha)
@@ -236,6 +245,9 @@
     def plotSegment(p1, p2, options = 'o', **kwargs):
         plot([p1.x, p2.x], [p1.y, p2.y], options, **kwargs)
 
+    def angle(self):
+        return atan2(self.y, self.x)
+        
     def norm2Squared(self):
         '''2-norm distance (Euclidean distance)'''
         return self.x**2+self.y**2
@@ -529,7 +541,7 @@
     def fromPoint(p):
         norm = p.norm2()
         if norm > 0:
-            angle = atan2(p.y, p.x)
+            angle = p.angle()
         else:
             angle = 0.
         return NormAngle(norm, angle)