Are there different conventions for representing rotations as quaternions? I am trying to understand how quaternions are represented as rotations, in particular how to convert from a quaternion representation to a rotation matrix. The following paper by Diebel gives an overview of many ways to represent rotations, including quaternions:
http://www.swarthmore.edu/NatSci/mzucker1/e27/diebel2006attitude.pdf
According to Diebel, a quaternion $a+bi+cj+dk$ corresponds to the following rotation matrix:
$\left( \begin{array}{ccc}
a^2+b^2-c^2-d^2 & 2bc+2ad & 2bd-2ac \\
2bc-2ad & a^2-b^2+c^2-d^2 & 2cd+2ab \\
2bd+2ac & 2cd-2ab & a^2-b^2-c^2+d^2 \end{array} \right)$
(This is equation 125 on page 15, just with the $q_0,q_1,q_2,q_3$ replaced with $a,b,c,d$ respectively.)
In contrast, on the Wikipedia page:
http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
the following matrix is given:
$\left( \begin{array}{ccc}
a^2+b^2-c^2-d^2 & 2bc-2ad & 2bd+2ac \\
2bc+2ad & a^2-b^2+c^2-d^2 & 2cd-2ab \\
2bd-2ac & 2cd+2ab & a^2-b^2-c^2+d^2 \end{array} \right)$
Note that this is not the same matrix as the one above (it is the transpose).
I have looked at some other references and I can find some that give the first matrix, and some that give the second matrix. For example, the following references agree with the matrix given by Diebel:
http://www.cs.princeton.edu/~gewang/projects/darth/stuff/quat_faq.html (question 54)
http://www.ladispe.polito.it/corsi/Meccatronica/02JHCOR/2011-12/Slides/Shuster_Pub_1993h_J_Repsurv_scan.pdf (equation 158)
(Note that some of these references use different names for the four quaternion components or put them with the scalar as the last instead of the first element; you can easily tell the difference in the two forms by seeing if the item in the first row, second column has a "+" or a "-" sign.)
But the following references agree with the matrix given by the Wikipedia article:
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/spicelib/q2m.html (under "Associating SPICE Quaternions with Rotation Matrices")
http://books.google.com/books?id=hiBFUv_FT0wC&printsec=frontcover&dq=game+programming+gems+volume+1&hl=en&sa=X&ei=LQ-IUZ7CLKmpyAG66IGIDA&ved=0CEAQ6AEwAQ#v=onepage&q=convert%20quaternion%20to%20rotation%20matrix&f=false
(page 202)

What is the cause of this difference? Since there are several references that use each of these two matrices, it seems unlikely that it is simply an error in one of the references. Are there different conventions for how to represent rotations by quaternions that would lead to this difference?
 A: This is a very old question, but none of the responses directly answer the question.
In short, YES, there are two different Quaternion conventions.  The original question even hints at the answer-- there is the JPL convention, used at parts of NASA, JPL, some spacecraft stuff, etc; and there is the original Hamiltonian convention used by almost everyone else.
For a discussion of how and why this happens, see the following article: https://arxiv.org/abs/1801.07478
This paper also describes the difference, and is generally an excellent reference for how Quaternions are used in certain navigation applications:
https://arxiv.org/abs/1711.02508
A: Found earlier answer How do you rotate a vector by a unit quaternion?
I will look for the place where I gave a really complete answer, but there are two versions for a very simple reason. You have a unit quaternion $\xi = a + b i + c j + d k.$ You have a vector in $\mathbb R^3,$ which is regarded as a "pure" quaternion $\alpha = x i + y j + z k.$ Finally, the is the conjugate $\bar{\xi} = a - b i - c j - d k.$ Unit means $a^2 + b^2 + c^2 + d^2 =1,$ so $\xi  \bar{\xi} =   \bar{\xi} \xi   = 1.$
The two linear mappings you are finding are:
$$  \xi \alpha \bar{\xi}  $$ OR
$$   \bar{\xi} \alpha \xi. $$
Either recipe works, for the simple reason that the "real part" of any quaternion product $\beta \gamma$ is the same as the real part of $\gamma \beta.$
So, given that the real part of $\alpha$ is $0,$ the real part of $  ( \bar{\xi} \alpha ) \xi  $ is the same as the real part of $ \xi ( \bar{\xi} \alpha )  $ is the same as the real part of $ (\xi  \bar{\xi}) \alpha   $ is the same as the real part of $  \alpha   $ which is $0.$ So the result is another vector, another pure quaternion.
A: I have looked more carefully at these references and I have figured out what the difference is. The difference is that the Diebel paper and the references that agree with it define the quaternion as the rotation of the coordinate system, which is the opposite direction of the rotation of the vector in the system. For instance, if I have two coordinate systems A and B, and system B is system A rotated 30 degrees counterclockwise around the Z axis, then if I have a vector in system A that I want to express in system B, I have to rotate the vector 30 degrees clockwise around the Z axis. A diagram that shows this is in figure 1 of Diebel's paper. This explains why there is the transposition discrepancy (because the transpose of a rotation matrix is its inverse). All the references use the form with the vectors being column vectors, and use the $\xi \alpha \bar{\xi}$ form.
A: What you are looking at is the translation of a quaternion rotation into a rotation matrix, that is, a $3\times 3$ matrix which you multiply vectors on a side to perform the rotation. There aren't really rotations by quaternions in that expression, just the ordinary representation of a rotation by a matrix.
The reason that your first matrix is the transpose of the other is simple: in one case they are following a convention of multiplying vectors on the right, and in the other case they are multiplying vectors on the left.
To make an analogy with two dimensions, 
$$
\begin{bmatrix}\cos(x)&-\sin(x)\\\sin(x)&\cos(x)\end{bmatrix}
$$
is the rotation matrix if vectors are column vectors on the right, and 
$$
\begin{bmatrix}\cos(x)&\sin(x)\\-\sin(x)&\cos(x)\end{bmatrix}
$$
is the matrix for the same rotation if the vectors are row vectors on the left.

The main way of representing 3-d rotations in terms of quaternions is this: you view the space of quaternions with zero real part as 3-space, and conjugate with the unit quaternions to produce rotations. Specifically, if $h$ is a unit quaternion pointing along the axis of rotation, and $\theta$ is the angle of rotation (measured right-handedly with respect to $h$), then $\cos(\theta)
+h\sin(\theta)=q$ is a unit quaternion, and $v\mapsto qvq^{-1}$ produces the rotation.
There are some pretty good descriptions here: https://math.stackexchange.com/a/331547/29335
and here: https://math.stackexchange.com/a/331203/29335
