I have a 3x3 rotation matrix named $A$ which represent the orientation of an object in $\mathbb{R}^3$. The basis vectors of this matrix are linearly independent.
Furthermore, I have a vector $V$ (also in $\mathbb{R}^3$).
From hereon I assume that the following notion is correct: $M_x$, $M_y$ and $M_z$ are the $x$, $y$ and $z$ basis vectors of a 3x3 rotation matrix $M$.
My goal is to calculate another rotation matrix $B$ which, when multiplied with $A$, aligns $A_x$ with $V$. So after calculating/determining $B$, I can calculate $C = B * A$ and $C_x$ aligns with $V$.
Naturally, there are infinitely many solutions to this. I would like to know how I can solve this in a way that $C_x$ aligns with $V$ but the direction of $C_z$ is the same as $A_z$ (a rotation around $A_z$).
In other words: I'd like to calculate $B$ so that $C_x$ aligns with $V$ while only rotating around $A_z$.
Edit: As mentioned in the comment, in a general case this is not possible. I am looking for an "as close as possible" solution. As the title suggest, I would refer to this as "the smallest rotation around $A_y$ and $A_z$ as possible".
Background: In a 3D computer graphics environment, I have a 3D model in a scene. The model is positioned & oriented using a 4x4 transformation matrix of which the upper left 3x3 is the rotation matrix. I want to rotate the object so that the rotation matrix $R_x$ vector is always aligned with another vector $V$. I tried to do this by creating a Quaternion from a two unit vectors ($R_x$ and $V$), constructing a rotation matrix from that Quaternion and applying the rotation via matrix multiplication. While my object's $x$-axis is properly aligned with the vector, the object's "remaining" orientation changes due to the nature of having infinitely many solutions to align the $x$-axis vector. What I want to do is to rotate the object in a way $A_x$ and $V$ are aligned but without rotating it around wildly. Imagine an object that has a clearly defined "front" and "up" direction. When performing the rotation to align $A_x$ with $V$, the "up" and "front" directions should change as little as possible. i.e: "up" should still be up and "front" should still be front. Currently the object can get rotated in a way that an entirely different. I lack the ability to explain this better...
Ignore the rest of $A$ for a minute, and find the smallest rotation that will align $A_x$ with $V$. The axis of this rotation is $A_x \times V$, with angle $\theta = \mathrm{arccos}(A_x \cdot V)$ (assuming $V$ is a unit vector). This same rotation will align the x axis of $A$ with $V$ while changing $A_y$ and $A_z$ as little as possible, although you can't guarantee either will remain unchanged. If $A_y$ or $A_z$ is not perpendicular to $V$, then they have to be modified if $A_x$ is to align with $V$.
If, on the other hand, you want to force $A_z$ to remain unchanged, and instead just get $A_x$ and $V$ as close as possible, that rotation is around the $A_z$ axis, and the angle can be found by projecting $V$ into the $A_{xy}$ plane and measuring the angle to $A_x$. First, rotate $V$ into the $A$ orientation, $V' = A^T V$, then take $\mathrm{arctan2}(V'_y, V'_x)$ (might have gotten the arguments reversed there). This will fail if both components are 0, but of course that happens when $V$ is aligned with $A_z$, so all rotations are equally bad.