Trigonometry to move an arm around axis in 3D space Hello I have a question about rotating a Rod hinged to a fixed point (so it swings all around), and targets. short form, I would like to know how to find a rotation that would point my rod (while still attached to the fixed point) towards the position of the target.
I would also like to find the rotation as a quaternion, and/or axis-angle to prevent gimbal lock.
The image I made shows my problem with clarity.

 A: Let $\hat{u}$ be the unit vector representing the current direction of the arm, with origin at the hinge, and $\hat{v}$ be the unit vector representing the direction of the desired target.
You need a rotation around unit axis vector $\hat{a}$ by angle $\theta$,
$$\begin{aligned}
\hat{a} &= \frac{\hat{u} \times \hat{v}}{\left\lVert \hat{u} \times \hat{v} \right\rVert} \\
\theta &= \arccos\left(\hat{u} \cdot \hat{v}\right) \\
\end{aligned}$$
This works, because cross product yields a vector that is perpendicular to both the current direction and the desired direction, and dot product of two unit vectors yields the cosine of the angle between the two.
If you want this as a quaternion $\mathbf{q} = (r, i, j, k)$, then
$$\left\lbrace ~ \begin{aligned}
r &= \cos\left(\frac{\theta}{2}\right) \\
i &= a_x \sin\left(\frac{\theta}{2}\right) \\
j &= a_y \sin\left(\frac{\theta}{2}\right) \\
k &= a_z \sin\left(\frac{\theta}{2}\right) \\
\end{aligned} \right.$$
and if you correctly implement this, with $\hat{a}$ an unit vector ($a_x^2 + a_y^2 + a_z^2 = 1$), then $r^2 + i^2 + j^2 + k^2 = 1$, and the quaternion $\mathbf{q}$ is the desired unit quaternion.
As a rotation matrix $\mathbf{R}$, the same is
$$\mathbf{R} = \left[ \begin{matrix}
a_x^2   n +     c & a_x a_y n - a_z c & a_x a_z n + a_y c \\
a_x a_y n + a_z c & a_y^2   n +     c & a_y a_z n - a_z c \\
a_x a_z n - a_y c & a_y a_z n + a_x c & a_z^2     +     c \\
\end{matrix} \right], \quad c = \cos\left(\theta\right), \quad n = 1 - c$$
