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.0Thu, 03 Nov 2011 21:25:01 -0500Can z value in quaternion get negative?https://answers.ros.org/question/11790/can-z-value-in-quaternion-get-negative/I'm still learning kinematics like quaternion. The answer of [this QA page](http://answers.ros.org/question/740/quaternions-orientation-representation), which I thank the author for the complete explanation, describes as follows:
(x, y, z, w) = (0, 0, sin(theta/2), cos(theta/2))
That means I guess 0 < z < 1 (when 0 <= theta < 2pi). However, in the return value from `tf.TransformListener().lookupTransform` (in `C++`), z can often be negative. For example, using `turtleSim` on `RViz`, z value I see is -0.717892 when a turtle looks almost down or 6PM or 3pi/2. Am I wrong somewhere?Thu, 03 Nov 2011 12:47:25 -0500https://answers.ros.org/question/11790/can-z-value-in-quaternion-get-negative/Answer by roehling for <p>I'm still learning kinematics like quaternion. The answer of <a href="http://answers.ros.org/question/740/quaternions-orientation-representation">this QA page</a>, which I thank the author for the complete explanation, describes as follows:</p>
<pre><code>(x, y, z, w) = (0, 0, sin(theta/2), cos(theta/2))
</code></pre>
<p>That means I guess 0 < z < 1 (when 0 <= theta < 2pi). However, in the return value from <code>tf.TransformListener().lookupTransform</code> (in <code>C++</code>), z can often be negative. For example, using <code>turtleSim</code> on <code>RViz</code>, z value I see is -0.717892 when a turtle looks almost down or 6PM or 3pi/2. Am I wrong somewhere?</p>
https://answers.ros.org/question/11790/can-z-value-in-quaternion-get-negative/?answer=17465#post-id-17465If you have a rotation quaternion q=(x,y,z,w), then -q=(-x,-y,-z,-w) describes the same rotation, so you cannot rely on z (or any other component) being positive.
A rotation quaternion is essentially a rotation axis (x,y,z) and an amount of rotation w (I avoid the word angle because it's not an angle in the usual sense), scaled to unit length (|q|=1). If you change the sign of w, you reverse the rotation direction. The same thing happens if you mirror the rotation axis to (-x,-y,-z). So if you do both, these effects cancel each other out.
Thu, 03 Nov 2011 21:25:01 -0500https://answers.ros.org/question/11790/can-z-value-in-quaternion-get-negative/?answer=17465#post-id-17465