Changeset 29:779e091fb740
- Timestamp:
- 12/20/10 11:36:35 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tanchiki/vector.py
r28 r29 ˆà 1 1 import mathˆà 2 2 ˆà 3 ˆà class Vector(object): ˆà 4 ˆà ˆà 5 ˆà def __init__(self, x=0 , y=0): ˆà ˆà 3 class Vector(object):ˆà ˆà 4 def __init__(self, x=0 , y=0):ˆà 6 5 self.x = xˆà 7 6 self.y = yˆà 8 7 ˆà 9 8 def __add__(self, other):ˆà 10 ˆà result = Vector(0, 0)ˆàˆà 9 result = Vector(0, 0)ˆà 11 10 result.x = self.x + other.xˆà 12 11 result.y = self.y + other.yˆà òÀæ òÀæ ˆà 20 19 ˆà 21 20 def dot_product(self, other):ˆà 22 ˆà return self.x*other.x + self.y*other.y ˆà 21 return self.x*other.x + self.y*other.yˆà 23 22 ˆà 24 23 def __abs__(self):ˆà òÀæ òÀæ ˆà 50 49 self.x , self.y = self.x*(new_rho/abs(self)) , self.y*(new_rho/abs(self))ˆà 51 50 ˆà 52 ˆà rho = property(get_rho, set_rho) ˆà 51 rho = property(get_rho, set_rho)ˆà 53 52 ˆà 54 53 def get_phi(self):ˆà òÀæ òÀæ ˆà 63 62 ˆà 64 63 phi = property(get_phi, set_phi)ˆà ˆà 64 ˆà ˆà 65 Vector.null = Vector(0, 0)ˆà
Note: See TracChangeset
for help on using the changeset viewer.