   how to compute this quaternion
  given two quaternions P and Q representing orientations, i would like to compute a  quaternion D such that:D * P = QHowever I would like the axis of rotation of D to be fixed (for my purpose the desired axis of rotation is the y axis), so the problem is one of minimising the difference between D*P and Q. I feel there should be a close form solution but my calculus is not that good.any help will be appreciated.   
  Think of this in terms of unit-length vectors.  Let Q*Inverse(P) = w + x*i + y*j + z*k, where (w,x,y,z) is a known unit-length vector.  Let D = cos(t/2) + sin(t/2) * (u0*i + u1*j + u2*k), where (u0,u1,u2) is a unit-length vector that you require to be constant.  The variable is the angle of rotation t.  D is a unit-length vector (cos(t/2),u0*sin(t/2),u1*sin(t/2),u2*sin(t/2)).As 4-tuples, you want to choose t so that D is a close to Q*Inverse(P) as possible on the 4D unit hypersphere.  Do this by choosing t to maximize the dot product of D and Q*Inverse(P), which minimizes the angle between the two vectors.  The dot product is F(t) = w*cos(t/2) + p*sin(t/2), where p = u0*x + u1*y + u2*z.  Take the derivative, F'(t) = -w*sin(t/2)/2 + p*cos(t/2)/2, and set it equal to zero.  The solution is (cos(t/2),sin(t/2)) = (w,p)/sqrt(w*w+p*p).  Another solution is the negative of this but it produces the minimum, not the maximum.  The maximum value of F is sqrt(w*w+p*p).  In a numerical implementation, you can use t = 2*atan2(p,w).   ;  outstanding, exactly what I need, thanks.   