# Measuring rotation about an axis

I need to measure how much a rotation $q$ has been rotated about a given axis $\hat{a}$. $q$ in my case is a quaternion but it could be any sort of 3d rotation and I know its original orientation.

Given $q$ and an axis $\hat{a}$ is it possible to determine its relative rotation about $\hat{a}$? The only solution I Thought of so far was to pick a parallel vector to $\hat{a}$ and after the rotation project onto the plane of the axis and take the dot product with the parallel vector to determine the angle. Unfortunately, that has issues with gimbal lock. I could do a conditional to see if its projection gives a zero length vector on the plane and then pick another axis but I feel like there should be a closed form solution of the problem.

Any ideas? Thanks!

-
What you're asking for does not quite seem to make sense as written. If your goal is to decompose a rotation into a number of rotations about fixed axes, try searching for "Euler angles" -- but you can't do such a decomposition one axis at a time. –  Henning Makholm Mar 18 '12 at 22:42
Let me give a physical example,Imagine you had a bolt and a special wrench. The wrench when attached can be rotated in any angle so you can get a good grip on it, however, when you turn it about the axis of the bolt (or twist if its parallel to the bolt) then the skrew twists. How would you determine how much the skrew has been twisted given the original orientation of the wrench and the new orientation. –  coderdave Mar 18 '12 at 23:10
Then what you want is certainly an Euler-angle decomposition with the length axis of the bolt as the principal axis. –  Henning Makholm Mar 19 '12 at 0:04