forked from lozuwa/impy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectorOperations.py
executable file
·50 lines (45 loc) · 1.31 KB
/
VectorOperations.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
"""
Author: Rodrigo Loza
Email: [email protected]
Description: Implements mathematical operations
related to vectors.
"""
import math
class VectorOperations(object):
def __init__(self):
super(VectorOperations, self).__init__()
@staticmethod
def compute_module(vector = None):
"""
Computes the module of a vector.
Args:
vector: A list or tuple that contains the coordinates that define
the position of the vector.
Returns:
A float that contains the module of the vector.
"""
module = math.sqrt(sum([i**2 for i in vector]))
return module
@staticmethod
def euclidean_distance(v0 = None, v1 = None):
"""
Computes the Euler distance between two points.
Args:
v0: A list that contains a vector.
v1: A list that contains another vector.
Returns:
An integer that contains the Euler distance.
"""
distance = math.sqrt(sum([(i-j)**2 for i,j in zip(v0, v1)]))
return distance
@staticmethod
def rotation_equations(x, y, theta):
"""
Apply a 2D rotation matrix to a 2D coordinate by theta degrees.
Args:
x: An int that represents the x dimension of the coordinate.
y: An int that represents the y dimension of the coordinate.
"""
x_result = int((x*math.cos(theta)) - (y*math.sin(theta)))
y_result = int((x*math.sin(theta)) + (y*math.cos(theta)))
return x_result, y_result