changeset 451:cd342a774806

Point/CurvilinearTrajectory/Interaction utiles
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 13 Feb 2014 01:24:27 -0500
parents c0786fe4ad94
children c59a47ce0209
files python/events.py python/moving.py python/tests/moving.txt
diffstat 3 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/python/events.py	Tue Feb 11 02:55:02 2014 -0500
+++ b/python/events.py	Thu Feb 13 01:24:27 2014 -0500
@@ -67,6 +67,7 @@
         self.roadUser2 = roadUser2
         self.categoryNum = categoryNum
         self.indicators = {}
+        self.interactionInterval = None
 
     def getRoadUserNumbers(self):
         return self.roadUserNumbers
@@ -141,8 +142,20 @@
         self.videoFilename= videoFilename	
 
     def addInteractionType(self,interactionType):
-	''' interaction types: conflict or collision if they are known'''
-        self.interactionType= interactionType			
+	    ''' interaction types: conflict or collision if they are known'''
+        self.interactionType= interactionType
+
+    def computeInteractionInterval(self):
+        ''' Computes the times during which the road users are getting closer,
+        ie the collision course angle is positive
+        (Other thresholds/indicators could be tried)'''
+        collisionCourseDotProducts = self.getIndicator(Interaction.indicatorNames[0])
+        inter = collisionCourseDotProducts.getTimeInterval()
+        interactionInstants = [t for t in inter if collisionCourseDotProducts[t] >= 0]
+        if len(interactionInstants) >= 2:
+            self.interactionInterval = moving.TimeInterval(interactionInstants[0], interactionInstants[-1])
+        else:
+            self.interactionInterval = moving.TimeInterval()
 
 def createInteractions(objects):
     '''Create all interactions of two co-existing road users
--- 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
 ##################
--- a/python/tests/moving.txt	Tue Feb 11 02:55:02 2014 -0500
+++ b/python/tests/moving.txt	Thu Feb 13 01:24:27 2014 -0500
@@ -42,6 +42,8 @@
 
 >>> Point(3,4)-Point(1,7)
 (2.000000,-3.000000)
+>>> -Point(1,2)
+(-1.000000,-2.000000)
 
 >>> Point(3,2).norm2Squared()
 13