views:

75

answers:

1

Given a quaternion q, and three 3D vectors (vx, vy, vz) which form coordinate axes, which can be oriented in arbitrary direction, but are all perpendicular to each other, thus forming a 3d space.

How can I check if the quaternion q is rotated to the same direction (or opposite direction) as some of the 3D vectors (vx, vy, vz)?

+3  A: 

If q = (w,x,y,z), where w is the "scalar part", and qv=(x,y,z) is the "vector part", then you can calculate the angle between qv and each of the basis vectors vx, vy, vz using the dot product.

cos(theta) = (qv dot vx) / ( |qv| * |vx|)

If cos(theta) is +1, the rotation axis of q is parallel to that basis vector.

cos(theta) = -1 implies that they are anti-parallel.

Jim Lewis
Hmm... This is ignoring totally the "w" component of the quaternion. Is this correct?
hasdf
@qutern: That's right...I hope I didn't misunderstand your question! If you normalize q to a unit quaternion, then w = cos(alpha/2) gives the rotation angle alpha, and (x,y,z) is a vector that lies on the rotation axis. I assume you were asking how to find out if the rotation axis (x,y,z) is parallel to one of the basis vectors vx, vy, vz. If so, w is not needed for that calculation.
Jim Lewis