comparison 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
comparison
equal deleted inserted replaced
450:c0786fe4ad94 451:cd342a774806
170 def __add__(self, other): 170 def __add__(self, other):
171 return Point(self.x+other.x, self.y+other.y) 171 return Point(self.x+other.x, self.y+other.y)
172 172
173 def __sub__(self, other): 173 def __sub__(self, other):
174 return Point(self.x-other.x, self.y-other.y) 174 return Point(self.x-other.x, self.y-other.y)
175
176 def __neg__(self):
177 return Point(-self.x, -self.y)
175 178
176 def multiply(self, alpha): 179 def multiply(self, alpha):
177 return Point(self.x*alpha, self.y*alpha) 180 return Point(self.x*alpha, self.y*alpha)
178 181
179 def draw(self, options = 'o', **kwargs): 182 def draw(self, options = 'o', **kwargs):
609 612
610 def setPosition(self, i, s, y, lane): 613 def setPosition(self, i, s, y, lane):
611 self.setPositionXY(i, s, y) 614 self.setPositionXY(i, s, y)
612 if i < self.__len__(): 615 if i < self.__len__():
613 self.lanes[i] = lane 616 self.lanes[i] = lane
617
618 def getIntersections(self, S1, lane = None):
619 '''Returns a list of the indices at which the trajectory
620 goes past the curvilinear coordinate S1
621 (in provided lane if lane != None)
622 the list is empty if there is no crossing'''
623 indices = []
624 for i in xrange(self.length()-1):
625 q1=self.__getitem__(i)
626 q2=self.__getitem__(i+1)
627 if q1[0] <= S1 <= q2[0] and lane == None or (self.lanes[i] == lane and self.lanes[i+1] == lane):
628 indices.append(i+(S1-q1[0])/(q2[0]-q1[0]))
629 return indices
614 630
615 ################## 631 ##################
616 # Moving Objects 632 # Moving Objects
617 ################## 633 ##################
618 634