diff python/moving.py @ 451:cd342a774806

Point/CurvilinearTrajectory/Interaction utiles
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 13 Feb 2014 01:24:27 -0500
parents 31604ef1cad4
children dcc821b98efc
line wrap: on
line diff
--- a/python/moving.py	Tue Feb 11 02:55:02 2014 -0500
+++ b/python/moving.py	Thu Feb 13 01:24:27 2014 -0500
@@ -173,6 +173,9 @@
     def __sub__(self, other):
         return Point(self.x-other.x, self.y-other.y)
 
+    def __neg__(self):
+        return Point(-self.x, -self.y)
+
     def multiply(self, alpha):
         return Point(self.x*alpha, self.y*alpha)
 
@@ -612,6 +615,19 @@
         if i < self.__len__():
             self.lanes[i] = lane
 
+    def getIntersections(self, S1, lane = None):
+        '''Returns a list of the indices at which the trajectory 
+        goes past the curvilinear coordinate S1
+        (in provided lane if lane != None)
+        the list is empty if there is no crossing'''
+        indices = []
+        for i in xrange(self.length()-1):
+            q1=self.__getitem__(i)
+            q2=self.__getitem__(i+1)
+            if q1[0] <= S1 <= q2[0] and lane == None or (self.lanes[i] == lane and self.lanes[i+1] == lane):
+                indices.append(i+(S1-q1[0])/(q2[0]-q1[0]))
+        return indices
+
 ##################
 # Moving Objects
 ##################