I have the orientation of a body in world frame, $_wP_b$. Let us say, a bottle with the z axis representing the height, lying on its sides on the table. Now, I have a direction vector $\textbf{v}$, given in world frame. I would like to align the z axis of the body along the vector $\textbf{v}$. But the constraint is that, the body must not be rotated about its z axis. e.g. with the bottle example, when I orient the height axis of the bottle along the vector $v$, it should not rotate about its height. Think of a robot gripper holding the bottle, so you cannot essentially the bottle along the gripper width, since it is clamped firmly.
I'd like to know if this is a well constrained and well formed problem that can be solved, or if I need additional constraints. Any help would be appreciated.
We can assume the directions of the $x',y',z'$ axes of the object are given by the columns of the rotation matrix
$ R = [u_1, u_2, u_3]$
Now the question, specifies that we want to rotate these axes about the $x'$ axis, then about the $y'$ axis, the resulting axes are the columns of $R_1$ which is given by
$R_1 = R R_x(\theta) R_y(\phi) $
To derive this formula, note that a point $P(x,y,z)$ specified in the world coordinates is related to the initial local coordinates (before rotation about the $x'$ axis and the $y'$ axis) by
$ P = R Q $
$Q$ here is the coordinates in the frame $O'x'y'z'$. Now if we rotate this frame about the $x'$ axis then
$Q = R_x(\theta) Q_1 $
And then after rotating about the new $y'$ axis then
$Q_1 = R_y(\phi) Q_2 $
Putting all this together, we find that
$ P = R R_x(\theta) R_y(\phi) Q_2 $
So the final axes of the frame attached to the object are the columns of
$ R' = R R_x(\theta) R_y(\phi) $
Now it is well-known that
$R_x(\theta) = \begin{bmatrix} 1 && 0 && 0 \\ 0 && \cos(\theta) && - \sin(\theta) \\ 0 && \sin(\theta) && \cos(\theta) \end{bmatrix} $
and
$R_y(\phi) = \begin{bmatrix} \cos(\phi) && 0 && \sin(\phi) \\ 0 && 1 && 0 \\ -\sin(\phi) && 0 && \cos(\phi) \end{bmatrix}$
The product is
$ R_x R_y = \begin{bmatrix} \cos(\phi) && 0&& \sin(\phi) \\ \sin(\theta)\sin(\phi) && \cos(\theta) && - \sin(\theta)\cos(\phi)\\ -\cos(\theta)\sin(\phi) && \sin(\theta) && \cos(\theta) \cos(\phi) \end{bmatrix} $
Now the $z'$ axis of the object is the vector $Q_2 = [0, 0, 1]^T$ , and we want this vector to point along the unit vector $v$, i.e. we want
$v = R R_x R_y [0, 0, 1]^T $
Multiply both sides by $R^T $ then
$R^T v = R_x R_y [0, 0, 1]$
The left hand side is some vector $w = R^T v $, and the right hand side is the third column of $R_x R_y$. Hence, we have the unit vector $w$ satisfying
$ w = \begin{bmatrix} \sin(\phi) \\ - \sin(\theta) \cos(\phi) \\ \cos(\theta) \cos(\phi) \end{bmatrix} $
From here, we can find the angles $\theta$ and $\phi$ as follows
$ w_x = \sin(\phi) \hspace{5pt} \Rightarrow \phi = \sin^{-1}(w_x) $
$ \theta = \text{Atan2}(- w_y , w_z ) $