-
Notifications
You must be signed in to change notification settings - Fork 0
/
angle.py
42 lines (28 loc) · 1.05 KB
/
angle.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
"""Calculating vector's angle w.r.t. given axis"""
import argparse
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--coordinate', nargs='*', default=[-2.978715e-01, 9.506773e-01,8.641501e-02])
parser.add_argument('-a', '--axis', type=int,
help="axis index of the angle you want to calculate, beginning at `0`",
default=2)
parse = parser.parse_args()
def main(coordinate=parse.coordinate, axis=parse.axis, module=False):
"""Calculating vector's angle w.r.t. given axis
:param coordinate:
:param axis: Axis index of the angle you want to calculate, beginning at `0`
:param module: `True` if using for other program
:return: Angle (Union: degree)
"""
if len(coordinate) != 3:
return None
sum = 0
for coor in coordinate:
sum += float(coor) ** 2
angle = np.arccos(float(coordinate[axis]) / (sum ** 0.5))
if not module:
print(angle * 180 / np.pi)
else:
return angle * 180 / np.pi
if __name__ == '__main__':
main()