Rotation around a vector

Started by
2 comments, last by rpreller 16 years, 11 months ago
I'm a bit rusty on my rotations. I am given angles ox, oy, and oz that correspond to rotation around the x,y,and z axis, and that correspond to the direction a model is facing. I then need to rotate these rotations an arbitrary amount around a vector V(.707, 0, .707)(directly between the X and Z axes) that passes through the origin. What I had been doing was rotating an identity matrix around ox,oy, then oz to get the rotated x,y, and z axes. Then I rotated by 45 degrees around the Y axis to place V onto the X axis. Then I rotated by the arbitrary amount around the X axis. Then rotated by -45 degrees around the y axis to return the V to its place. Then taking this matrix, I did the math for the RxRyRz rotation by hand to get each element in terms of sin and cos thetax,thetay,and thetaz. This last step causes trouble since I get different results for x and z depending on which I solve for first. Any other way of doing this?
Advertisement
If I understand your problem correctly, it seems to me the simplest way to do what you're after would be to do as follows:

First rotate/translate the model so that its up-vector becomes the direction that vector_r is pointing towards and so that its position becomes vector_r's position--here, vector_r is the vector being rotated around. In other words, align the model's axis to vector_r's axis.

Second, rotate the model by the arbitrary amount.

Third, undo the rotations/translations performed in the first step, in the opposite order--meaning, maintain the rotation/translation amounts from step one, then use their negative values as if you were undoing that original step; must be opposite order or else you'll get funky results.

This should put your model into the desired position.
Quote:Original post by Omega147
Third, undo the rotations/translations performed in the first step, in the opposite order--meaning, maintain the rotation/translation amounts from step one, then use their negative values as if you were undoing that original step; must be opposite order or else you'll get funky results.

Yes, but you can take a shortcut here. Since aligning the axes involves only rotation, the transformation matrix is orthogonal. So rather than recomputing it with the angles negated, you can simply transpose, for the inverse. The calculation looks like this, in row-vector notation:

vnew = RaxisT . Rangle . Raxis . vold

where Raxis aligns the axes and Rangle rotates about the new axis.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Thanks for the replies. But, I forgot to mention I need to pull out the new ox,oy, and oz after putting vector_r back into place. Is this possible to do from the new matrix?

This topic is closed to new replies.

Advertisement