Find $\theta_y$ $\theta_x$ from two vectors $\vec{u}$ and $\vec{v}$ if $\vec{v} = R_yR_x\vec{u}$

47 Views Asked by At

If I know that $\vec{u}$ was rotated to $\vec{v}$ by rotation along the $y$ axis followed by rotation along the $x$ axis, or that $$\vec{v} = R_yR_x\vec{u}$$

Is it possible to solve for angles $y$ and $x$ either analytically or numerically quickly?

The simplified case is when $\vec{u}= \hat{i},\hat{j},\hat{k}$, in the case of $\vec{u}=\hat{k}$,

$$\vec{v}= \begin{bmatrix} \cos y& 0 & \sin y\\ 0 & 1 & 0 \\ -\sin y & 0 & \cos y \\ \end{bmatrix}\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos x& -\sin x \\[3pt] 0 & \sin x & \cos x \\[3pt] \end{bmatrix}\left(\begin{matrix}0\\0\\1\end{matrix}\right)$$ which simplifies to $$ \vec{v} = \left(\begin{matrix}\sin y\cos x\\-\sin x\\ \cos x \cos y\end{matrix}\right) $$

which is easy enough to solve for, analytically and numerically. However, for a generic vector $\vec{u} = (a,b,c)$, it becomes $$ \vec{v}=\begin{pmatrix}\cos \left(y\right)a+\sin \left(y\right)\sin \left(x\right)b+\sin \left(y\right)\cos \left(x\right)c\\ b\cos \left(x\right)-c\sin \left(x\right)\\ -a\sin \left(y\right)+b\cos \left(y\right)\sin \left(x\right)+c\cos \left(y\right)\cos \left(x\right)\end{pmatrix}$$

which I'm not sure if it is possible to solve analytically. Numerically, solve from sympy works, but is much too slow for my use case. Using nsolve from sympy works for most cases, but it occasionally fails to find a solution. Furthermore, I would like to find all possible solutions within $-\pi/2 \leq x,y \leq \pi/2$ and sympy only returns one solution.

Any ideas?

1

There are 1 best solutions below

4
On BEST ANSWER

Call $\vec{v} = (A,B,C)^T$ and if you multiply the first and third equations by $\sin y$ and $\cos y$, respectively, and then add them together, you will get: $$\begin{cases} A\sin y + C\cos y &= b\sin x + c\cos x \\ B &= b\cos x - c\sin x \end{cases}$$

Then you square both these equations and add them again to get: $$B^2+(A\sin y + C\cos y)^2 = b^2+c^2$$ and from this, you can even have an analytic solution for $y$, if you introduce an auxiliary angle for which $\cos\theta = \dfrac{A}{\sqrt{A^2+C^2}}$

EDIT: Choose $\theta$ such that $\cos\theta = \dfrac{A}{\sqrt{A^2+C^2}}$ and $\sin\theta = \dfrac{C}{A^2+C^2}$, then you have: $$\cos\theta\sin y+\sin\theta\cos y = \pm\sqrt{\dfrac{b^2+c^2-B^2}{A^2+C^2}} = \sin(\theta+y).$$

This technically allows you to have closed form solutions using $\arcsin$.