ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to get the transformation matrix from translation and rotation

asked 2020-10-02 11:25:19 -0500

antibus gravatar image

From tf.Transformer.lookupTransform() I get the translation and rotation. Is there a convenient way to get the 4x4 transformation matrix from those vectors?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-04 06:36:01 -0500

bob-ROS gravatar image

By 4x4 Transformation matrix, I assume you want an affine 3d transformation.

#include <tf2_eigen/tf2_eigen.h>  // I think is the only needed additional dependency

bool getTfTransformMatrix(Eigen::Affine3d &transform_matrix, const std::string source_frame, const std::string target_frame)
    geometry_msgs::TransformStamped transform_to_robot = tf_buffer.lookupTransform(target_frame, source_frame,ros::Time::now(),ros::Duration(0.05));
    transform_matrix = tf2::transformToEigen(transform_to_robot);
    return true;
  catch (tf2::TransformException &ex){
    return false;
edit flag offensive delete link more



Wow I did not know you could get both the rotation and translation that succinctly into one matrix. For anyone unfamiliar with Eigen::Affine3D check out this link that I just found. I did not test the above code, but I like it.

JackB gravatar image JackB  ( 2020-10-04 08:44:59 -0500 )edit

Strictly speaking I'm look for an Isometry transform. But an Affine transform is a Super-Super-set of Isometry, so it is kind of true if you consider Affine transform with properties implied from Isometry.

I was actually looking for Python code. I found the solution already. fromTranslationRotation from tf.TransformerROS does the trick. But thx anyway.

antibus gravatar image antibus  ( 2020-10-04 13:32:44 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-10-02 11:25:19 -0500

Seen: 1,335 times

Last updated: Oct 04 '20