# Axis Rotations

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

## Recommended Posts

Hi there, in my project i want to rotate around a local-axis. I've been spending quite a lot of time trying to figure out how i can convert the following angles:
X, Y, Z: 0, 0, 90
Along the orientation of the current angles of my object. Which is already rotated along is local axis. Simply setting it to the above changes it according to world angles, which isn't relative to the objects orientation. If anyone can help it is greatly appreciated, i need to set the exact current rotation and still maintain the objects current orientation. Thanks, Dan

##### Share on other sites
The following method actually rotates around the global equivalent of the chosen local axis.

To rotate around an "arbitrary" axis you can use the axis/angle representation of rotations. This can easily be converted into a quaternion or rotation matrix, whatever you use to handle rotations.

To get the correct axis you have to transform the local axis (e.g. [0 0 1] for the z axis) by the same rotation that has caused the current orientation of the model. If you have the belonging local-to-global transformation matrix at hand, then the transformation mentioned above simply picks the belonging row (if using row vectors) or column (if using column vectors), resp., from the basis of the matrix.

##### Share on other sites
Hi, thanks for your very informative answer, i'm having a bit of trouble understanding it, could you perhaps show me in pseudo code?

Thanks,
Dan

##### Share on other sites
Pseudo code is a bit problematic, because of the various possibilities.

Assumeing you have a transformation matrix at hand that is used as local-to-global transformation. Then the matrix desribes how the local co-ordinate frame is to be rotated and translated so that it is located in the world as desired (we ignore scaling here since it (a) makes the things more complex and (b) is seldom used). Looking at the matrix, you'll see a 3x3 sub-matrix, a position vector, and a 0 vector. If you use column vectors then the layout may look like
[ rxx ryx rzx tx ][ rxy ryy rzy ty ][ rxz ryz rzz tz ][  0   0   0   1 ]
(e.g. OpenGL), and if you use row vectors then the layout may look like
[ rxx rxy rxz 0 ][ ryx ryy ryz 0 ][ rzx rzy rzz 0 ][  tx  ty  tz 1 ]
(e.g. D3D). Other orders are possible, too. You haven't told us which version you use.

If you want to rotate around an axis that is e.g. [0 0 1] in the local space, then the same axis given in global space is
M * [0 0 1 0]T
for column vectors, resp.
[0 0 1 0] * M
for row vectors, where M is to be substituted with the matching matrix from above. If you really perform the multiplication, you will see that
[rzx rzy rzz] for local z
is the result for the given local axis (namely z). Similarly, you get
[rxx rxy rxz] for local x
[ryx ryy ryz] for local y

So the said 3x3 sub-matrix gives the global space equivalents of the local co-ordinate axes. You can pick out which axis you want and use it furthur for the axis/angle rotation.

For the coherences of the various rotation representations see e.g. here, and especially for conversion from axis/angle to matrix see e.g. here (you only need the part in-between "which can be expanded out to give the terms of the matrix components" and "This can be written as the sum of 3 matricies"). I hope those source is correct, but normally I've heard only good things about "euclideanspace".

1. 1
2. 2
frob
20
3. 3
Rutin
17
4. 4
5. 5

• 13
• 10
• 9
• 18
• 9
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007035

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!