Skip to content

Instantly share code, notes, and snippets.

@nicolov
Created August 9, 2016 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolov/10399012bdfcd5be6ab46ade3266c608 to your computer and use it in GitHub Desktop.
Save nicolov/10399012bdfcd5be6ab46ade3266c608 to your computer and use it in GitHub Desktop.
Tilt-torsion decomposition for rotation matrices
import numpy as np
from tf.transformations import *
def tilt_torsion_decomposition(R):
z_axis = [0, 0, 1]
target_z = np.dot(R.T, z_axis)
axis = np.cross(z_axis, target_z)
angle = np.arctan2(np.linalg.norm(axis), np.dot(z_axis, target_z))
R_tilt = quaternion_matrix(quaternion_about_axis(angle, axis))[:3, :3]
R_torsion = np.dot(R, R_tilt.T)
return R_torsion, R_tilt
tor1, tilt1 = tilt_torsion_decomposition(euler_matrix(0.5, 1, 1)[:3, :3])
tor2, tilt2 = tilt_torsion_decomposition(euler_matrix(0.5, 1, 0.5)[:3, :3])
euler_from_matrix(np.dot(tor1, tilt1)) # 0.5, 1, 1
euler_from_matrix(np.dot(tor2, tilt1)) # 0.5, 1, 0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment