# How to rotate vector by quaternion in python

What is the python tf API to rotate a vector by a quaternion to get another vector?

How to rotate vector by quaternion in python

What is the python tf API to rotate a vector by a quaternion to get another vector?

add a comment

3

There's a copy of transformations.py embedded inside tf for linear math operations.

1

1

Hi robzz, Have a closer look at the link that tfoote posted; the comments give an explanation and examples.

Yep, that's the ticket. Have a look here to get an idea of /why/ this works.

8

Okay, based on @tfoote's response and this answer to a related question, I *think* this does the job:

```
# rotate vector v1 by quaternion q1
def qv_mult(q1, v1):
v1 = tf.transformations.unit_vector(v1)
q2 = list(v1)
q2.append(0.0)
return tf.transformations.quaternion_multiply(
tf.transformations.quaternion_multiply(q1, q2),
tf.transformations.quaternion_conjugate(q1)
)[:3]
```

1

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

Asked: ** 2014-10-28 17:58:31 -0500 **

Seen: **6,630 times**

Last updated: **Oct 28 '14**

what are quaternions and how can I use them?

turning turtlebot a set number of degrees

p3dx urdf model isn't shown correctly in rviz

robot_localization does not produce odom->base_link transform

What transforms do I need to publish in order to make robot_pose_ekf and slam_gmapping happy?

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.