# Rotation around a vector

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by Omega147Third, 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.

##### Share on other sites
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?

• 18
• 11
• 16
• 9
• 51
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999790
×