comparison python/moving.py @ 339:9c1818a71c9c

minor
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 19 Jun 2013 22:56:21 -0400
parents 3950bfe22768
children 74e437ab5f11
comparison
equal deleted inserted replaced
338:f3aceea2afbb 339:9c1818a71c9c
252 def fromPoint(p): 252 def fromPoint(p):
253 from math import atan2 253 from math import atan2
254 norm = p.norm2() 254 norm = p.norm2()
255 if norm > 0: 255 if norm > 0:
256 angle = atan2(p.y, p.x) 256 angle = atan2(p.y, p.x)
257 else:
258 angle = 0.
257 return NormAngle(norm, angle) 259 return NormAngle(norm, angle)
258 260
259 def __add__(self, other): 261 def __add__(self, other):
260 'a norm cannot become negative' 262 'a norm cannot become negative'
261 return NormAngle(max(self.norm+other.norm, 0), self.angle+other.angle) 263 return NormAngle(max(self.norm+other.norm, 0), self.angle+other.angle)
455 print 'Trajectories of different lengths' 457 print 'Trajectories of different lengths'
456 return None 458 return None
457 else: 459 else:
458 return Trajectory([[a-b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())], 460 return Trajectory([[a-b for a,b in zip(self.getXCoordinates(),traj2.getXCoordinates())],
459 [a-b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]]) 461 [a-b for a,b in zip(self.getYCoordinates(),traj2.getYCoordinates())]])
462
463 def differentiate(self):
464 diff = Trajectory()
465 for i in xrange(1, self.length()):
466 diff.addPosition(self[i]-self[i-1])
467 return diff
460 468
461 def norm(self): 469 def norm(self):
462 '''Returns the list of the norms at each instant''' 470 '''Returns the list of the norms at each instant'''
463 # def add(x, y): return x+y 471 # def add(x, y): return x+y
464 # sq = map(add, [x*x for x in self.positions[0]], [y*y for y in self.positions[1]]) 472 # sq = map(add, [x*x for x in self.positions[0]], [y*y for y in self.positions[1]])