-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
56 lines (41 loc) · 1.29 KB
/
test.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
import numpy as np
import random
from abc import abstractmethod
from models.orientation import Rotation
from models.math import Vector, Quaternion
class Test:
@abstractmethod
def run(self):
pass
class QuaternionRotationTest(Test):
def run(self):
face = Quaternion(0, 1, 0, 0)
head = Quaternion(0, 0, 0, 1)
rotation = Rotation(np.pi/2, 0, 1, 0)
print(rotation)
print(rotation.rotate(face))
print(rotation.rotate(head))
class VectorOperationTest(Test):
def run(self):
""" Multiplication within an integer """
v1 = Vector(random.random(), random.random(), random.random())
m = random.randint(1, 5)
print(v1, m, v1 * m, m * v1, v1*m == m*v1)
""" Division within a float """
print(v1, m, v1 / m)
""" Addition """
v2 = Vector(random.random(), random.random(), random.random())
print(v1, v2, v1 + v2, v2 + v1)
""" Subtraction """
print(v1, v2, v1 - v2, v2 - v1)
""" Projection """
x = Vector(1, 1, 1)
y = Vector(1, 0, 1)
projection = x.projection(y)
print(x)
print(y)
print(projection)
print(x.scalar_projection(y))
if __name__ == '__main__':
test = VectorOperationTest()
test.run()