view vector.py @ 48:0598557ca61b
Nicer tank graphics. Displays body direction too.
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Mon, 20 Dec 2010 20:58:14 +0300 |
parents |
b7a85caedc7f dfdc1def5d24 |
children |
d740eff76e7e |
line source
5 def __init__(self, x=0 , y=0):
9 def __add__(self, other):
11 result.x = self.x + other.x
12 result.y = self.y + other.y
15 def __sub__(self, other):
17 result.x = self.x - other.x
18 result.y = self.y - other.y
21 def __mul__(self, alpha):
23 result.x = self.x * alpha
24 result.y = self.y * alpha
27 def dot_product(self, other):
28 return self.x*other.x + self.y*other.y
31 return (self.x**2 + self.y**2)**0.5
34 return "(%s, %s)" % (self.x, self.y)
52 def set_rho(self, new_rho):
53 if self.is_null() == 1:
54 self.x , self.y = new_rho*math.cos(self.phi) , new_rho*math.sin(self.phi)
56 self.x , self.y = self.x*(new_rho/abs(self)) , self.y*(new_rho/abs(self))
58 rho = property(get_rho, set_rho)
61 phi = math.pi/2 - math.atan2(self.x, self.y)
66 def set_phi(self, new_phi):
68 self.x , self.y = rho*math.cos(new_phi) , rho*math.sin(new_phi)
70 phi = property(get_phi, set_phi)