Skip to main content
added 249 characters in body
Source Link
concept3d
  • 12.8k
  • 4
  • 46
  • 57

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 we are doneI think you don't need to multiply it with the inverse initial orientation.

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();

And we are done.

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.

Source Link
concept3d
  • 12.8k
  • 4
  • 46
  • 57

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();

And we are done.