问题
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)?
回答1:
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.
来源:https://stackoverflow.com/questions/3524433/quaternion-and-three-axes