Mercurial Hosting > traffic-intelligence
comparison python/utils.py @ 569:0057c04f94d5
work in progress on intersections (for PET)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 06 Aug 2014 17:53:38 -0400 |
parents | ee45c6eb6d49 |
children | e24eeb244698 |
comparison
equal
deleted
inserted
replaced
567:072cedc3f33d | 569:0057c04f94d5 |
---|---|
2 ''' Generic utilities.''' | 2 ''' Generic utilities.''' |
3 | 3 |
4 #from numpy import * | 4 #from numpy import * |
5 #from pylab import * | 5 #from pylab import * |
6 from datetime import time, datetime | 6 from datetime import time, datetime |
7 from math import sqrt | |
7 | 8 |
8 __metaclass__ = type | 9 __metaclass__ = type |
9 | 10 |
10 datetimeFormat = "%Y-%m-%d %H:%M:%S" | 11 datetimeFormat = "%Y-%m-%d %H:%M:%S" |
11 | 12 |
239 from math import ceil,pow | 240 from math import ceil,pow |
240 tens = pow(10,nDecimals) | 241 tens = pow(10,nDecimals) |
241 return ceil(v*tens)/tens | 242 return ceil(v*tens)/tens |
242 | 243 |
243 def inBetween(bound1, bound2, x): | 244 def inBetween(bound1, bound2, x): |
244 return bound1 <= x <= bound2 or bound2 <= x<= bound1 | 245 return bound1 <= x <= bound2 or bound2 <= x <= bound1 |
246 | |
247 def pointDistanceL2(x1,y1,x2,y2): | |
248 ''' Compute point-to-point distance (L2 norm, ie Euclidean distance)''' | |
249 return sqrt((x2-x1)**2+(y2-y1)**2) | |
245 | 250 |
246 def crossProduct(l1, l2): | 251 def crossProduct(l1, l2): |
247 return l1[0]*l2[1]-l1[1]*l2[0] | 252 return l1[0]*l2[1]-l1[1]*l2[0] |
248 | 253 |
249 def filterMovingWindow(inputSignal, halfWidth): | 254 def filterMovingWindow(inputSignal, halfWidth): |