-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcoordinate_conversion.py
61 lines (38 loc) · 1.01 KB
/
coordinate_conversion.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
import numpy as np
def index_to_angle(index, shape):
angle = np.zeros(2)
a = index[0]
b = index[1]
M = shape[0]
N = shape[1]
alpha = (a-0.5*M+0.5) * np.pi / M
beta = (b-0.5*N+0.5) * np.pi / N
angle[0] = alpha
angle[1] = beta
return angle
def angle_to_index(angle, shape):
alpha = angle[0]
beta = angle[1]
M = shape[0]
N = shape[1]
a = (alpha / np.pi + 0.5 - 0.5/M) * M
b = (beta / np.pi + 0.5 - 0.5/N) * N
index = np.array([a,b])
return index
def angle_to_point(angle):
alpha = angle[0]
beta = angle[1]
point = np.zeros(3)
point[1] = np.sin(beta)
point[0] = np.sin(alpha)*np.cos(beta)
point[2] = np.cos(alpha)*np.cos(beta)
point *= np.sign(point[2])
return point
def point_to_angle(point):
angle = np.zeros(2)
angle[1] = np.arcsin(point[1])
inner = point[0] / np.cos(angle[1])
inner = np.minimum(inner, 1)
inner = np.maximum(inner, -1)
angle[0] = np.arcsin(inner)
return angle