How to determine the rotation angles of a telescope I have two control buttons on my telescope, one to increase/decrease the right ascension (rotation around z-axis) and one to increase/decrease the declination (rotation around y-axis). My first target has a right ascension of 10 deg and declination of 20 deg. First I command a 20-deg rotation around the y-axis and then a second rotation of 10 deg about the z-axis. Now my telescope (original pointing direction to (1, 0, 0)) points to
$$ (0.925416 \hspace{3mm} 0.163176 \hspace{3mm} 0.342020)$$
The second target has a right ascension of 20 deg and declination of 40 deg. If I repeat the same matrix multiplications as before (20-deg rotation around the y-axis followed by a rotation of 10 deg about the z-axis) I am not ending up exactly at right ascension of 20 deg and declination of 40 deg. This is the result:
$$ (0.712860 \hspace{3mm} 0.291390 \hspace{3mm} 0.637905)$$
But I should point to:
$$ (0.719846 \hspace{3mm} 0.262003 \hspace{3mm} 0.642788)$$
My question is, how do I calculate the correct rotation angles for the third and the fourth rotation? I could numerically solve for the unknown rotation angles, but I wonder if there exists an analytical solution where I do not need a root finder. I am grateful for any help.
 A: The reason why it does not work for you is that matrix multiplication is not commutative. Let's call $\vec v_0=(1,0,0)$. Then you apply a rotation first around the $y$ axis $R_y(20)$, and then a rotation around $z$ axis $R_z(10)$. In matrix notation this is $$\vec v_1=R_z(10)R_y(20)\vec v_0$$
When you repeat the same procedure you get $$\vec v_2=R_z(10)R_y(20)R_z(10)R_y(20)\vec v_0$$
But this is different than $R_z(20)R_y(40)\vec v_0$ because
$$R_z(10)R_y(20)\ne R_y(20)R_z(10)$$
So how to fix this? Start from $\vec v_1$ and you want to get to some desired $\vec v_d$. Write the general rotation matrix consisting of a rotation around $z$ by an angle $\alpha$ and a rotation around $y$ by an angle $\beta$.
You get $$\vec v_d=R_z(20)R_y(40)\vec v_0=R_z(\alpha)R_y(\beta)\vec v_1=R_z(\alpha)R_y(\beta)R_z(10)R_y(20)\vec v_0$$
So $$R_z(20)R_y(40)=R_z(\alpha)R_y(\beta)R_z(10)R_y(20)$$
Noting that $R^{-1}(p)=R(-p)$, multiply both sides on the right first by $R_y(-20)$, then by $R_z(-10)$, and you get:
$$R_z(\alpha)R_y(\beta)=R_z(20)R_y(40)R_y(-20)R_z(-10)=R_z(20)R_y(20)R_z(-10)$$
If you wrote explicitly the general rotation matrix you can now determine the angles.
A: I assume that when your telescope is pointing to $(1,0,0)$, it is pointing at the equator on the local meridian. If so, the declination axis is aimed at the point due east: $(0,1,0)$ and the polar axis is pointing at the north celestial pole: $(0,0,1)$.
The matrix for rotating $\alpha$ in right ascension is
$$
R_\text{A}(\alpha)=
\begin{bmatrix}
\cos(\alpha)&\sin(\alpha)&0\\
-\sin(\alpha)&\cos(\alpha)&0\\
0&0&1
\end{bmatrix}
$$
The matrix for rotating $\delta$ in declination is
$$
R_\text{D}(\delta)=
\begin{bmatrix}
\cos(\delta)&0&\sin(\delta)\\
0&1&0\\
-\sin(\delta)&0&\cos(\delta)
\end{bmatrix}
$$
However, since matrix multiplication is not commutative, $R_\text{D}$ is only valid for rotating when the scope is aimed on the local meridian. As the right ascension changes, the declination axis is rotated. So to see the effect of rotating $\delta$ on the declination axis after your telescope has rotated a total of $\alpha$ in right ascension, you would use the matrix
$$
R_\text{D}(\delta\vert\alpha)=R_\text{A}(-\alpha)\,R_\text{D}(\delta)\,R_\text{A}(\alpha)
$$
$R_\text{D}(\delta\vert\alpha)$ undoes the action of rotating $\alpha$ in right ascension, performs the rotation of $\delta$ in declination, then restores the action of rotating $\alpha$ in right ascension.
So, as you computed:
$$
(1,0,0)\,R_\text{D}\!\left(20^{\large\circ}\right)R_\text{A}\!\left(10^{\large\circ}\right)=(0.925417, 0.163176, 0.342020)
$$
But then, using $R_\text{D}\!\left(20^{\large\circ}\vert10^{\large\circ}\right)$
$$
(1,0,0)\,R_\text{D}\!\left(20^{\large\circ}\right)R_\text{A}\!\left(10^{\large\circ}\right)R_\text{D}\!\left(20^{\large\circ}\vert10^{\large\circ}\right)R_\text{A}\!\left(10^{\large\circ}\right)=(0.719846, 0.262003, 0.642788)
$$
To repeat the process, you would use $R_\text{D}\!\left(20^{\large\circ}\vert20^{\large\circ}\right)$, since you have rotated a total of $20^{\large\circ}$ in right ascension.
