ROS Answers: Open Source Q&A Forum - RSS feedhttps://answers.ros.org/questions/Open source question and answer forum written in Python and DjangoenROS Answers is licensed under Creative Commons Attribution 3.0Fri, 15 Jun 2012 06:30:02 -0500how to construct a vector from quaternionhttps://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/Messages like Pose or PoseStamped have a orientation which is a quaternion. I would like to construct a vector3 of length 1 facing in the direction of the orientation from the quaternion. Is there a helper function in tf to acomplish this?
Thanks! Thu, 14 Jun 2012 04:05:27 -0500https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/Answer by Lorenz for <p>Messages like Pose or PoseStamped have a orientation which is a quaternion. I would like to construct a vector3 of length 1 facing in the direction of the orientation from the quaternion. Is there a helper function in tf to acomplish this?</p>
<p>Thanks! </p>
https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?answer=36520#post-id-36520When using the TF library, you can use the method tf::quatRotate to rotate your vector by the rotation represented by the quaternion. E.g. the following code rotates your vector by 180 degrees around the x axis:
tf::Quaternion rotation(1, 0, 0, 0);
tf::Vector3 vector(0, 1, 0);
tf::Vector3 rotated_vector = tf::quatRotate(rotation, vector);
Don't forget to include `tf/tf.h`.
Thu, 14 Jun 2012 04:55:14 -0500https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?answer=36520#post-id-36520Comment by blejzzz for <p>When using the TF library, you can use the method tf::quatRotate to rotate your vector by the rotation represented by the quaternion. E.g. the following code rotates your vector by 180 degrees around the x axis:</p>
<pre><code>tf::Quaternion rotation(1, 0, 0, 0);
tf::Vector3 vector(0, 1, 0);
tf::Vector3 rotated_vector = tf::quatRotate(rotation, vector);
</code></pre>
<p>Don't forget to include <code>tf/tf.h</code>.</p>
https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36522#post-id-36522so for instance if i set a goal in rviz and use your code (and replace the values of rotation with the goal orientation) and construct a new point like so: goal.position + rotatedVector; it will result in a point 1 meter forward in the goal direction/orientation?Thu, 14 Jun 2012 05:25:41 -0500https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36522#post-id-36522Comment by Lorenz for <p>When using the TF library, you can use the method tf::quatRotate to rotate your vector by the rotation represented by the quaternion. E.g. the following code rotates your vector by 180 degrees around the x axis:</p>
<pre><code>tf::Quaternion rotation(1, 0, 0, 0);
tf::Vector3 vector(0, 1, 0);
tf::Vector3 rotated_vector = tf::quatRotate(rotation, vector);
</code></pre>
<p>Don't forget to include <code>tf/tf.h</code>.</p>
https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36524#post-id-36524Yes. I think so. Alternatively, you can convert your goal to a tf::Stamped<tf::Pose> and multiply it with another tf::Pose with origin 1 0 0 and rotation 0 0 0 1. Same maths but less code. Also see for convertion functions: http://ros.org/doc/fuerte/api/tf/html/c++/transform__datatypes_8h.htmlThu, 14 Jun 2012 05:35:34 -0500https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36524#post-id-36524Comment by blejzzz for <p>When using the TF library, you can use the method tf::quatRotate to rotate your vector by the rotation represented by the quaternion. E.g. the following code rotates your vector by 180 degrees around the x axis:</p>
<pre><code>tf::Quaternion rotation(1, 0, 0, 0);
tf::Vector3 vector(0, 1, 0);
tf::Vector3 rotated_vector = tf::quatRotate(rotation, vector);
</code></pre>
<p>Don't forget to include <code>tf/tf.h</code>.</p>
https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36604#post-id-36604it works. thanks alot! Just one note in electric quatRotate isnt in tf namespace it is in btQuaternion.h.Fri, 15 Jun 2012 06:30:02 -0500https://answers.ros.org/question/36517/how-to-construct-a-vector-from-quaternion/?comment=36604#post-id-36604