Extracting basis vectors from a quaternion

Started by
12 comments, last by alvaro 8 years, 5 months ago

A 3x3 matrix describes orientation and/or rotation with three (basis) vectors placed in the matrix vectors (or columns). Such a matrix can be converted to a quaternion and vice-versa. I'm wondering how to extract the three basis vectors from the quaternio, without converting the quaternion to a matrix. Is that even possible?

Advertisement

Since the matrix is the set of basis vectors you're looking for, converting the quaternion to a matrix or to basis vectors would have to be equivalent. If you get the matrix, you automatically have the basis vectors; if you have the basis vectors, you automatically have the matrix. A possible exception, of course, would be if you only need one or two of the basis vectors, but that's equivalent to a partial matrix conversion.

Yes but is there any other way? I mean, to sort of "read" the basis vectors straight from the quaternion? Or to put it this way. From a quaternion we can easily read the axis of rotation and the angle. I think that axis-angle and quaternion are equivalent beings. If so, then that means that from axis-angle we could also somewhat "read" the basis vectors. But I don't see how.

But my point is, you want the basis vectors, and the matrix consists exclusively of the basis vectors. No matter how you read the basis vectors from the quaternion, a matrix can always be created exactly the same way and you get the matrix for free when you have the basis vectors. There's no way to read the basis vectors that doesn't give you the matrix, because the collection of basis vectors is the matrix.

Of course Brother Bob is right, but perhaps this explanation might help you. A rotation is a mapping from R^3 to R^3. When a matrix is used to represent a rotation, its columns are the images of (1,0,0), (0,1,0) and (0,0,1). If you have the rotation represented as a quaternion, you can compute those columns the same way you would rotate any other vector (something like q * i * conj(q), q * j * conj(q) and q * k * conj(q)).

Okay... I think I get your point but still something bugs me.

Let's put it this way. We have axis-angle representation and want to get the basis-vectors (or matrix if you like). One of the basis vectors is the axis of rotation. How do I compute the other two vectors? The only information I have left is that these two vectors lie on the plane perpendicular to the axis of rotation. And of course I have the angle, which definitely is needed to get the second vector but I'm not sure how.

The axis of rotation is not a basis vector. This is only true if you are rotating about one of the principal axes, but not in general.

Just take each of the identity basis vectors (1, 0, 0), (0, 1, 0) and (0, 0, 1) and rotate them with the quaternion. This will give you a new set of basis vectors that should correspond to the columns in a rotation matrix.

Late but still - thanks :).

Thumbs up given.

Here the code to compute the forward, right and up vector from a quaternion :

CVector3 CQuaternion::ComputeForwardVector() const
{
  const float x2 = 2.0f * x;
  const float y2 = 2.0f * y;
  const float z2 = 2.0f * z;
  const float x2w = x2 * w;
  const float y2w = y2 * w;
  const float x2x = x2 * x;
  const float z2x = z2 * x;
  const float y2y = y2 * y;
  const float z2y = z2 * y;
  return CVector3( z2x + y2w, z2y - x2w, 1.0f - ( x2x + y2y ) );
}

CVector3 CQuaternion::ComputeRightVector() const
{
  const float y2 = 2.0f * y;
  const float z2 = 2.0f * z;
  const float y2w = y2 * w;
  const float z2w = z2 * w;
  const float y2x = y2 * x;
  const float z2x = z2 * x;
  const float y2y = y2 * y;
  const float z2z = z2 * z;
  return CVector3( 1.0f - ( y2y + z2z ), y2x + z2w, z2x - y2w );
}

CVector3 CQuaternion::ComputeUpVector() const
{
  const float x2 = 2.0f * x;
  const float y2 = 2.0f * y;
  const float z2 = 2.0f * z;
  const float x2w = x2 * w;
  const float z2w = z2 * w;
  const float x2x = x2 * x;
  const float y2x = y2 * x;
  const float z2y = z2 * y;
  const float z2z = z2 * z;
  return CVector3( y2x - z2w, 1.0f - ( x2x + z2z ), z2y + x2w );
}

This topic is closed to new replies.

Advertisement