Quaternion and three axes
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 vector开发者_JS百科s (vx, vy, vz)?
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.
精彩评论