'Coordinate transform using rotation vector produces zero vector

Our goal is to transform a rotation r in XYZ coordinate to XZY.

Now suppose the rotation r = (0.5,0.7,0.7), we will first transform it into a rotation matrix format. Then we will transform it from XYZ into XZY. Below is our code.

(We use from scipy.spatial.transform import Rotation, please install to run the toy demo.)

from scipy.spatial.transform import Rotation as R
import numpy as np
if __name__ == '__main__':
    trans_mat = np.array([[1., 0., 0.], [0., 0., 1.], [0., 1., 0.]])
    # we use trans_mat to map the rotation from XYZ to XZY.

    r = R.from_rotvec(np.array([0.1, 0.7, 0.7]))
    print(r.as_rotvec())
    # r is the rotation vector, for which we want to map it from XYZ to XZY.
    print(r.as_matrix())
    print("---")
    print(trans_mat)
    # we express it into matrix format.
    mat = trans_mat @ r.as_matrix()
    # we apply coordinate transform to r.
    print(mat)

    print(R.from_matrix(mat).as_rotvec())
    # here we print the rotation after applying coordinate transform to r.

    # And we can see the result is [0,0,0]


This is confusing...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source