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?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
What is the python tf API to rotate a vector by a quaternion to get another vector?
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):
# comment this out if v1 doesn't need to be a unit vector
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]
This answer is concise, matches the code above: https://gamedev.stackexchange.com/que...
Pre-multiply the vector with q and post-multiply it with the conjugate q*
There's a copy of transformations.py embedded inside tf for linear math operations.
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.
Asked: 2014-10-28 17:58:31 -0600
Seen: 11,369 times
Last updated: Nov 11 '21
what are quaternions and how can I use them?
What is the difference between geometry and tf quaternions?
rosbag play & tf static_transform_publisher
Corrected Odometry from GMapping / Karto?
How to synchronize tfMessage and Image messages?
gazebo pr2 launch success but with tf errors
No transform from [anything] to [/base_link]