view python/tests/moving.txt @ 542:a3add9f751ef

added differentiate function for curvilinear trajectories and modified the addPosition functions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 07 Jul 2014 16:54:10 -0400
parents f012a8ad7a0e
children 0057c04f94d5
line wrap: on
line source

>>> from moving import *
>>> import numpy as np

>>> Interval().empty()
True
>>> Interval(0,1).empty()
False
>>> Interval(0,1)
[0, 1]
>>> Interval(0,1).length()
1.0
>>> Interval(23.2,24.9).length()
1.6999999999999993
>>> Interval(10,8).length()
0.0

>>> TimeInterval(0,1).length()
2.0
>>> TimeInterval(10,8).length()
0.0

>>> [i for i in TimeInterval(9,13)]
[9, 10, 11, 12, 13]

>>> TimeInterval(2,5).equal(TimeInterval(2,5))
True
>>> TimeInterval(2,5).equal(TimeInterval(2,4))
False
>>> TimeInterval(2,5).equal(TimeInterval(5,2))
False

>>> TimeInterval(3,6).distance(TimeInterval(4,6))
0
>>> TimeInterval(3,6).distance(TimeInterval(6,10))
0
>>> TimeInterval(3,6).distance(TimeInterval(8,10))
2
>>> TimeInterval(20,30).distance(TimeInterval(3,15))
5
>>> unionIntervals([TimeInterval(3,6), TimeInterval(8,10),TimeInterval(11,15)])
[3, 15]

>>> Point(3,4)-Point(1,7)
(2.000000,-3.000000)
>>> -Point(1,2)
(-1.000000,-2.000000)

>>> Point(3,2).norm2Squared()
13

>>> Point.distanceNorm2(Point(3,4),Point(1,7))
3.605551275463989

>>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[1,0],[1,1],[0,1]]))
False
>>> Point(3,2).inPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
True

>>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS
((1.0...,1.0...), (10.0...,10.0...))

>>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2))
>>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1))
>>> segmentIntersection(Point(0,0),Point(2,0), Point(1,-1),Point(1,1))
(1.000000,0.000000)
>>> segmentIntersection(Point(0,1),Point(2,0),Point(1,1),Point(1,2))

>>> Trajectory().length()
0
>>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
>>> t1.length() == 3.
True
>>> t1[1]
(1.500000,3.500000)
>>> t1.getTrajectoryInPolygonNoShapely(np.array([[0,0],[4,0],[4,3],[0,3]]))
(0.500000,0.500000)
>>> t1.getTrajectoryInPolygonNoShapely(np.array([[10,10],[14,10],[14,13],[10,13]])).length()
0

>>> t1.differentiate()
(1.000000,3.000000) (1.000000,3.000000)
>>> t1.differentiate(True)
(1.000000,3.000000) (1.000000,3.000000) (1.000000,3.000000)
>>> t1 = Trajectory([[0.5,1.5,3.5],[0.5,2.5,7.5]])
>>> t1.differentiate()
(1.000000,2.000000) (2.000000,5.000000)

>>> from utils import LCSS
>>> lcss = LCSS(lambda x,y: Point.distanceNorm2(x,y) <= 0.1)
>>> Trajectory.lcss(t1, t1, lcss)
3
>>> lcss = LCSS(lambda p1, p2: (p1-p2).normMax() <= 0.1)
>>> Trajectory.lcss(t1, t1, lcss)
3

>>> p1=Point(0,0)
>>> p2=Point(1,0)
>>> v1 = Point(0.1,0.1)
>>> v2 = Point(-0.1, 0.1)
>>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.)-5.0) < 0.00001
True
>>> abs(Point.timeToCollision(p1, p2, v1, v2, 0.1)-4.5) < 0.00001
True
>>> p1=Point(0,1)
>>> p2=Point(1,0)
>>> v1 = Point(0,0.1)
>>> v2 = Point(0.1, 0)
>>> Point.timeToCollision(p1, p2, v1, v2, 0.) == None
True
>>> Point.timeToCollision(p2, p1, v2, v1, 0.) == None
True

>>> t = CurvilinearTrajectory(S = [1., 2., 3., 5.], Y = [0.5, 0.5, 0.6, 0.7], lanes = ['1']*4)
>>> t.differentiate() # doctest:+ELLIPSIS
[1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1']
>>> t.differentiate(True) # doctest:+ELLIPSIS
[1.0, 0.0, '1'] [1.0, 0.099..., '1'] [2.0, 0.099..., '1'] [2.0, 0.099..., '1']

>>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3]))
>>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)
>>> userTypeNames[o1.getUserType()]
'car'
>>> o1.classifyUserTypeSpeedMotorized(0.5, np.mean)
>>> userTypeNames[o1.getUserType()]
'car'
>>> o1.classifyUserTypeSpeedMotorized(1.5, np.median)
>>> userTypeNames[o1.getUserType()]
'pedestrian'