Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 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 | 418b41056e6c |
children | e47168f6b694 |
comparison
equal
deleted
inserted
replaced
37:911b52744ceb | 38:0d321c23d337 |
---|---|
139 >>> Point(3,4)-Point(1,7) | 139 >>> Point(3,4)-Point(1,7) |
140 (2.000000,-3.000000) | 140 (2.000000,-3.000000) |
141 ''' | 141 ''' |
142 return Point(self.x-other.x, self.y-other.y) | 142 return Point(self.x-other.x, self.y-other.y) |
143 | 143 |
144 def norm2Squared(self): | |
145 '''2-norm distance (Euclidean distance) | |
146 >>> Point(3,2).norm2Squared() | |
147 13 | |
148 ''' | |
149 return self.x*self.x+self.y*self.y | |
150 | |
151 def norm2(self): | |
152 '2-norm distance (Euclidean distance)' | |
153 return sqrt(self.norm2Squared()) | |
154 | |
155 def distanceNorm2(p1, p2): | |
156 ''' | |
157 >>> Point.distanceNorm2(Point(3,4),Point(1,7)) | |
158 3.6055512754639891 | |
159 ''' | |
160 return (p1-p2).norm2() | |
161 | |
144 def aslist(self): | 162 def aslist(self): |
145 return [self.x, self.y] | 163 return [self.x, self.y] |
146 | 164 |
147 class Trajectory: | 165 class Trajectory: |
148 '''Class for trajectories | 166 '''Class for trajectories |
224 self.type = type | 242 self.type = type |
225 # compute bounding polygon from trajectory | 243 # compute bounding polygon from trajectory |
226 | 244 |
227 def length(self): | 245 def length(self): |
228 return self.timeInterval.length() | 246 return self.timeInterval.length() |
247 | |
248 def getPositions(self): | |
249 return self.positions | |
250 | |
251 def getVelocities(self): | |
252 return self.velocities | |
253 | |
254 def getPositionAt(self, i): | |
255 return self.positions[i] | |
256 | |
257 def getVelocityAt(self, i): | |
258 return self.velocities[i] | |
229 | 259 |
230 def getXCoordinates(self): | 260 def getXCoordinates(self): |
231 return self.positions.getXCoordinates() | 261 return self.positions.getXCoordinates() |
232 | 262 |
233 def getYCoordinates(self): | 263 def getYCoordinates(self): |