# How are these formulas for Quaternion -> Rotation Matrix related?

I'm trying to write a program to convert a quaternion to a rotation matrix. One source I found is: http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Conversion_to_and_from_the_matrix_representation

I am pretty sure that for the variable names, a=w, b=x, c=y, d=z, but that doesn't explain the fact that the two matrices look completely different. When I try to implement them, the second one looks right whereas the first one looks wrong. What is the difference between the two matrices?

• You may be more likely to get an answer if you make your question more self-contained by including the matrices you are asking about. Feb 21 '13 at 4:02

There are two differences. One is that the second matrix is $4\times4$ because it represents an affine transform, which can accommodate translations but in this case doesn't; the fourth component doesn't interact with the other three and you can just ignore it for purposes of comparing the two matrices.
The second difference is in the diagonal elements. To see that the diagonal elements are in fact equal, note that the first answer assumes and the second answer ensures that $a^2+b^2+c^2+d^2=1$. Thus $a^2+b^2=1-c^2-d^2$, which you can use to transform the first diagonal elements into each other, and likewise with the other two pairings of the four variables for the other two diagonal elements.