# Can z value in quaternion get negative?

I'm still learning kinematics like quaternion. The answer of this QA page, 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?

edit retag close merge delete

Sort by » oldest newest most voted

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

more