Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 630:69a98f84f3eb
corrected major issue with pPET, only for CVDirect prediction for now
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 17 Feb 2015 02:21:31 +0100 |
parents | 82e9f78a4714 |
children | 2d1d33ae1c69 |
line wrap: on
line diff
--- a/python/moving.py Tue Feb 17 00:56:47 2015 +0100 +++ b/python/moving.py Tue Feb 17 02:21:31 2015 +0100 @@ -579,6 +579,15 @@ else: return None +def segmentLineIntersection(p1, p2, p3, p4): + '''Indicates if the line going through p1 and p2 intersects inside p3, p4''' + inter = intersection(p1, p2, p3, p4) + if inter != None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y)): + return inter + else: + return None + + class Trajectory(object): '''Class for trajectories: temporal sequence of positions @@ -808,7 +817,7 @@ q1=self.__getitem__(i) q2=self.__getitem__(i+1) p = utils.segmentIntersection(q1, q2, p1, p2) - if p: + if p != None: if q1.x != q2.x: ratio = (p.x-q1.x)/(q2.x-q1.x) elif q1.y != q2.y: @@ -818,6 +827,28 @@ indices.append(i+ratio) return indices + def getLineIntersections(self, p1, p2): + '''Returns a list of the indices at which the trajectory + intersects with the segment of extremities p1 and p2 + the list is empty if there is no crossing''' + indices = [] + intersections = [] + + for i in xrange(self.length()-1): + q1=self.__getitem__(i) + q2=self.__getitem__(i+1) + p = utils.segmentLineIntersection(p1, p2, q1, q2) + if p != None: + if q1.x != q2.x: + ratio = (p.x-q1.x)/(q2.x-q1.x) + elif q1.y != q2.y: + ratio = (p.y-q1.y)/(q2.y-q1.y) + else: + ratio = 0 + indices.append(i+ratio) + intersections.append(p) + return indices, intersections + def getTrajectoryInInterval(self, inter): 'Returns all position between index inter.first and index.last (included)' if inter.first >=0 and inter.last<= self.length():