Getting Rotation X, Y, Z from D3DXMatrixRotationAxis()

Started by
2 comments, last by Tsus 11 years, 11 months ago
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"?
Advertisement
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 this.

Best regards!
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]

[background=rgb(250, 251, 252)]D3DXVECTOR3 axis;[/background]

[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]FLOAT angle;[/background]

[/font]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]I use those variables to get the rotation by using:[/background]

[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]D3DXMatrixRotationAxis(&rotation, &axis, angle);[/background]

[/font]

How can I get Pitch Yaw Roll from the two variables "[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]D3DXVECTOR3 axis;" and "[/background]

[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]FLOAT angle;[/background]

[/font]"?

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

This topic is closed to new replies.

Advertisement