Mercurial Hosting > traffic-intelligence
comparison python/prediction.py @ 636:3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 24 Mar 2015 18:11:28 +0100 |
parents | 69a98f84f3eb |
children | 335f6641bf7a |
comparison
equal
deleted
inserted
replaced
635:6ae68383071e | 636:3058e00887bc |
---|---|
274 t2 = 0 | 274 t2 = 0 |
275 while not cz and t2 < timeHorizon: | 275 while not cz and t2 < timeHorizon: |
276 #if (et1.predictPosition(t1)-et2.predictPosition(t2)).norm2() < collisionDistanceThreshold: | 276 #if (et1.predictPosition(t1)-et2.predictPosition(t2)).norm2() < collisionDistanceThreshold: |
277 # cz = (et1.predictPosition(t1)+et2.predictPosition(t2)).multiply(0.5) | 277 # cz = (et1.predictPosition(t1)+et2.predictPosition(t2)).multiply(0.5) |
278 cz = moving.segmentIntersection(et1.predictPosition(t1), et1.predictPosition(t1+1), et2.predictPosition(t2), et2.predictPosition(t2+1)) | 278 cz = moving.segmentIntersection(et1.predictPosition(t1), et1.predictPosition(t1+1), et2.predictPosition(t2), et2.predictPosition(t2+1)) |
279 if cz != None: | 279 if cz is not None: |
280 deltaV= (et1.predictPosition(t1)- et1.predictPosition(t1+1) - et2.predictPosition(t2)+ et2.predictPosition(t2+1)).norm2() | 280 deltaV= (et1.predictPosition(t1)- et1.predictPosition(t1+1) - et2.predictPosition(t2)+ et2.predictPosition(t2+1)).norm2() |
281 crossingZones.append(SafetyPoint(cz, et1.probability*et2.probability, abs(t1-t2)-(float(collisionDistanceThreshold)/deltaV))) | 281 crossingZones.append(SafetyPoint(cz, et1.probability*et2.probability, abs(t1-t2)-(float(collisionDistanceThreshold)/deltaV))) |
282 t2 += 1 | 282 t2 += 1 |
283 t1 += 1 | 283 t1 += 1 |
284 | 284 |
498 else: | 498 else: |
499 v1 = obj1.getVelocityAtInstant(currentInstant) | 499 v1 = obj1.getVelocityAtInstant(currentInstant) |
500 v2 = obj2.getVelocityAtInstant(currentInstant) | 500 v2 = obj2.getVelocityAtInstant(currentInstant) |
501 intersection = moving.intersection(p1, p1+v1, p2, p2+v2) | 501 intersection = moving.intersection(p1, p1+v1, p2, p2+v2) |
502 | 502 |
503 if intersection != None: | 503 if intersection is not None: |
504 dp1 = intersection-p1 | 504 dp1 = intersection-p1 |
505 dp2 = intersection-p2 | 505 dp2 = intersection-p2 |
506 dot1 = moving.Point.dot(dp1, v1) | 506 dot1 = moving.Point.dot(dp1, v1) |
507 dot2 = moving.Point.dot(dp2, v2) | 507 dot2 = moving.Point.dot(dp2, v2) |
508 #print dot1, dot2 | 508 #print dot1, dot2 |
530 # firstUser = obj1 | 530 # firstUser = obj1 |
531 # secondUser = obj2 | 531 # secondUser = obj2 |
532 # p2 = secondUser.getPositionAtInstant(currentInstant) | 532 # p2 = secondUser.getPositionAtInstant(currentInstant) |
533 # v2 = secondUser.getVelocityAtInstant(currentInstant) | 533 # v2 = secondUser.getVelocityAtInstant(currentInstant) |
534 # indices, intersections = firstUser.getPositions().getLineIntersections(p2, p2+v2) | 534 # indices, intersections = firstUser.getPositions().getLineIntersections(p2, p2+v2) |
535 # if indices != None: | 535 # if indices is not None: |
536 # pass | 536 # pass |
537 # else: # one has to predict !!! | 537 # else: # one has to predict !!! |
538 | 538 |
539 if debug and intersection!= None: | 539 if debug and intersection is not None: |
540 from matplotlib.pyplot import plot, figure, axis, title | 540 from matplotlib.pyplot import plot, figure, axis, title |
541 figure() | 541 figure() |
542 plot([p1.x, intersection.x], [p1.y, intersection.y], 'r') | 542 plot([p1.x, intersection.x], [p1.y, intersection.y], 'r') |
543 plot([p2.x, intersection.x], [p2.y, intersection.y], 'b') | 543 plot([p2.x, intersection.x], [p2.y, intersection.y], 'b') |
544 intersection.plot() | 544 intersection.plot() |
565 p2 = obj2.getPositionAtInstant(currentInstant) | 565 p2 = obj2.getPositionAtInstant(currentInstant) |
566 v1 = obj1.getVelocityAtInstant(currentInstant) | 566 v1 = obj1.getVelocityAtInstant(currentInstant) |
567 v2 = obj2.getVelocityAtInstant(currentInstant) | 567 v2 = obj2.getVelocityAtInstant(currentInstant) |
568 intersection = moving.intersection(p1, p1+v1, p2, p2+v2) | 568 intersection = moving.intersection(p1, p1+v1, p2, p2+v2) |
569 | 569 |
570 if intersection != None: | 570 if intersection is not None: |
571 ttc = moving.Point.timeToCollision(p1, p2, v1, v2, collisionDistanceThreshold) | 571 ttc = moving.Point.timeToCollision(p1, p2, v1, v2, collisionDistanceThreshold) |
572 if ttc: | 572 if ttc: |
573 return [SafetyPoint(intersection, 1., ttc)], [] # (p1+v1.multiply(ttc)+p2+v2.multiply(ttc)).multiply(0.5) | 573 return [SafetyPoint(intersection, 1., ttc)], [] # (p1+v1.multiply(ttc)+p2+v2.multiply(ttc)).multiply(0.5) |
574 else: | 574 else: |
575 return [],[] | 575 return [],[] |