diff python/moving.py @ 555:f13220f765e0

added static methods to create trajectories and moving objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 13 Jul 2014 23:34:00 -0400
parents ca6bded754ac
children 259ccb3dd962
line wrap: on
line diff
--- a/python/moving.py	Fri Jul 11 16:25:57 2014 -0400
+++ b/python/moving.py	Sun Jul 13 23:34:00 2014 -0400
@@ -420,6 +420,16 @@
             self.positions = [[],[]]
 
     @staticmethod
+    def generate(p, v, nPoints):
+        t = Trajectory()
+        p0 = Point(p.x, p.y)
+        t.addPosition(p0)
+        for i in xrange(nPoints-1):
+            p0 += v
+            t.addPosition(p0)
+        return t, Trajectory([[v.x]*nPoints, [v.y]*nPoints])
+
+    @staticmethod
     def load(line1, line2):
         return Trajectory([[float(n) for n in line1.split(' ')],
                            [float(n) for n in line2.split(' ')]])
@@ -724,6 +734,11 @@
         self.features = []
         # compute bounding polygon from trajectory
         
+    @staticmethod
+    def generate(p, v, timeInterval):
+        positions, velocities = Trajectory.generate(p, v, int(timeInterval.length())) 
+        return MovingObject(timeInterval = timeInterval, positions = positions, velocities = velocities)
+
     def getObjectInTimeInterval(self, inter):
         '''Returns a new object extracted from self,
         restricted to time interval inter'''