hasdf
hasdf

Reputation: 729

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 vectors (vx, vy, vz)?

Upvotes: 5

Views: 1457

Answers (1)

Jim Lewis
Jim Lewis

Reputation: 45115

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.

Upvotes: 4

Related Questions