comparison python/moving.py @ 148:ad21db62b785

bug correction for cosine functions in python
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 01 Sep 2011 16:44:23 -0400
parents 550556378466
children 74b1fc68d4df
comparison
equal deleted inserted replaced
147:0089fb29cd26 148:ad21db62b785
423 @staticmethod 423 @staticmethod
424 def collisionCourseDotProduct(movingObject1, movingObject2, instant): 424 def collisionCourseDotProduct(movingObject1, movingObject2, instant):
425 'A positive result indicates that the road users are getting closer' 425 'A positive result indicates that the road users are getting closer'
426 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) 426 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant)
427 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) 427 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)
428 return moving.Point.dot(deltap, deltav) 428 return Point.dot(deltap, deltav)
429 429
430 @staticmethod 430 @staticmethod
431 def collisionCourseCosine(movingObject1, movingObject2, instant): 431 def collisionCourseCosine(movingObject1, movingObject2, instant):
432 'A positive result indicates that the road users are getting closer' 432 'A positive result indicates that the road users are getting closer'
433 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) 433 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant)
434 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) 434 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)
435 return moving.Point.dot(deltap, deltav)/(deltap.norm2()*deltav.norm2()) 435 return Point.dot(deltap, deltav)/(deltap.norm2()*deltav.norm2())
436 436
437 def plotRoadUsers(objects, colors): 437 def plotRoadUsers(objects, colors):
438 '''Colors is a PlottingPropertyValues instance''' 438 '''Colors is a PlottingPropertyValues instance'''
439 from matplotlib.pyplot import figure, axis 439 from matplotlib.pyplot import figure, axis
440 figure() 440 figure()