Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 771:bd13937818a4 dev
minor bug fix
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 22 Jan 2016 17:43:09 -0500 |
parents | f8e0a8ea8402 |
children | 84420159c5f4 |
comparison
equal
deleted
inserted
replaced
770:0f6b0f63eb07 | 771:bd13937818a4 |
---|---|
214 'Warning, returns a new Point' | 214 'Warning, returns a new Point' |
215 return Point(self.x/alpha, self.y/alpha) | 215 return Point(self.x/alpha, self.y/alpha) |
216 | 216 |
217 def plot(self, options = 'o', **kwargs): | 217 def plot(self, options = 'o', **kwargs): |
218 plot([self.x], [self.y], options, **kwargs) | 218 plot([self.x], [self.y], options, **kwargs) |
219 | |
220 @staticmethod | |
221 def plotSegment(p1, p2, options = 'o', **kwargs): | |
222 plot([p1.x, p2.x], [p1.y, p2.y], options, **kwargs) | |
219 | 223 |
220 def norm2Squared(self): | 224 def norm2Squared(self): |
221 '''2-norm distance (Euclidean distance)''' | 225 '''2-norm distance (Euclidean distance)''' |
222 return self.x**2+self.y**2 | 226 return self.x**2+self.y**2 |
223 | 227 |
843 return None | 847 return None |
844 | 848 |
845 def getIntersections(self, p1, p2): | 849 def getIntersections(self, p1, p2): |
846 '''Returns a list of the indices at which the trajectory | 850 '''Returns a list of the indices at which the trajectory |
847 intersects with the segment of extremities p1 and p2 | 851 intersects with the segment of extremities p1 and p2 |
848 the list is empty if there is no crossing''' | 852 Returns an empty list if there is no crossing''' |
849 indices = [] | 853 indices = [] |
850 intersections = [] | 854 intersections = [] |
851 | 855 |
852 for i in xrange(self.length()-1): | 856 for i in xrange(self.length()-1): |
853 q1=self.__getitem__(i) | 857 q1=self.__getitem__(i) |
854 q2=self.__getitem__(i+1) | 858 q2=self.__getitem__(i+1) |
855 p = utils.segmentIntersection(q1, q2, p1, p2) | 859 p = segmentIntersection(q1, q2, p1, p2) |
856 if p is not None: | 860 if p is not None: |
857 if q1.x != q2.x: | 861 if q1.x != q2.x: |
858 ratio = (p.x-q1.x)/(q2.x-q1.x) | 862 ratio = (p.x-q1.x)/(q2.x-q1.x) |
859 elif q1.y != q2.y: | 863 elif q1.y != q2.y: |
860 ratio = (p.y-q1.y)/(q2.y-q1.y) | 864 ratio = (p.y-q1.y)/(q2.y-q1.y) |
861 else: | 865 else: |
862 ratio = 0 | 866 ratio = 0 |
863 indices.append(i+ratio) | 867 indices.append(i+ratio) |
864 intersections.append(p) | 868 intersections.append(p) |
865 return indices | 869 return indices, intersections |
866 | 870 |
867 def getLineIntersections(self, p1, p2): | 871 def getLineIntersections(self, p1, p2): |
868 '''Returns a list of the indices at which the trajectory | 872 '''Returns a list of the indices at which the trajectory |
869 intersects with the segment of extremities p1 and p2 | 873 intersects with the line going through p1 and p2 |
870 the list is empty if there is no crossing''' | 874 Returns an empty list if there is no crossing''' |
871 indices = [] | 875 indices = [] |
872 intersections = [] | 876 intersections = [] |
873 | 877 |
874 for i in xrange(self.length()-1): | 878 for i in xrange(self.length()-1): |
875 q1=self.__getitem__(i) | 879 q1=self.__getitem__(i) |
876 q2=self.__getitem__(i+1) | 880 q2=self.__getitem__(i+1) |
877 p = utils.segmentLineIntersection(p1, p2, q1, q2) | 881 p = segmentLineIntersection(p1, p2, q1, q2) |
878 if p is not None: | 882 if p is not None: |
879 if q1.x != q2.x: | 883 if q1.x != q2.x: |
880 ratio = (p.x-q1.x)/(q2.x-q1.x) | 884 ratio = (p.x-q1.x)/(q2.x-q1.x) |
881 elif q1.y != q2.y: | 885 elif q1.y != q2.y: |
882 ratio = (p.y-q1.y)/(q2.y-q1.y) | 886 ratio = (p.y-q1.y)/(q2.y-q1.y) |
987 | 991 |
988 def getIntersections(self, S1, lane = None): | 992 def getIntersections(self, S1, lane = None): |
989 '''Returns a list of the indices at which the trajectory | 993 '''Returns a list of the indices at which the trajectory |
990 goes past the curvilinear coordinate S1 | 994 goes past the curvilinear coordinate S1 |
991 (in provided lane if lane is not None) | 995 (in provided lane if lane is not None) |
992 the list is empty if there is no crossing''' | 996 Returns an empty list if there is no crossing''' |
993 indices = [] | 997 indices = [] |
994 for i in xrange(self.length()-1): | 998 for i in xrange(self.length()-1): |
995 q1=self.__getitem__(i) | 999 q1=self.__getitem__(i) |
996 q2=self.__getitem__(i+1) | 1000 q2=self.__getitem__(i+1) |
997 if q1[0] <= S1 < q2[0] and (lane is None or (self.lanes[i] == lane and self.lanes[i+1] == lane)): | 1001 if q1[0] <= S1 < q2[0] and (lane is None or (self.lanes[i] == lane and self.lanes[i+1] == lane)): |