-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.py
More file actions
69 lines (53 loc) · 1.92 KB
/
vector.py
File metadata and controls
69 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import math
class Vec3D(object):
def __init__(self, x, y,phi):
self._x = x
self._y = y
self._phi = phi
def __add__(self, other):
return Vec3D(self._x + other._x, self._y + other._y,self._phi + other._phi)
def __iadd__(self, other):
if type(other) == int or type(other) == float:
return Vec3D(self._x + other, self._y + other,self._phi + other)
else:
return Vec3D(self._x + other._x, self._y + other._y,self._phi + other._phi)
def __sub__(self, other):
return Vec3D(self._x - other._x, self._y - other._y,self._phi - other._phi)
def __isub__(self, c):
return Vec3D(self._x - c, self._y - c,self._phi - c)
def __mul__(self, other):
if type(other) == int or type(other) == float:
return Vec3D(self._x*other, self._y*other, self._phi*other)
else:
return Vec3D(self._x*other._x, self._y*other._y, self._phi*other._phi)
def __imul__(self, other):
if type(other) == int or type(other) == float:
return Vec3D(self._x*other, self._y*other, self._phi*other)
else:
return Vec3D(self._x*other._x, self._y*other._y, self._phi*other._phi)
def __abs__(self):
return math.sqrt(self._x**2 + self._y**2 + self._phi**2)
def __eq__(self, other):
return self._x == other._x and self._y == other._y and self._phi == other._phi
def __str__(self):
return '(%g, %g, %g)' % (self._x, self._y,self._phi)
def __ne__(self, other):
return not self.__eq__(other) # reuse __eq__
# @property
# def x(self):
# return self._x
# @x.setter
# def x(self,x):
# self._x = x
# @property
# def y(self):
# return self._y
# @x.setter
# def y(self,y):
# self._y = y
# @property
# def phi(self):
# return self._phi
# @phi.setter
# def phi(self,phi):
# self._phi = phi