Mercurial Hosting > traffic-intelligence
changeset 38:0d321c23d337
added norm functions for Point and accessor methods for MovingObject
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Tue, 18 May 2010 17:35:09 -0400 |
parents | 911b52744ceb |
children | e47168f6b694 |
files | python/moving.py |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Mon Apr 12 15:54:20 2010 -0400 +++ b/python/moving.py Tue May 18 17:35:09 2010 -0400 @@ -141,6 +141,24 @@ ''' return Point(self.x-other.x, self.y-other.y) + def norm2Squared(self): + '''2-norm distance (Euclidean distance) + >>> Point(3,2).norm2Squared() + 13 + ''' + return self.x*self.x+self.y*self.y + + def norm2(self): + '2-norm distance (Euclidean distance)' + return sqrt(self.norm2Squared()) + + def distanceNorm2(p1, p2): + ''' + >>> Point.distanceNorm2(Point(3,4),Point(1,7)) + 3.6055512754639891 + ''' + return (p1-p2).norm2() + def aslist(self): return [self.x, self.y] @@ -227,6 +245,18 @@ def length(self): return self.timeInterval.length() + def getPositions(self): + return self.positions + + def getVelocities(self): + return self.velocities + + def getPositionAt(self, i): + return self.positions[i] + + def getVelocityAt(self, i): + return self.velocities[i] + def getXCoordinates(self): return self.positions.getXCoordinates()