ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how to get rotation matrix from quaternion in python

asked 2019-05-30 12:19:46 -0500

mugetsu gravatar image

I can see tf.transformations have a matrix to quaternion function, but is there a way to do the opposite in python?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2019-05-31 04:47:18 -0500

Mehdi. gravatar image

updated 2019-05-31 04:51:38 -0500

you can import tf.transformations and use the many functions defined there the code itself can be found here

from tf.transformations import quaternion_matrix
matrix = quaternion_matrix([1, 0, 0, 0])

Just be careful for what you type in, I think the order here if you use a quaternion from a ros message would be [quat.w, quat.x, quat.y, quat.z]

EDIT: the version coming with ROS Kinetic is quite old and uses the input [quat.x, quat.y, quat.z, quat.w], the updated version on the link uses the reversed input shown above.

edit flag offensive delete link more

answered 2019-05-30 17:41:10 -0500

Geoff gravatar image

updated 2019-05-30 17:42:23 -0500

The tf.TransformerROS class has a fromTranslationRotation method that will turn a translation and quaternion into a 4x4 matrix representation. If you set the translation to zero then it will give you just the rotation in the matrix. The asMatrix method is also relevant if you have just the target frame, because it will also do the lookup for you.

edit flag offensive delete link more

answered 2019-05-30 13:36:53 -0500

pring gravatar image

pretty simple to code start here

edit flag offensive delete link more

Question Tools


Asked: 2019-05-30 12:19:46 -0500

Seen: 9,299 times

Last updated: May 31 '19