# Converting a Matrix to Rotation Angles

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

## Recommended Posts

I have a D3DXMATRIX and I need to get the rotation in radians around the Y axis. Is this possible, and if so where can I get some information/code on how to do it? If this isn't a simple thing, is it possible to get the direction vector from a matrix? Thanks [Edited by - GremlinX on September 5, 2005 10:13:27 PM]

##### Share on other sites
Rotation around y axis:

Y(x)={(cos(x),0,-sin(x),0),(0,1,0,0),(sin(x),0,cos(x),0),(0,0,0,1)}

##### Share on other sites
Quote:
 I have a D3DXMATRIX and I need to get the rotation in radians around the Y axis. Is this possible, and if so where can I get some information/code on how to do it?
You can certainly extract Euler angles from a matrix, but you have to choose an appropriate order and write your code accordingly. I'm guessing though that you may not need anything that complicated. The matrix that you want to extract the y rotation from - how was it constructed in the first place?
Quote:
 If this isn't a simple thing, is it possible to get the direction vector from a matrix?
By direction vector, do you mean the 'forward' vector, i.e. the direction an object with that orientation is facing?

##### Share on other sites
The matrix is coming from a 3rd party physics engine, so I'm not sure how's it's constructed. However, when I get the 3rd party matrix I convert it to a D3DXMATRIX by just setting the values of the D3DXMATRIX structure... like _11, _12... etc using the values from the 3rd party matrix. Does this answer your question?

By direction vector, I meant forward vector, yes. If I can get the rotation around the Y axis from the matrix I won't need to worry about the forward vector though.

##### Share on other sites
It will probably be easiest to just extract the forward vector directly. Assuming the source matrix represents only rotation and translation, the basis vectors for the coordinate frame are stored in the first three rows, like this:

11 12 13
21 22 23
31 32 33

=

Xx Xy Xz
Yx Yy Yz
Zx Zy Zz

So if, say, z is forward, just create your forward vector from elements 31, 32 and 33.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×