# Getting Rotation X, Y, Z from D3DXMatrixRotationAxis()

## Recommended Posts

I have the following lines:
D3DXVECTOR3 axis;
FLOAT angle;
D3DXMatrixRotationAxis(&rotation, &axis, angle);

How can I get the rotation Pitch, Yaw and Roll from the two variables "axis" and "angle"?

##### Share on other sites
Hi!

Extracting those angles is a rather laborious procedure, since you have to deal with singularities. What do you need the angles for?
The following is from John J. Craig: Introduction to Robotics. Page 47f, Addison-Wesley Publishing Company, Reading, Mass. 1989, ISBN 0-201-09528-9.

Given a rotation matrix R:
[formula]R=\begin{pmatrix}r_{11} & r_{12} & r_{13}\\r_{21} & r_{22} & r_{23}\\r_{31} & r_{32} & r_{33}\end{pmatrix}[/formula]

The angles are:
[formula]\beta = Atan2\left(-r_{31},\sqrt{r_{11}^2+r_{21}^2}\right)[/formula]
[formula]\alpha = Atan2\left(\frac{r_{21}}{cos(\beta)},\frac{r_{11}}{cos(\beta)}\right)[/formula]
[formula]\gamma = Atan2\left(\frac{r_{32}}{cos(\beta)},\frac{r_{33}}{cos(\beta)}\right)[/formula]
With [formula]\alpha[/formula] being roll, [formula]\beta[/formula] being pitch and [formula]\gamma[/formula] being yaw.

Now the singularities:
If [formula]\beta=+\pi/2[/formula] then
[formula]\alpha=0[/formula]
[formula]\gamma=Atan2(r_{12},r_{22})[/formula]

If [formula]\beta=-\pi/2[/formula] then
[formula]\alpha=0[/formula]
[formula]\gamma=-Atan2(r_{12},r_{22})[/formula]

Or you can look at [url="http://en.wikipedia.org/wiki/Yaw,_pitch,_and_roll#Angles_of_a_given_frame:_Geometric_derivation"]this[/url].

Best regards! Edited by Tsus

##### Share on other sites
I think you misunderstood my question, I don't want to extract Pitch Yaw Roll from the rotation matrix, rather I have the following two variables:
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]D3DXVECTOR3 axis;[/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]FLOAT angle;[/background][/left][/size][/font][/color]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]I use those variables to get the rotation by using:[/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]D3DXMatrixRotationAxis(&rotation, &axis, angle);[/background][/left][/size][/font][/color]

How can I get Pitch Yaw Roll from the two variables "[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]D3DXVECTOR3 axis;" and "[/background][/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]FLOAT angle;[/background][/left][/size][/font][/color]"?

##### Share on other sites
Sorry, I forgot to mention. I'd have used the matrix as some sort of detour to get to the angles.
I guess the conversion from (axis, angle) to (yaw, pitch, roll) is probably a little more complicated.
So instead, I’d suggest to go from (axis, angle) to (rotation matrix) to (yaw, pitch, roll).

So, first, create the 4x4 matrix with D3DXMatrixRotationAxis(&rotation, &axis, angle); as you already had.
Then, only consider the top-left 3x3 matrix as only this part contains the rotation part.

Best regards

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982384

• 10
• 9
• 15
• 24
• 11