Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 937:b67a784beb69
work started on prototype prediction
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 17 Jul 2017 01:38:06 -0400 |
parents | 56cc8a1f7082 |
children | a2f3f3ca241e |
line wrap: on
line diff
--- a/python/moving.py Fri Jul 14 16:48:42 2017 -0400 +++ b/python/moving.py Mon Jul 17 01:38:06 2017 -0400 @@ -865,6 +865,23 @@ positions = self.getPositions().asArray().T return cdist(positions, positions, metric = metric).max() + def getClosestPoint(self, p1, maxDist2 = None): + '''Returns the instant of the closest position in trajectory to p1 (and the point) + if maxDist is not None, will check the distance is smaller + TODO: could use cdist for different metrics''' + distances2 = [] + minDist2 = float('inf') + i = -1 + for p2 in self: + distances2.append(Point.distanceNorm2(p1, p2)) + if distances2[-1] < minDist2: + minDist2 = distances2[-1] + i = len(distances)-1 + if maxDist2 is None or (maxDist2 is not None and minDist2 < maxDist2): + return i + else: + return None + def similarOrientation(self, refDirection, cosineThreshold, minProportion = 0.5): '''Indicates whether the minProportion (<=1.) (eg half) of the trajectory elements (vectors for velocity) have a cosine with refDirection is smaller than cosineThreshold'''