Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direction vector from Quaternion?

I have a Quaternion representing the rotation of a 3D characters upper arm. I also have a line that is supposed to represent the new position of that characters' arm. That lines position is given by two 3D points.

This is the only data I have, and Im trying to call a method in a 3D package (Digital Rune) that takes 2 direction vectors and returns the Quaternion representing the rotation needed to move the arm to the new position.

The problem is that I see some odd behavior, as if the axes are mixed up and it is just generally not behaving. Also, the Quaternion object (which is from the 3D package) representing the 3D guys' arm has W, X, Y and Z. Do X,Y and Z represent the direction vector? Because that's what I need to call the function properly. I have been using this along with my calculated direction vector from the endpoints of my line, but as I said it looks funny.

If the X,Y and Z are not a direction vector, how to convert from a Quaternion to the two endpoints so I can calculate the direction vector?

like image 623
Nicros Avatar asked Dec 22 '11 23:12

Nicros


1 Answers

In your context (and in most computer graphics contexts), a quaternion is used to represent a rotation. You don't want to use the X, Y and Z directly; instead (as described in the above-linked tutorial), you use it to generate a rotation matrix. You should then use the rotation matrix like any other 3D transformation matrix; it will rotate points around the origin as described by the quaternion it came from.

The quaternion's X, Y, and Z do represent the axis of the rotation, but the quaternion also encodes the magnitude of the rotation, in a not-particularly-straightforward way. If your package includes functions that return a quaternion, it should also include functions that turn its quaternions into rotation matrices; you should use the packaged function if possible (because it ought to be using the same conventions as the method that produced them).

After reading up on quaternions and transformation matrices, you should reread the documentation of the function in question carefully, to make sure you're providing the right kinds of arguments, and to make sure that you're using the results in the right way (it's easy enough to screw it up, even when you're familiar with the math...).

like image 114
comingstorm Avatar answered Sep 19 '22 02:09

comingstorm