1
\$\begingroup\$

How do I obtain the relative orientation given two orientations (represented by quaternions q0 and q1)?

\$\endgroup\$
  • \$\begingroup\$ not sure what you are asking here, since you are not telling how did you calculate the quaternion in the first place. but my answer here might be related gamedev.stackexchange.com/questions/67199/… and btw you are mixing euler angles with quaternions which is sth I also addressed in the answer. \$\endgroup\$ – concept3d Jan 1 '14 at 23:09
  • \$\begingroup\$ which API are you using? it is supposed to be stated in the documentation of how do you interpret orientation. \$\endgroup\$ – concept3d Jan 1 '14 at 23:37
  • \$\begingroup\$ from what I understand you can't extract euler angles in the traditional sense. Try converting the quaternion to a matrix and there is a way of analyzing that matrix to extract the euler angles which may not work. But TBH I feel you are asking the wrong question. why do you want to extract pitch in the first place ? \$\endgroup\$ – concept3d Jan 1 '14 at 23:48
1
\$\begingroup\$

Quaternion is another representation of axis angle. The solution is to create a new quaternion from the original quaternion that only has the needed components.

An axis angle representation can be converted to a quaternion using the following formula

q[0] = cos(R/2);
q[1] = sin(R/2)*x;
q[2] = sin(R/2)*y;
q[3] = sin(R/2)*z;

Where R is the angle in radians, and (x,y,z) represents the axis, and quaternion is (R,x,y,z).

So in order to create a new quaternion with only the pitch component you just zero out the other components and normalize the quaternion:

Quaternion q; // this is your original quaternion
q.x = 0.0;
q.z = 0.0;
q.Normalize();

Edit based on your update:

Sensors AFAIK calculate orientation relative to gravity, in other words Y (or Z) is the direction of the gravity. You need take that into consideration. And I think you don't need to multiply it with the inverse initial orientation.

\$\endgroup\$
  • \$\begingroup\$ This works great if I know that the motion is pitch. In general, that is unknown. \$\endgroup\$ – ilp Jan 2 '14 at 0:32
  • \$\begingroup\$ @ilp well, what you can do, is extract the component with the highest contribution to the rotation and use that. So instead of taking a fixed axis. Use the one with the highest contribution and zero out the others. \$\endgroup\$ – concept3d Jan 2 '14 at 0:35
  • \$\begingroup\$ @ilp at this point I can't answer your question, because I don't know the neccessary details :-) maybe you should edit the question and give it a context so we are able to help. \$\endgroup\$ – concept3d Jan 2 '14 at 0:43
  • \$\begingroup\$ @ilp edited the answer. \$\endgroup\$ – concept3d Jan 2 '14 at 1:12
0
\$\begingroup\$

The relative orientation is obtained simply by division:

q = q0 / q1

Or, if division is not available:

q = q0 * inverse(q1)

Note that since the quaternions used to represent rotations are unit quaternions, the inverse of q1 is simply its conjugate q1*, and is obtained by flipping the sign of x, y, z but not w.

\$\endgroup\$
  • \$\begingroup\$ if you checked the edits, he is already doing that q = q0 * inverse(q1), so am not particularly sure what he is trying to do. \$\endgroup\$ – concept3d Jan 2 '14 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.