MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / euler_from_matrix

Function euler_from_matrix

utils/utils_poses/ATE/transformations.py:1264–1319  ·  view source on GitHub ↗

Return Euler angles from rotation matrix for specified axis sequence. axes : One of 24 axis sequences as string or encoded tuple Note that many Euler angle triplets can describe one matrix. >>> R0 = euler_matrix(1, 2, 3, 'syxz') >>> al, be, ga = euler_from_matrix(R0, 'syxz') >

(matrix, axes='sxyz')

Source from the content-addressed store, hash-verified

1262
1263
1264def euler_from_matrix(matrix, axes='sxyz'):
1265 """Return Euler angles from rotation matrix for specified axis sequence.
1266
1267 axes : One of 24 axis sequences as string or encoded tuple
1268
1269 Note that many Euler angle triplets can describe one matrix.
1270
1271 >>> R0 = euler_matrix(1, 2, 3, 'syxz')
1272 >>> al, be, ga = euler_from_matrix(R0, 'syxz')
1273 >>> R1 = euler_matrix(al, be, ga, 'syxz')
1274 >>> numpy.allclose(R0, R1)
1275 True
1276 >>> angles = (4.0*math.pi) * (numpy.random.random(3) - 0.5)
1277 >>> for axes in _AXES2TUPLE.keys():
1278 ... R0 = euler_matrix(axes=axes, *angles)
1279 ... R1 = euler_matrix(axes=axes, *euler_from_matrix(R0, axes))
1280 ... if not numpy.allclose(R0, R1): print axes, "failed"
1281
1282 """
1283 try:
1284 firstaxis, parity, repetition, frame = _AXES2TUPLE[axes.lower()]
1285 except (AttributeError, KeyError):
1286 _ = _TUPLE2AXES[axes]
1287 firstaxis, parity, repetition, frame = axes
1288
1289 i = firstaxis
1290 j = _NEXT_AXIS[i+parity]
1291 k = _NEXT_AXIS[i-parity+1]
1292
1293 M = numpy.array(matrix, dtype=numpy.float64, copy=False)[:3, :3]
1294 if repetition:
1295 sy = math.sqrt(M[i, j]*M[i, j] + M[i, k]*M[i, k])
1296 if sy > _EPS:
1297 ax = math.atan2(M[i, j], M[i, k])
1298 ay = math.atan2(sy, M[i, i])
1299 az = math.atan2(M[j, i], -M[k, i])
1300 else:
1301 ax = math.atan2(-M[j, k], M[j, j])
1302 ay = math.atan2(sy, M[i, i])
1303 az = 0.0
1304 else:
1305 cy = math.sqrt(M[i, i]*M[i, i] + M[j, i]*M[j, i])
1306 if cy > _EPS:
1307 ax = math.atan2(M[k, j], M[k, k])
1308 ay = math.atan2(-M[k, i], cy)
1309 az = math.atan2(M[j, i], M[i, i])
1310 else:
1311 ax = math.atan2(-M[j, k], M[j, j])
1312 ay = math.atan2(-M[k, i], cy)
1313 az = 0.0
1314
1315 if parity:
1316 ax, ay, az = -ax, -ay, -az
1317 if frame:
1318 ax, az = az, ax
1319 return ax, ay, az
1320
1321

Callers 1

euler_from_quaternionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected