Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/moving.py @ 1300:f3574e43c238
correcting bug on line crossings (and renaming method)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 11 Apr 2025 16:14:51 -0400 |
| parents | 9012fb72d79a |
| children | 4bc0651d91f9 |
comparison
equal
deleted
inserted
replaced
| 1299:c4bef099d0a2 | 1300:f3574e43c238 |
|---|---|
| 767 return inter, ratio | 767 return inter, ratio |
| 768 else: | 768 else: |
| 769 return None, None | 769 return None, None |
| 770 | 770 |
| 771 def segmentLineIntersection(p1, p2, p3, p4): | 771 def segmentLineIntersection(p1, p2, p3, p4): |
| 772 '''Indicates if the line going through p1 and p2 intersects inside p3, p4''' | 772 '''Indicates if the line going through p3 and p4 intersects inside p1, p2''' |
| 773 inter, ratio = intersection(p1, p2, p3, p4) | 773 inter, ratio = intersection(p1, p2, p3, p4) |
| 774 if inter is not None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y): | 774 if inter is not None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y): |
| 775 return inter, ratio | 775 return inter, ratio |
| 776 else: | 776 else: |
| 777 return None, None | 777 return None, None |
| 1111 rightToLeftOrientations = [] | 1111 rightToLeftOrientations = [] |
| 1112 | 1112 |
| 1113 for i in range(self.length()-1): | 1113 for i in range(self.length()-1): |
| 1114 q1=self.__getitem__(i) | 1114 q1=self.__getitem__(i) |
| 1115 q2=self.__getitem__(i+1) | 1115 q2=self.__getitem__(i+1) |
| 1116 p, ratio = segmentIntersection(p1, p2, q1, q2) | 1116 p, ratio = segmentIntersection(q1, q2, p1, p2) |
| 1117 if p is not None: | 1117 if p is not None: |
| 1118 # if q1.x != q2.x: | |
| 1119 # ratio = (p.x-q1.x)/(q2.x-q1.x) | |
| 1120 # elif q1.y != q2.y: | |
| 1121 # ratio = (p.y-q1.y)/(q2.y-q1.y) | |
| 1122 # else: | |
| 1123 # ratio = 0 | |
| 1124 indices.append(i+ratio) | 1118 indices.append(i+ratio) |
| 1125 intersections.append(p) | 1119 intersections.append(p) |
| 1126 if computeOrientations: | 1120 if computeOrientations: |
| 1127 rightToLeftOrientations.append(segmentOrientationCrossing(p1, p2, q1, q2)) | 1121 rightToLeftOrientations.append(segmentOrientationCrossing(p1, p2, q1, q2)) |
| 1128 return indices, intersections, rightToLeftOrientations | 1122 return indices, intersections, rightToLeftOrientations |
| 1137 for i in range(self.length()-1): | 1131 for i in range(self.length()-1): |
| 1138 q1=self.__getitem__(i) | 1132 q1=self.__getitem__(i) |
| 1139 q2=self.__getitem__(i+1) | 1133 q2=self.__getitem__(i+1) |
| 1140 p, ratio = segmentLineIntersection(q1, q2, p1, p2) | 1134 p, ratio = segmentLineIntersection(q1, q2, p1, p2) |
| 1141 if p is not None: | 1135 if p is not None: |
| 1142 # if q1.x != q2.x: | |
| 1143 # ratio = (p.x-q1.x)/(q2.x-q1.x) | |
| 1144 # elif q1.y != q2.y: | |
| 1145 # ratio = (p.y-q1.y)/(q2.y-q1.y) | |
| 1146 # else: | |
| 1147 # ratio = 0 | |
| 1148 indices.append(i+ratio) | 1136 indices.append(i+ratio) |
| 1149 intersections.append(p) | 1137 intersections.append(p) |
| 1150 return indices, intersections | 1138 return indices, intersections |
| 1151 | 1139 |
| 1152 def subTrajectoryInInterval(self, inter): | 1140 def subTrajectoryInInterval(self, inter): |
| 2004 | 1992 |
| 2005 def setRoutes(self, startRouteID, endRouteID): | 1993 def setRoutes(self, startRouteID, endRouteID): |
| 2006 self.startRouteID = startRouteID | 1994 self.startRouteID = startRouteID |
| 2007 self.endRouteID = endRouteID | 1995 self.endRouteID = endRouteID |
| 2008 | 1996 |
| 2009 def getInstantsCrossingLine(self, p1, p2, computeOrientations = False): | 1997 def getInstantsCrossingSegment(self, p1, p2, computeOrientations = False): |
| 2010 '''Returns the instant(s) | 1998 '''Returns the instant(s) |
| 2011 at which the object passes from one side of the segment to the other | 1999 at which the object passes from one side of the segment to the other |
| 2012 empty list if there is no crossing''' | 2000 empty list if there is no crossing''' |
| 2013 indices, intersections, rightToLeftOrientations = self.positions.getIntersections(p1, p2, computeOrientations) | 2001 indices, intersections, rightToLeftOrientations = self.positions.getIntersections(p1, p2, computeOrientations) |
| 2014 return [t+self.getFirstInstant() for t in indices], intersections, rightToLeftOrientations | 2002 return [t+self.getFirstInstant() for t in indices], intersections, rightToLeftOrientations |
