-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.py
50 lines (40 loc) · 1.45 KB
/
Vector.py
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
import numpy as np
class Vector:
def __init__(self,name,mag,degangle):
self.name=name
self.mag = mag
if degangle > 180:
self.degangle = degangle -360
elif degangle <= -180:
self.degangle = degangle + 360
else:
self.degangle = degangle
self.resolve()
def resolve(self):
self.radangle = (self.degangle*np.pi)/180
self.x = self.mag*np.cos(self.radangle)
self.y = self.mag*np.sin(self.radangle)
self.quad()
def quad(self):
if 0 <= self.degangle and 90 >= self.degangle: # Quad 1
self.x = np.abs(self.x)
self.y = np.abs(self.y)
elif 90 < self.degangle and 180 >= self.degangle: # Quad 2
self.x = -1*np.abs(self.x)
self.y = np.abs(self.y)
elif -90 > self.degangle and -180 < self.degangle: # Quad 3
self.x = -1*np.abs(self.x)
self.y = -1*np.abs(self.y)
elif 0 > self.degangle and -90 <= self.degangle: # Quad
self.x = np.abs(self.x)
self.y = -1*np.abs(self.y)
def add(self,vec2):
self.name = str(self.name+" + "+vec2.name)
self.x += vec2.x
self.y += vec2.y
self.mag = np.sqrt(self.x**2+self.y**2)
self.radangle = np.arctan2(self.y, self.x)
self.degangle = self.radangle * 180/np.pi
self.quad()
def rename(self,rename):
self.name = rename