Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 881:8ba82b371eea
work on storing PET
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 14 Mar 2017 17:48:40 -0400 |
parents | 000555430b28 |
children | e2452abba0e7 |
comparison
equal
deleted
inserted
replaced
880:000555430b28 | 881:8ba82b371eea |
---|---|
338 if delta >= 0: | 338 if delta >= 0: |
339 deltaRoot = sqrt(delta) | 339 deltaRoot = sqrt(delta) |
340 ttc1 = (-b + deltaRoot)/(2*a) | 340 ttc1 = (-b + deltaRoot)/(2*a) |
341 ttc2 = (-b - deltaRoot)/(2*a) | 341 ttc2 = (-b - deltaRoot)/(2*a) |
342 if ttc1 >= 0 and ttc2 >= 0: | 342 if ttc1 >= 0 and ttc2 >= 0: |
343 ttc = min(ttc1,ttc2) | 343 return min(ttc1,ttc2) |
344 elif ttc1 >= 0: | 344 elif ttc1 >= 0: |
345 ttc = ttc1 | 345 return ttc1 |
346 elif ttc2 >= 0: | 346 elif ttc2 >= 0: |
347 ttc = ttc2 | 347 return ttc2 |
348 else: # ttc1 < 0 and ttc2 < 0: | 348 else: # ttc1 < 0 and ttc2 < 0: |
349 ttc = None | 349 return None |
350 else: | 350 else: |
351 ttc = None | 351 return None |
352 return ttc | |
353 | 352 |
354 @staticmethod | 353 @staticmethod |
355 def midPoint(p1, p2): | 354 def midPoint(p1, p2): |
356 'Returns the middle of the segment [p1, p2]' | 355 'Returns the middle of the segment [p1, p2]' |
357 return Point(0.5*p1.x+0.5*p2.x, 0.5*p1.y+0.5*p2.y) | 356 return Point(0.5*p1.x+0.5*p2.x, 0.5*p1.y+0.5*p2.y) |
1426 @staticmethod | 1425 @staticmethod |
1427 def computePET(obj1, obj2, collisionDistanceThreshold): | 1426 def computePET(obj1, obj2, collisionDistanceThreshold): |
1428 '''Post-encroachment time based on distance threshold | 1427 '''Post-encroachment time based on distance threshold |
1429 | 1428 |
1430 Returns the smallest time difference when the object positions are within collisionDistanceThreshold''' | 1429 Returns the smallest time difference when the object positions are within collisionDistanceThreshold''' |
1431 #for i in xrange(int(obj1.length())-1): | |
1432 # for j in xrange(int(obj2.length())-1): | |
1433 # inter = segmentIntersection(obj1.getPositionAt(i), obj1.getPositionAt(i+1), obj2.getPositionAt(i), obj2.getPositionAt(i+1)) | |
1434 positions1 = [p.astuple() for p in obj1.getPositions()] | 1430 positions1 = [p.astuple() for p in obj1.getPositions()] |
1435 positions2 = [p.astuple() for p in obj2.getPositions()] | 1431 positions2 = [p.astuple() for p in obj2.getPositions()] |
1436 pets = zeros((int(obj1.length()), int(obj2.length()))) | 1432 pets = zeros((int(obj1.length()), int(obj2.length()))) |
1437 for i,t1 in enumerate(obj1.getTimeInterval()): | 1433 for i,t1 in enumerate(obj1.getTimeInterval()): |
1438 for j,t2 in enumerate(obj2.getTimeInterval()): | 1434 for j,t2 in enumerate(obj2.getTimeInterval()): |
1439 pets[i,j] = abs(t1-t2) | 1435 pets[i,j] = abs(t1-t2) |
1440 distances = cdist(positions1, positions2, metric = 'euclidean') | 1436 distances = cdist(positions1, positions2, metric = 'euclidean') |
1441 if distances.min() <= collisionDistanceThreshold: | 1437 if distances.min() <= collisionDistanceThreshold: |
1438 #idx = distances.argmin() | |
1442 return pets[distances <= collisionDistanceThreshold].min() | 1439 return pets[distances <= collisionDistanceThreshold].min() |
1443 else: | 1440 else: |
1444 return None | 1441 return None |
1445 | 1442 |
1446 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): | 1443 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): |