Skip to content

Instantly share code, notes, and snippets.

@leixingyu
Last active September 21, 2022 01:56
Show Gist options
  • Save leixingyu/f8849105d509bd52723f3e94a35cab67 to your computer and use it in GitHub Desktop.
Save leixingyu/f8849105d509bd52723f3e94a35cab67 to your computer and use it in GitHub Desktop.
import numpy as np
np.set_printoptions(precision=3)
np.set_printoptions(suppress=True)
def change_xform(source_xform, change_of_basis):
"""
Change a transformation matrix from one coordinate to another
https://youtu.be/P2LTAUO1TdA
M_new = M_cob * M_source * inverse(M_cob)
:param source_xform: numpy.ndarray. original transformation matrix
:param change_of_basis: numpy.ndarray. change of basis matrix
:return: converted transformation matrix in new coordinate system
"""
inverse_change_of_basis = np.linalg.inv(change_of_basis)
temp = np.matmul(change_of_basis, source_xform)
return np.matmul(temp, inverse_change_of_basis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment