-
Notifications
You must be signed in to change notification settings - Fork 1
/
transform.py
64 lines (43 loc) · 1.39 KB
/
transform.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
62
63
64
import numpy as np
def getTransFromRp(R, p):
T = np.vstack((np.hstack((R, np.array([[p[0]], [p[1]], [p[2]]]))),
np.array([0, 0, 0, 1])))
return T
def getRotationRoll(theta):
R = np.array([[1, 0, 0],
[0, np.cos(theta), -np.sin(theta)],
[0, np.sin(theta), np.cos(theta)]])
return R
def getRotationPitch(theta):
R = np.array([[np.cos(theta), 0, np.sin(theta)],
[0, 1, 0],
[-np.sin(theta), 0, np.cos(theta)]])
return R
def getRotationYaw(theta):
R = np.array([[np.cos(theta), -np.sin(theta), 0],
[np.sin(theta), np.cos(theta), 0],
[0, 0, 1]])
return R
def getPositionFromT(T):
p = T[0:3, 3]
return p
def getRotationFromT(T):
R = T[0:3, 0:3]
return R
def getRotationAndPositionFromT(T):
p = T[0:3, 3]
R = T[0:3, 0:3]
return R, p
def getRollPitchYawFromR(R):
pitch = np.arcsin(-R[2, 0])
yaw = np.arctan2(R[1, 0], R[0, 0])
roll = np.arctan2(R[2, 1], R[2, 2])
return np.array([roll, pitch, yaw])
def skewSymmetricMatrix(v):
matrix = np.array([[0, -v[2], v[1]],
[v[2], 0, -v[0]],
[-v[1], v[0], 0]])
return matrix
def rodriguesEquation(E, a, theta):
a_h = skewSymmetricMatrix(a)
return E + a_h * np.sin(theta) + a_h.dot(a_h) * (1 - np.cos(theta))