Re: [Algorithms] Rotation about arbitrary axis
Brought to you by:
vexxed72
From: Ron L. <ro...@do...> - 2000-08-21 18:02:50
|
Pierre Terdiman wrote > > Since I needed a piece of code to do that I searched the web and found: >...... > I used the final matrix at the bottom of the page, but it seems to fail when > the arbitrary axis actually is the Z axis. The third column gets erased > where it should at least contain a 1. This is obvious when looking at the > provided matrix, since the third column of the third row depends on the > rotation angle - and of course if the input axis already is the Z axis, it > shouldn't. > I haven't checked this out, but it must be wrong because it is perfectly possible to write down the matrix in a form such that it applies to any ARBITRARY axis, including the z-axis. > Now, it sounds normal regarding the underlying method (mapping the rotation > axis to Z, etc). But I wonder whether there's an easy way to perform a real > arbitrary rotation about any arbitrary axis without using different code > paths according to the input axis. > > I think it can probably be done by introducing quaternions or better, > angle-axis, in the story. But err.... maybe there's something simpler. Absolutely. You can do it entirely in terms of elementary vector geometry, which I certainly regard as simpler, or at least more elemenary than quaternions. It is an instructive exercise in elementary vector geometry to derive the following formula. Let A be a unit vector that points along the axis of rotation, let ang be the angle of rotation, and let V be any vector. The result of rotating V through angle ang about axis A is the vector V' = cos(ang)V + (1-cos(ang)) (A dot V) A + sin(ang) A cross V Notice that this is a vector formula. You can apply it directly to rotate any given vector V. Or if you want the matrix of this rotation with respect to any given coordinate system, simply express A in that coordinate system and successively substitute (1, 0, 0), (0, 1, 0), (0, 0,1) for V, and the nine elements of the three values you get for V', naturally, form the elements of the 3x3 rotation matrix. Whether you arrange these three V' vectors in rows or columns depends on which matrix convention you are using. Notice how esthetically satisfying is this vector formula: it expresses the result of the rotation in terms of V, A, and the simplest vector that can be constructed from V and A that is (in general) linearly independent of V and A, namely A cross V. It uses only the elementary vector operations of vector addition, multiplication by a scalar, dot and cross product, and it uses all of them. As for the derivation of this vector formula for rotation about an arbitrary axis, start by resolving V into components parallel and perpendicular to A. Clearly, rotation preserves vector sums so V' must be the sum of the images of the components under the rotation. The rotation of the perpendicular component is rotation in a plane, which you know how to do from elementary analytic gometry, You need to put all that together with some trig identities, and, (this is the trickiest part of the derivation), the following identity from elementary vector analysis, which you will find in your calculus book A cross (B cross C) = (A dot C)B - (A dot B)C (correct up to a sign that I can never remember). (You can find the derivation of the vector rotation spelled out in Goldstein's "Classical Mechanics". Also pay attention that there is a sign ambiguity of the sense of A coupled with the sign of ang and also the handedness of your cross product rule. The same ambiguity exists, of course, in any quaternion formulation). |