# how to get rotation matrix from quaternion in python

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

how to get rotation matrix from quaternion in python

add a comment

1

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.

1

`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.

-1

pretty simple to code start here

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

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

Seen: **161 times**

Last updated: **May 31**

tf2 - where's quaternion_from_euler gone?

General problem with Service Server / Client (python)

Velodyne VLP16 frequency too low

Defining joint bounds for moveit

import in rosgraph/masterapi.py failing

Run RViz with configuration file from .launch file

static transformation publisher

ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.