# HG changeset patch # User Nicolas Saunier # Date 1411417313 14400 # Node ID 6ebfb43e938e7ead2fd60bc7fe812116f8fb6b42 # Parent 7e1ae4d97f1a0d94a4f7099923d20007fc03fa8f added midpoint function (from laurent gauthier) diff -r 7e1ae4d97f1a -r 6ebfb43e938e python/moving.py --- a/python/moving.py Thu Sep 18 15:36:57 2014 -0400 +++ b/python/moving.py Mon Sep 22 16:21:53 2014 -0400 @@ -316,6 +316,10 @@ ttc = None return ttc + @staticmethod + def midPoint(p1, p2): + 'Returns the middle of the segment [p1, p2]' + return Point(0.5*p1.x+0.5*p2.x, 0.5*p1.y+0.5*p2.y) if shapelyAvailable: def pointsInPolygon(points, polygon): diff -r 7e1ae4d97f1a -r 6ebfb43e938e python/tests/moving.txt --- a/python/tests/moving.txt Thu Sep 18 15:36:57 2014 -0400 +++ b/python/tests/moving.txt Mon Sep 22 16:21:53 2014 -0400 @@ -138,6 +138,8 @@ True >>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None True +>>> Point.midPoint(p1, p2) +(0.500000,0.500000) >>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4) >>> t.differentiate() # doctest:+ELLIPSIS