Definition of terms:
It you want to consider the rotation only then the code for this is shown
here.
Alternatively if we want to consider the possibility that there is also a translation
from the centre, and that the rotation may not be about the centre but may be
about some arbitrary point, then we need to extend the notation as follows:
 A 3D vector has to be added to the quaternion so that together they can
specify the position and orientation.
 The matrix has to be increased from 3x3 to 4x4 so that it can specify the
position and orientation. (as explained
here).
Rotation about a point other than origin
Quaternions and 3x3 matrices alone can only represent rotations about the origin.
But if we include a 3D vector with the quaternion we can use this to represent
the point about which we are rotating. Also if we use a 4x4 matrix then this
can hold a translation (as explained
here) and therefore can specify a rotation about a point.
The following code generates a 3D vector (representing the centre of rotation)
from the 4x4 matrix. The theory is given
here.

= 1/det[m] * 
(m11  1)*m22  m12*m21 
m02*m21  m01*(m22  1) 
m01*m12  m02*(m11  1) 
m12*m20  m10*(m22  1) 
m00*(m22  1)  m02*m20 
m02*m10  (m00  1)*m12 
m10*m21  (m11  1)*m20 
m01*m20  (m00  1)*m21 
m00*(m11  1)  m01*m10 


This site may have errors. Don't use for critical systems.