-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
38 lines (30 loc) · 774 Bytes
/
utils.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
import math
def R(x, y):
"""
Polar transform (r, theta) for (x, y)
"""
r = math.sqrt(x**2 + y**2)
theta = math.atan2(y, x)
return r, theta
def M(theta):
"""
Map theta to [-pi, pi)
"""
theta %= 2 * math.pi
if theta < -math.pi: theta += 2 * math.pi
elif theta >= math.pi: theta -= 2 * math.pi
return theta
def normalize_basis(p1, p2):
"""
Normalize the basis so that p1 equals (0, 0, 0)
"""
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
phi1 = p1[2]
# Rotation matrix with -phi
x_new = math.cos(phi1) * dx + math.sin(phi1) * dy
y_new = -math.sin(phi1) * dx + math.cos(phi1) * dy
phi_new = p2[2] - p1[2]
return x_new, y_new, phi_new
def rad2deg(rad):
return rad / math.pi * 180