Unique rotation matrix using two axes when rotating a vector

56 Views Asked by At

I have a vector $v1$, and a rotated vector $v2$. I want to find two rotation matrices $Rx$ and $Ry$, which are rotation matrices around x-axis and y-axis, respectively, so that $Rx \times Ry \times v1 = v2$. My intuition tells me both $Rx$ and $Ry$ are unique if I restrict $\theta$, which corresponds to $Rx$ as between [-90, 90], and $\phi$, which corresponds to $Ry$ as between [0, 360]. But how am I going to find those matrices?

Make the problem simplified, let $v1=(0,0,1)$. I finally get this equation:

$\begin{pmatrix} \sin(\phi) \\ -\sin(\theta)cos(\phi) \\ \cos(\theta)cos(\phi) \\ \end{pmatrix}=\begin{pmatrix}x\\y\\z\end{pmatrix}.$

But I don't feel right about that. $\phi$ is determined by $x$? It's so easy to find a counterexample, e.g. $v1=(0, 0, 1), v2=(x, y, 0)$. In this case, $\phi$ should be 90 or 270. Where am I wrong?

3

There are 3 best solutions below

1
On BEST ANSWER

The rotation about the $x$ axis by an angle $\theta$ is given by the rotation matrix:

$ R_x = \begin{bmatrix} 1 && 0 && 0 \\ 0 && c_1 && -s_1 \\ 0 && s_1 && c_1 \end{bmatrix} $

where $c_1 = \cos \theta, s_1 = \sin \theta $

And the rotation about the $y$ axis by an angle $\phi$ is given by the rotation matrix:

$R_y = \begin{bmatrix} c_2 && 0 && s_2 \\ 0 && 1 && 0 \\ -s_2 && 0 && c_2 \end{bmatrix} $

where $c_2 = \cos(\phi), s_2 = \sin(\phi) $

So, the combined rotation is

$ R = R_x R_y = \begin{bmatrix} 1 && 0 && 0 \\ 0 && c_1 && -s_1 \\ 0 && s_1 && c_1 \end{bmatrix} \begin{bmatrix} c_2 && 0 && s_2 \\ 0 && 1 && 0 \\ -s_2 && 0 && c_2 \end{bmatrix} = \begin{bmatrix} c_2 && 0 && s_2 \\ s_1 s_2 && c_1 && -s_1 c_2 \\ - c_1 s_2 && s_1 && c_1 c_2 \end{bmatrix} $

Now given two arbitrary unit vectors given as follows:

$v_1 = ( x_1, y_1, z_1 ) $ and $v_2 = (x_2, y_2, z_2 ) $

where $x_1^2 + y_1^2 + z_1^2 = 1 = x_2^2 + y_2^2 + z_2^2 $

And you want $v_2 = R v_1 $, so

$ \begin{pmatrix} x_2 \\ y_2 \\ z_2 \end{pmatrix} = \begin{bmatrix} c_2 && 0 && s_2 \\ s_1 s_2 && c_1 && -s_1 c_2 \\ - c_1 s_2 && s_1 && c_1 c_2 \end{bmatrix} \begin{pmatrix} x_1 \\ y_1 \\ z_1 \end{pmatrix} $

From the first component of the left and right sides of this vector equation we have

$ x_2 = c_2 x_1 + s_2 z_1 $

And this equation can be solved for $\phi$ as long as

$ | x_2 | \le \sqrt{ x_1^2 + z_1^2} $

Otherwise there is no solution.

Assuming this inequality is satisfied, then we have $\phi$ and therefore, $c_2$ and $s_2$.

The second component says

$ y_2 = s_1 s_2 x_1 + c_1 y_1 - s_1 c_2 z_1 = s_1 (s_2 x_1 - c_2 z_1) + c_1 y_1 $

And this equation will have a solution if and only if

$ | y_2 | \le \sqrt{ (s_2 x_1 - c_2 z_1)^2 + y_1^2 } $

And finally, from the third component, we have

$ z_2 = c_1 ( c_2 z_1 - s_2 x_1 ) + s_1 y_1 $

And it will have a solution if and only if

$ | z_2 | \le \sqrt{ (c_2 z_1 - s_2 x_1)^2 + y_1^2 } $

It can shown that the last two inequalities follow from the first one. So only one check is necessary, namely, that $|x_2| \le \sqrt{x_1^2+z_1^2} $.

If this inequality is satisfied, then we readily obtaine $\phi$ of $R_y$. And then to find $\theta$ of $R_x$, solve for $c_1$ and $s_1$ from the second and third components. These two equations can be written as the following linear system in $c_1 $ and $s_1$

$\begin{bmatrix} y_1 && s_2 x_1 - c_2 z_1 \\ c_2 z_1 - s_2 x_1 && y_1 \end{bmatrix} \begin{bmatrix} c_1 \\ s_1 \end{bmatrix} = \begin{bmatrix} y_2 \\ z_2 \end{bmatrix} $

From which

$ \begin{bmatrix} c_1 \\ s_1 \end{bmatrix} = \dfrac{1}{y_1^2 + ( s_2 x_1 - c_2 z_1)^2 } \begin{bmatrix} y_1 && c_2 z_1 - s_2 x_1 \\ s_2 x_1 - c_2 z_1 && y_1 \end{bmatrix} \begin{bmatrix} y_2 \\ z_2 \end{bmatrix}$

And this simplifies to

$ \begin{bmatrix} c_1 \\ s_1 \end{bmatrix} = \dfrac{1}{y_1^2 + (s_2 x_1 - c_2 z_1)^2 } \begin{bmatrix} y_1 y_2 + z_2 (c_2 z_1 - s_2 x_1) \\ (s_2 x_1 - c_2 z_1) y_2 + y_1 z_2 \end{bmatrix} $

Once we have the numerical value of $c_1$ and $s_1$, angle $\theta$ can be determined uniquely as

$ \theta = \text{atan2}(c_1, s_1) $

So, in summary, if there are solutions, we can have a single solution (this case occurs when $| x_2 | = \sqrt{ x_1^2 + z_1^2}$ . Otherwise, there will be exactly two solutions for $\phi$ and a corresponding unique $\theta$ for each of the two $\phi$'s.

0
On

What you ask is not always possible. Consider for instance the situation in figure below. Rotating vector $v_1$ about $y$-axis (green) will make its endpoint to stay on the purple circle. But the transformed vector can be carried to $v_2$ after a rotation about $x$-axis (red) only if its endpoint lies on the orange circle. And that is impossible, because those two circles don't intersect.

As an extreme case, think of $v_1$ lying on the $y$-axis: $Ry$ will have no effect on it, and $Rx$ can then do its job only if $v_2$ lies in the $yz$-plane.

enter image description here

0
On

The idea of this transformation is really quite simple. The last rotation (about the $x$ axis) cannot change the $x$ coordinate, so the first rotation (around the $y$ axis) must set the $x$ coordinate to whatever final value it requires.

The limitation of the first rotation is that it cannot change the $y$ coordinate. If $v_1 = ( x_1, y_1, z_1 )$, then the vector after any rotation around the $y$ axis can only be a vector $v' = (x', y_1, z')$ where the magnitudes of $v'$ and $v_1$ are the same. Moreover, since the last rotation can't change the $x$ coordinate, the only way to have a solution is if $x' = x_2$, so the result of the first rotation really needs to be $v' = (x_2, y_1, z')$.

That's why $\phi$ is determined by $x$ in your "counterexample". Under the conditions you have set up, the only way to get the desired $x$ coordinate in $v_2$ is by choosing an appropriate rotation around $y$. There are at most two choices that work within the permitted minimum and maximum rotation angles, and they are precisely the ones that (in your example) satisfy $\sin(\phi)=x$.

The general case is only a little more complicated than your example, but we can simplify it by considering only vectors $v_1$ and $v_2$ with magnitude $1$ (unit vectors), such as the vector $(0,0,1)$ that you used in your example. Then we know that the magnitude of $v'$ also has to be $1$. We already know two of the $x$ and $y$ coordinates of $v'$ by examining the coordinates of $v_1$ and $v_2$, so only $z'$ is left to determine.

The square of the magnitude of $v'$ is $$ x_2^2 + y_1^2 + z'^2 = 1. $$ If this is solvable, it has two solutions:

$$ z' = \pm\sqrt{1 - (x_2^2 + y_1^2)}. $$

So we have a solution if and only if $x_2^2 + y_1^2 \leq 1$. Since the conditions for setting up the problem, which put no restriction on $v_1$ and $v_2$ other than that they are both unit vectors, allow $x_2$ and $y_1$ each to be anything between $-1$ and $1$, independently of each other, it is not guaranteed that there will be a solution.

But let's suppose that $x_2^2 + y_1^2 \leq 1$. Then since $\phi$ has a full $360^\circ$ interval which we can choose our angle of rotation around the $y$ axis, we can certainly find an angle $\phi$ to rotate $v_1$ to either of the vectors that have the necessary $x$ coordinate,

$$ \left(x_2, y_1, \sqrt{1 - (x_2^2 + y_1^2)}\right) \quad\text{or}\quad \left(x_2, y_1, -\sqrt{1 - (x_2^2 + y_1^2)}\right). $$

Now we run into the constraint on $\theta$. As we rotate $v'$ around the $x$ axis, it traces a circle of radius $\sqrt{1 - x_2^2}$, but you can only go $90^\circ$ in either direction along that circle according to the constraints you have defined. If we start with $y_1 > 0$, the minimum value of $y$ that we can rotate to is $-\sqrt{1 - (x_2^2 + y_1^2)}$. If we start with $y_1 < 0$, the maximum value of $y$ that we can rotate to is $\sqrt{1 - (x_2^2 + y_1^2)}$. This is illustrated in the figure below, where the arrows labeled $v'$ are the two choices for where we can rotate $v_1$ with the first rotation and the green sector shows all the directions either of these vectors can be rotated to. The red sector shows unreachable vectors.

enter image description here

That is, the problem as stated in the question is solvable only if $x_2^2 + y_1^2 \leq 1$ and at least one of the following two statements is true:

  1. $y_2$ has the same sign as $y_1$.
  2. $\lvert y_2\rvert \leq \sqrt{1 - (x_2^2 + y_1^2)}$.

There are ways to get vectors in every possible direction using just two rotations, one by up to $360^\circ$ in one direction and one by up to $90^\circ$ in either of two directions. Consider latitudes and longitudes on the surface of the Earth as a way of specifying a vector from the center of the Earth to the surface, or a platform that can turn completely around in a horizontal plane with a telescope mounted on that platform in a way that lets the telescope be elevated or depressed $90^\circ$ above or below the horizon.

The main reasons these examples don't apply here are that in the case of latitudes and longitudes, the angles don't express motion between points; and in the case of the telescope, one of the rotations is about a body axis rather than a spatial axis. That is, when you turn the platform, the axis of the telescope's mount changes direction; but when you rotate your vector around the $y$ axis, the $x$ axis doesn't change direction.

You can pretend that the telescope mount doesn't need to use a body axis if we consider the $z$ axis to be the vertical axis and start with the telescope pointing along the $y$ axis. Then we can elevate or depress the telescope by up to $90^\circ$ by rotating around the $x$ axis to the desired angle above or below the horizon. Then we can rotate around the $z$ axis to point in the exact desired direction.

And that's another odd thing about your setup. In order to use only the axes of the coordinate system in an azimuth-elevation scheme, we do the elevation rotation -- the one that is limited to $90^\circ$ up or down -- before we do the rotation that is allowed $360^\circ$. You have reversed the order of rotation. You can still point your vector $v_2$ in any direction if you start with a suitable $v_1$ -- any $v_1$ with $y=0$ will do -- but the mechanics of doing this will look rather weird if you were expecting them to be like the azimuth-elevation model.