开发者

Math for a high-quality Quaternion equivalent to matrix transformation [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

I'm interested in implementing a clean solution providing an alternative to 4x4 matrices for 3D transformation. Quaternions provide the equivalent of rotation, but no translation. Therefore, in addition to a Quaternion, you need an additional vector of translations (tx,ty,tz). I have always seen it stated that you need 12 values for the matrix representation, and only 7 for the quaternion-based representation.

What I don't understand is how to manipulate the translation values.

For rotation of a quaternion, no problem.

For a vector v, an axis vector x, and an angle a:

q = cos(a/2) + x sin(a/2)

To rotate the vector:

v' = qvq^-1

For multiple rotations, you can apply the transformations to the quaternion, and only when you have the final rotation do you have to apply it to the data. This is why matrix transformation is so nice in 3d graphics systems.

Ok, so now if translation enters into it, what do I do?

A given vector transformation is:

T = (tx,ty,tz)
v' = qvq^-1 + T

If I want to 开发者_如何学Pythonapply a rotation and translation operation to this, I would have to modify T and q. What should the result be?


Well, I don't know quaterions from Adam, but I do know that these are linear operations. So if you have one (rotate,translate) operation (q,T), and another (r,U), and you apply them in that order, the total transformation is:

r(qvq^-1 + T)r^-1 + U

Distribute r over the stuff in parens from the left:

(rqvq^-1 + rT)r^-1 + U

Then distribute r^-1 from the right:

rqvq^-1r^-1 + rTr^-1 + U

And re-arrange slightly:

= (rq)v((rq)^-1) + (rTr^-1 + U)

So this composition is equivalent to a single (rotate,translate) of (rq, rTr^-1 + U). And if you can compose 2 of them, you can compose N of them.

Does this help at all, or did I misunderstand the question?


In addition to Nemo's answer, if you really want a completely mathematical construct to represent a rotation together with a translation, you can use dual quaternions, although the mathematics might be a bit overkill, they got some nice properties. Essentially the are just two quaternions (a real and a dual part) interpreted in a special way. The nice thing is, that by the usual operations defined on them (multiplication, conjugate, qvq*, ...) you can just compute with rigid body transformations in a mathematically clean way, like with normal quaternions for rotations.

The Wikipedia article might not be that descriptive, but Ladislav Kavan uses them for skinning (where they really play their advantages over matrices) and in his paper he gives a good explanation.


A few issue with quaternions you need to be aware of:

  • The quaternion inverse is much simpler to calculate you stick with unit quaternions. The inverse of a unit quaternion is simply the conjugate, which is trivial to calculate. The inverse of a general quaternion requires four multiplies, a square root, and a divide: Something you don't want to do if you need speed.

  • Transforming a vector via a quaternion involves several more multiplies and adds than transforming via a matrix. If you need to make the same transformation multiple times you might want to maintain both the quaternion and the corresponding transformation matrix and use whichever is faster/more precise given the operation at hand.

  • Unit quaternions are a double cover of the group SO(3). Negate all elements of a quaternion and you get the same transformation.

  • Left versus right quaternions. There are two ways to transform a vector v with a quaternion q: qvq* and q*vq. These two schemes differ only in whether the unconjugated quaternion go on the left of the vector (left quaternions) or on the right (right quaterions). Both representations are perfectly valid. Pick one, but do beware that no matter which one you pick, someone else will use the other. This can make exchanging quaternions with some other package problematic (but not if you know that this ambiguity exists).

  • Transformation versus rotation. This issue of transformation versus rotation also arises with 3x3 matrices. (I am not talking about that 4x4 mathematical travesty that some people use.) Suppose you have a sheet of white graph paper and a transparency sheet with graph lines printed on it. Align the two so the graph lines overlap. Now rotate the transparency. This physical rotation can be described mathematically in terms of a rotation matrix or a rotation quaternion (or a slew of other representations; there are many charts on SO(3).) Now imagine there is a dot somewhere on the white sheet of paper. You can read off the position of this dot in terms of the white sheet's coordinate system or in terms of the transparency's coordinate system. The transformation from white sheet coordinates to transparency coordinates is a transformation (not a rotation). Transformation and rotation are closely related concepts; one is the transpose (or conjugate) of the other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜