-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.py
121 lines (100 loc) · 3.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class Vector(object):
def __init__(self, coordinates):
"""
This function is used to initialize a vector
Args:
(self)
(coordinates): The values of the vector
"""
try:
if not coordinates:
raise ValueError
self.coordinates = tuple(coordinates)
self.dimension = len(coordinates)
except ValueError:
raise ValueError('Empty Coordinates')
except TypeError:
raise TypeError('Must be iterable')
def __str__(self):
"""
This function is Used when printing the object
Return:
A string that contains the coordonates
"""
return 'Vector: {}'.format(self.coordinates)
def __eq__(self, vector):
"""
This function is used to perform equality
Return:
If the coordinates are equal returns true
"""
return self.coordinates == vector.coordinates
def sum(self, vector):
"""
This function is used to perform the sum of two vectors:
Args:
(vector): the intend to sum vector
Return:
(sum): return the sum answer
"""
def minus(self, vector):
"""
This function is used to perform the minus of two vectors:
Args:
(vector): the intend to minus vector
Return:
(minus): return the minus answer
"""
def scaler_multiplication(self, scaler):
"""
This function is used to perform the scaler multiplication of a vector:
Args:
(scaler): the intend to multiply with a scaler
Return:
(scaler_multiplication): return the answer of scaler multiplication
"""
def magnitude(self):
"""
This function is used to get the magnitude of a vector
Return:
(magnitude): returns a value of the vector's magnitude
"""
def normalize(self, magnitude):
"""
This function is used to get the normalized vector of this
Args:
(magnitude): the calculated magnitude of the vector using magnitude() function
Return:
(normalized_vector): returns the normalized vector
"""
def dot(self, v):
"""
This function is used to find the dot product of two vectors
Args:
(v): the target vecor
Return:
the answer of the dot product.
"""
def angle(self, v):
"""
This function is used to find the angle between two vectors
Args:
(v): the second vector
Returns:
The angle between two vectors.
"""
def is_orthogonal_to(self, v):
"""
"""
def is_parallel_to(self, v):
"""
"""
def component_parallel_to(self, basis):
"""
"""
def component_orthogonal_to(self, basis):
"""
"""
def cross(self, v):
"""
"""