# rotation matrix $R$ to axis and angle

Is it possible to convert a $3 \times 3$ rotation matrix $R$ to axis and angle representation such that the axis $n = \left ( n_x, n_y, n_z \right )$ is enforced to have all positive values and the angle is bound between $\left [0, 2\pi \right )$. Right now I am using:

$$\theta = \cos^{-1} \left( \frac{R(1,1)+R(2,2)+R(3,3)-1}{2}\right) \\ nx = \frac{R(3,2)-R(2,3)}{2\sin(\theta)} \\ ny = \frac{R(1,3)-R(3,1)}{2\sin(\theta)} \\ nz = \frac{R(2,1)-R(1,2)}{2\sin(\theta)} \\$$

but this does not enforce either condition and has a singularity at $\theta = 0$.

Your all-axis-values-positive constraint is too strict. It's impossible to satisfy in some cases. For example, the axis +X - Z doesn't have all positive values and neither does its opposite -X + Z.

If you weaken the constraint to requiring that the axis have a positive dot product against the vector X+Y+Z, then that's do-able. Just take any typical axis-angle-to-matrix conversion method, follow it up by dot-product-ing the axis against X+Y+Z, then negate both the axis and the angle if the dot-product was negative.