I have an orthonormal basis ${\bf{b}}_1$ and ${\bf{b}}_2$ in $\mathbb{R}^2$. I want to find out the angle of rotation. I added a little picture here. I essentially want to find $\theta$
I know that I can compute the angle between two vectors but then there are $4$ combinations here
- $\theta_{11} = \arccos({\bf{b}}_1^\top{\bf{e}}_1)$
- $\theta_{12} = \arccos({\bf{b}}_1^\top{\bf{e}}_2)$
- $\theta_{21} = \arccos({\bf{b}}_2^\top{\bf{e}}_1)$
- $\theta_{22} = \arccos({\bf{b}}_2^\top{\bf{e}}_2)$
How would one know which angle is correct? Importantly, here I used the labels $b_1$, $b_2$ in the same order as $e_1$ and $e_2$ but that's not necessarily the same order geometically!

Let $\mathbf{b}_1 = (x_1, y_1)$. Then, $\theta = \operatorname{atan2}(y_1, x_1)$.
$\operatorname{atan2}(y_1, x_1)$ is the two-argument form of arcus tangent, equivalent to $\arctan(y_1 / x_1)$ except that the two-argument form takes the quadrant (signs of both $x_1$ and $y_1$) into account.
If you do not know which of $\mathbf{b}_1 = (x_1, y_1)$ and $\mathbf{b}_2 = (x_2, y_2)$ to use, then $$\begin{aligned} d &= x_1 y_2 - x_2 y_1 \\ \theta &= \begin{cases} \operatorname{atan2}(y_1, x_1), & d \ge 0 \\ \operatorname{atan2}(y_2, x_2), & d \lt 0 \\ \end{cases} \end{aligned}$$ Here, $d \gt 0$ if $\mathbf{b}_2$ is counterclockwise from $\mathbf{b}_1$, and $d \lt 0$ if clockwise. This uses the vector which is the clockwise one of the pair.
Note that for arbitrary coordinate system $\mathbf{e}_1$, $\mathbf{e}_2$, you can use $$\begin{aligned} x_1 &= \mathbf{b}_1^T \mathbf{e}_1 \\ y_1 &= \mathbf{b}_1^T \mathbf{e}_2 \\ x_2 &= \mathbf{b}_2^T \mathbf{e}_1 \\ y_2 &= \mathbf{b}_2^T \mathbf{e}_2 \\ \end{aligned}$$ above.