Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 674:01b89182891a
corrected bug for intersection of lines (thanks to Paul for finding)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 26 May 2015 18:16:51 +0200 |
parents | 5473b7460375 |
children | ab3fdff42624 |
comparison
equal
deleted
inserted
replaced
673:5505f9dbb28e | 674:01b89182891a |
---|---|
534 ''' Intersection point (x,y) of lines formed by the vectors p1-p2 and p3-p4 | 534 ''' Intersection point (x,y) of lines formed by the vectors p1-p2 and p3-p4 |
535 http://paulbourke.net/geometry/pointlineplane/''' | 535 http://paulbourke.net/geometry/pointlineplane/''' |
536 dp12 = p2-p1 | 536 dp12 = p2-p1 |
537 dp34 = p4-p3 | 537 dp34 = p4-p3 |
538 #det = (p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y) | 538 #det = (p4.y-p3.y)*(p2.x-p1.x)-(p4.x-p3.x)*(p2.y-p1.y) |
539 det = dp34.y*dp12.x-dp34.x*dp12.y | 539 det = float(dp34.y*dp12.x-dp34.x*dp12.y) |
540 if det == 0: | 540 if det == 0.: |
541 return None | 541 return None |
542 else: | 542 else: |
543 ua = (dp34.x*(p1.y-p3.y)-dp34.y*(p1.x-p3.x))/det | 543 ua = (dp34.x*(p1.y-p3.y)-dp34.y*(p1.x-p3.x))/det |
544 return p1+dp12.multiply(ua) | 544 return p1+dp12.multiply(ua) |
545 | 545 |