views:

39

answers:

2

Given an object quaternion q, and basis vectors vx, vy, vz forming a 3D space, how can I check whether the quaternion is parallel or perpendicular to all of the basis vectors?

For example, I have basis vectors: vx = (0.447410, 0, -0.894329) vy = (0, 1, 0) vz = (0.894329, 0, 0.447410)

and quaternion q(w,x,y,z) = (-0.973224, 0, -0.229860, 0)

I know the quaternion is perpendicular or parallel (or anti-parallel) to all of the basis vectors but how can I actually calculate it?

Another example, q(w,x,y,z) = (0.823991, 0, 0.566602, 0)

This is NOT perpendicular or parallel (or anti-parallel) to all of the basis vectors.

A: 

A note about terminology: Strictly speaking, it's not clear exactly what you mean by "the quaternion is perpendicular to one of the basis vectors"...quaternions and 3-D vectors are not comparable that way. However, quaternions can be thought of as a representation of a rotation axis (3-D vector) and a scalar rotation angle, so I'll assume you want to know if the rotation axis is perpendicular to one of the basis vectors.

For unit quaternions considered as 3-D rotations, the convention is that for q=(w,x,y,z), x, y, and z form a 3-D vector (let's call it qv) along the rotation axis, and w=cos(alpha/2) represents the rotation angle alpha.

In your case, qv = (x,y,z) = (0, -0.229860, 0). vx, vy, and vz are all unit vectors, so it's easier to see what's going on if you normalize qv to also be a unit vector. Divide through by its length (0.229860) to get qv_unit = (0, -1, 0). To find the angles between qv_unit and vx, vy, and vz, use the dot product:

For unit vectors v1=(a, b, c) and v2=(d, e, f):

cos(theta) = v1 dot v2 = ad + be + cf

qv_unit dot vx = 0*.447410 + -1*0 + 0*-894329 = 0 = cos(theta), so theta=pi/2, and we see that qv_unit is perpendicular to vx.

qv_unit dot vy = 0*0 + -1*1 + 0*0 = -1 = cos(theta), so theta=pi, and qv_unit is anti-parallel to vy.

qv_unit dot vz = 0*.894329 + -1*0 + 0*.447410 = 0 = cos(theta), so theta=pi/2, and qv_unit is also perpendicular to vz.

Jim Lewis
This happens to work in that particular case but what if the quaternion is: q(w,x,y,z) = (0.823991, 0, 0.566602, 0)? I know the rotation is NOT perpendicular to any of the axes. Although the two dot products give 0.
Quaternional
@Quaternional: Your question says you "know the quaternion is perpendicular to one of the basis vectors", but now you say"the rotation is NOT perpendicular to any of the axes". So I have no idea what you're really asking...please clarify. Where are the basis vectors and quaternion coming from? What is the context?
Jim Lewis
Actually, I want to know whether the quaternion rotation is perpendicular or parallel to ALL of the axes. Sorry about the confusion.
Quaternional
@Quaternional: If the rotation axis is parallel or anti-parallel to one basis vector, it must be perpendicular to the others if vx, vy, vz are orthogonal. At any rate, everything you need to know is in the dot products, and I assure you it works for the general case as long as q=[w,x,y,z] has the interpretation I described in my answer.
Jim Lewis
The quaternion represents an object's rotation. I can see with my eyes that the object's rotation is parallel or perpendicular to all of the basis vectors when the quaternion is (-0.973224, 0, -0.229860, 0) but it is NOT when the quaternion is (0.823991, 0, 0.566602, 0). You cannot just ignore the w component!
Quaternional
@Quaternional: Then the conventions you're using must differ from what I described. Maybe if you drew a picture?
Jim Lewis
Are you really saying that the w component does not affect to object's rotation?
Quaternional
@Quat: I'm saying that the w component does not affect the _axis_ of rotation. We seem to be visualizing this differently...I don't know what else I can say.
Jim Lewis
Of course it does not affect the axis of rotation but it affects the actual rotation. And I am interested in that rotation.
Quaternional
A: 

I solved this by converting the quaternion to matrix. Taking the basis vectors from the matrix, and calculating the dot products between the matrix basis vectors and the original basis vectors. If they all are 0 or 1, the quaternion is parallel or perpendicular to the original basis vectors.

Quaternional
OK, I think I see what the misunderstanding was. You wanted to know if the result of rotating the original x, y, z basis vectors, using quaternion q, gave results rx, ry, rz that were parallel or perpendicular to your vx, vy, vz. But you asked about q being parallel/perpendicular to vx, vy, vz -- which isn't really a well-defined concept, and I guessed incorrectly about what you meant by that. At any rate, I'm glad your problem is solved, and I hope the discussion was helpful.
Jim Lewis