2 Tiny matrix functions, taken from Oscar source code.
6 from random
import random
8 from numpy
import array, cos, inner, matrix, pi, sin, sqrt
9 from numpy.linalg
import norm
23 return tuple(M.tolist())
25 return tuple(M.tolist()[0])
27 return tuple(M.transpose().tolist()[0])
38 px = M1[0][3] - M2[0][3]
39 py = M1[1][3] - M2[1][3]
40 pz = M1[2][3] - M2[2][3]
56 u2 = v2 - inner(v2, e1) * e1
59 u3 = v3 - inner(v3, e1) * e1 - inner(v3, e2) * e2
66 (e1[0][0], e2[0][0], e3[0][0]),
67 (e1[0][1], e2[0][1], e3[0][1]),
68 (e1[0][2], e2[0][2], e3[0][2]),
75 m = sqrt(M[2][1] ** 2 + M[2][2] ** 2)
76 p = atan2(-M[2][0], m)
78 if abs(p - pi / 2) < 0.001:
80 y = atan2(M[0][1], M[1][1])
81 elif abs(p + pi / 2) < 0.001:
83 y = -atan2(M[0][1], M[1][1])
85 r = atan2(M[1][0], M[0][0])
86 y = atan2(M[2][1], M[2][2])
88 return [float(r), float(p), float(y)]
93 Convert a 4x4 homogeneous matrix to a 6x1 rpy pose vector.
96 return [M[0][3], M[1][3], M[2][3], rot[2], rot[1], rot[0]]
101 Convert a 6x1 rpy pose vector to a 4x4 homogeneous matrix.
103 M = array(
rpy2tr(pr[3], pr[4], pr[5]))
110 """eg. T=rot('x',pi/4): rotate pi/4 rad about x axis"""
114 mat = ((1, 0, 0, 0), (0, ca, -sa, 0), (0, sa, ca, 0), (0, 0, 0, 1))
116 mat = ((ca, 0, sa, 0), (0, 1, 0, 0), (-sa, 0, ca, 0), (0, 0, 0, 1))
118 mat = ((ca, -sa, 0, 0), (sa, ca, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))
120 print(
"Axis should be: x,y or z only")
128 1 - 2 * qy**2 - 2 * qz**2,
129 2 * qx * qy - 2 * qz * qw,
130 2 * qx * qz + 2 * qy * qw,
133 2 * qx * qy + 2 * qz * qw,
134 1 - 2 * qx**2 - 2 * qz**2,
135 2 * qy * qz - 2 * qx * qw,
138 2 * qx * qz - 2 * qy * qw,
139 2 * qy * qz + 2 * qx * qw,
140 1 - 2 * qx**2 - 2 * qy**2,