Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 255:13ec22bec5d4
corrected typos and bugs and added a test
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 23 Jul 2012 23:07:19 -0400 |
parents | 59f547aebaac |
children | dc1faa7287bd |
comparison
equal
deleted
inserted
replaced
254:4b71e81e3383 | 255:13ec22bec5d4 |
---|---|
243 angle = atan2(p.x, p.y) | 243 angle = atan2(p.x, p.y) |
244 return NormAngle(norm, angle) | 244 return NormAngle(norm, angle) |
245 | 245 |
246 def __add__(self, other): | 246 def __add__(self, other): |
247 'a norm cannot become negative' | 247 'a norm cannot become negative' |
248 return NormAngle(max(self.norm+other.norm, 0), self.orientation+other.orientation) | 248 return NormAngle(max(self.norm+other.norm, 0), self.angle+other.angle) |
249 | 249 |
250 def getPoint(self): | 250 def getPoint(self): |
251 from math import cos, sin | 251 from math import cos, sin |
252 return Point(self.norm*cos(self.orientation), self.norm*sin(self.orientation)) | 252 return Point(self.norm*cos(self.angle), self.norm*sin(self.angle)) |
253 | 253 |
254 | 254 |
255 def predictPositionNoLimit(nTimeSteps, initialPosition, initialVelocity, initialAcceleration = Point(0,0)): | 255 def predictPositionNoLimit(nTimeSteps, initialPosition, initialVelocity, initialAcceleration = Point(0,0)): |
256 '''Predicts the position in nTimeSteps at constant speed/acceleration''' | 256 '''Predicts the position in nTimeSteps at constant speed/acceleration''' |
257 return initialVelocity + initialAcceleration.multiply(nTimeSteps),initialPosition+initialVelocity.multiply(nTimeSteps) + initialAcceleration.multiply(nTimeSteps**2*0.5) | 257 return initialVelocity + initialAcceleration.multiply(nTimeSteps),initialPosition+initialVelocity.multiply(nTimeSteps) + initialAcceleration.multiply(nTimeSteps**2*0.5) |
569 return [t+self.getFirstInstant() for t in indices] | 569 return [t+self.getFirstInstant() for t in indices] |
570 | 570 |
571 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): | 571 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): |
572 '''Predicts the position of object at instant+deltaT, | 572 '''Predicts the position of object at instant+deltaT, |
573 at constant speed''' | 573 at constant speed''' |
574 return predictPosition(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) | 574 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) |
575 | 575 |
576 @staticmethod | 576 @staticmethod |
577 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | 577 def collisionCourseDotProduct(movingObject1, movingObject2, instant): |
578 'A positive result indicates that the road users are getting closer' | 578 'A positive result indicates that the road users are getting closer' |
579 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | 579 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) |