Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 245:bd8ab323c198
corrected issue with predictPosiont static method
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 17 Jul 2012 13:25:34 -0400 |
parents | 5027c174ab90 |
children | 571ba5ed22e2 |
comparison
equal
deleted
inserted
replaced
244:5027c174ab90 | 245:bd8ab323c198 |
---|---|
189 if p1.x == p2.x or self.x <= xinters: | 189 if p1.x == p2.x or self.x <= xinters: |
190 counter+=1; | 190 counter+=1; |
191 p1=p2 | 191 p1=p2 |
192 return (counter%2 == 1); | 192 return (counter%2 == 1); |
193 | 193 |
194 | |
195 @staticmethod | 194 @staticmethod |
196 def dot(p1, p2): | 195 def dot(p1, p2): |
197 'Scalar product' | 196 'Scalar product' |
198 return p1.x*p2.x+p1.y*p2.y | 197 return p1.x*p2.x+p1.y*p2.y |
199 | 198 |
209 @staticmethod | 208 @staticmethod |
210 def plotAll(points, color='r'): | 209 def plotAll(points, color='r'): |
211 from matplotlib.pyplot import scatter | 210 from matplotlib.pyplot import scatter |
212 scatter([p.x for p in points],[p.y for p in points], c=color) | 211 scatter([p.x for p in points],[p.y for p in points], c=color) |
213 | 212 |
214 @staticmethod | 213 |
215 def predictPosition(nTimeSteps, initialPosition, initialVelocity, initialAcceleration = Point(0,0)): | 214 def predictPosition(nTimeSteps, initialPosition, initialVelocity, initialAcceleration = Point(0,0)): |
216 '''Predicts the position in nTimeSteps at constant speed/acceleration''' | 215 '''Predicts the position in nTimeSteps at constant speed/acceleration''' |
217 return initalPosition+velocity.multiply(nTimeSteps) + initialAcceleration.multiply(nTimeSteps**2) | 216 return initalPosition+velocity.multiply(nTimeSteps) + initialAcceleration.multiply(nTimeSteps**2) |
217 | |
218 | 218 |
219 class FlowVector: | 219 class FlowVector: |
220 '''Class to represent 4-D flow vectors, | 220 '''Class to represent 4-D flow vectors, |
221 ie a position and a velocity''' | 221 ie a position and a velocity''' |
222 def __init__(self, position, velocity): | 222 def __init__(self, position, velocity): |
514 return [t+self.getFirstInstant() for t in indices] | 514 return [t+self.getFirstInstant() for t in indices] |
515 | 515 |
516 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): | 516 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): |
517 '''Predicts the position of object at instant+deltaT, | 517 '''Predicts the position of object at instant+deltaT, |
518 at constant speed''' | 518 at constant speed''' |
519 return Point.predictPosition(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) | 519 return predictPosition(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) |
520 | 520 |
521 @staticmethod | 521 @staticmethod |
522 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | 522 def collisionCourseDotProduct(movingObject1, movingObject2, instant): |
523 'A positive result indicates that the road users are getting closer' | 523 'A positive result indicates that the road users are getting closer' |
524 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | 524 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) |