Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 464:dcc821b98efc
integrated and reorganized Sohail s work on exact ttc computation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 23 Feb 2014 23:18:08 -0500 |
parents | cd342a774806 |
children | 6464e4f0cc26 |
comparison
equal
deleted
inserted
replaced
463:cb9683f9efe7 | 464:dcc821b98efc |
---|---|
263 scatter([p.x for p in points],[p.y for p in points], **kwargs) | 263 scatter([p.x for p in points],[p.y for p in points], **kwargs) |
264 | 264 |
265 def similarOrientation(self, refDirection, cosineThreshold): | 265 def similarOrientation(self, refDirection, cosineThreshold): |
266 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold' | 266 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold' |
267 return Point.cosine(self, refDirection) >= cosineThreshold | 267 return Point.cosine(self, refDirection) >= cosineThreshold |
268 | |
269 @staticmethod | |
270 def timeToCollision(p1, p2, v1, v2): | |
271 from math import sqrt | |
272 a = pow(v1.x-v2.x,2) + pow(v1.y-v2.y,2) | |
273 b = 2 * ((p1.x-p2.x) * (v1.x-v2.x) + (p1.y-p2.y) * (v1.y-v2.y)) | |
274 c = pow(p1.x-p2.x,2) + pow(p1.y-p2.y,2) - pow(l,2) | |
275 | |
276 if pow(b,2) >= 4*a*c: | |
277 ttc1 = (-b + sqrt(pow(b,2) - 4*a*c)) / (2*a) | |
278 ttc2 = (-b - sqrt(pow(b,2) - 4*a*c)) / (2*a) | |
279 if ttc1 >= 0 and ttc2 >= 0: | |
280 ttc = min(ttc1,ttc2) | |
281 else: | |
282 if ttc1 < 0: | |
283 ttc = ttc2 | |
284 if ttc2 < 0: | |
285 ttc = ttc1 | |
286 if ttc1 < 0 and ttc2 < 0: | |
287 ttc = None | |
288 else: | |
289 ttc = None | |
290 return ttc | |
291 | |
268 | 292 |
269 if shapelyAvailable: | 293 if shapelyAvailable: |
270 def pointsInPolygon(points, polygon): | 294 def pointsInPolygon(points, polygon): |
271 '''Optimized tests of a series of points within (Shapely) polygon ''' | 295 '''Optimized tests of a series of points within (Shapely) polygon ''' |
272 prepared_polygon = prep(polygon) | 296 prepared_polygon = prep(polygon) |