11
$\begingroup$

Given two points on the surface of a sphere in 3D space, is it possible to/how does one systematically determine the set of rotations around the x, y, and z-axes in order to transform one point to the other?

For example, on the unit sphere centred at the origin with a radius of 1, the points $(1, 0, 0)$ and $(0, \frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}})$ are both (I believe) on the sphere's surface. One can translate from $(1, 0, 0)$ to $(0, \frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}})$ by rotating $90^o$ degrees (counter-clockwise?) around the z-axis, then rotating $45^0$ degrees (clockwise?) around the x-axis.

I feel like the answer to this should be simple, but I have been struggling to answer it for a few days now.

EDIT: Just to add my attempt to follow Robert Israel's approach below with my real world example; perhaps someone can spot my mistake.

My input point is $(0.248729, -0.617981, 0.07822)$, the target is $(0.31209, -0.524457, 0.07822)$ - note that these both have a length (distance from $(0, 0, 0)$) of $0.670735...$, so are on the same sphere (give or take floating point errors.)

$a = 0.248739,\ b = -0.617981,\ c =0.07822,\ d = 0.31209,\ e = -0.524457,\ f =0.07822$

I compute $r = \sqrt{a^2 + b^2} = 0.6615811...$.

Therefore, $\theta = \operatorname{sgn}(b)\arccos(a/r) = -1 * 1.1881482... = -1.1881482...$

$|d|$ is $0.31209$, which is less than $r$, so $\alpha$ can just be computed as $\alpha = \arccos(d/r) - \theta = 2.271361...$

Rotating the original point by this, to $(d, g, h)$, gives $(0.31209, 0.588529, 0.078229)$ - this is good, since $d$ is correct and the length of this is also $0.670735...$, so it's on the sphere. Additionally, $g^2 + h^2 = 0.3524... = e^2 + f^2$.

However, this is where I flounder. I attempt to calculate $\phi$:

$g = \sqrt{g^2 + h^2} \,\cos(\phi)$

$\phi = \arccos\left(\sqrt{g^2 + h^2}/g\right)$

However, $\sqrt{g^2 + h^2}/g = 1.0087...$, so it doesn't work to take the $\arccos$ of it... and now I don't know where to go.

  • 0
    It is trivial to find the rotation matrix that does this. Perhaps you could do that, and then [extract](https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Rotation_matrix_%E2%86%94_Euler_angles) the Euler/Tait-Bryan angles from the matrix? The exact formulae depends on the order of the rotations, of course; that being one of the ways Euler/Tait-Bryan angles are evil.2018-04-27

4 Answers 4

7

In general, suppose you want to start with $(a,b,c)$ and transform it to $(d,e,f)$ (where $a^2 + b^2 + c^2 = d^2 + e^2 + f^2 = 1$) using a rotation around the $z$ axis followed by a rotation around the $x$ axis.
Now rotation by angle $\alpha$ around the $z$ axis takes $(a,b,c)$ to $(a \cos(\alpha) - b \sin(\alpha), a \sin(\alpha) + b \cos(\alpha), c)$. Since a rotation around the $x$ axis preserves the $x$ coordinate, you need $a \cos(\alpha) - b \sin(\alpha) = d$. Write $a = r \cos(\theta)$, $b = r \sin(\theta)$ where $r = \sqrt{a^2 + b^2}$ and $\theta = \text{signum}(b) \arccos(a/r)$, and this equation becomes $r \cos(\alpha + \theta) = d$. For this to be possible you need $|d|\le r$, and then you can take $\alpha = \arccos(d/r) - \theta$. If the result of this rotation is $(d, g, h)$, we will have $g^2 + h^2 = 1 - d^2 = e^2 + f^2$, and rotation by angle $\beta$ around the $x$ axis will take this to $(d, g \cos(\beta) - h \sin(\beta), g \sin(\beta) + h \cos(\beta))$. Write $g = \sqrt{g^2+h^2} \cos(\phi)$, $h = \sqrt{g^2 + h^2} \sin(\phi)$, $e = \sqrt{g^2+h^2} \cos(\tau)$ and $f = \sqrt{g^2+h^2} \sin(\tau)$, and you'll see that $\beta = \tau - \phi$ will work.

Of course you can always throw in a rotation around the $y$ axis too (and you'll need one if |d| > r).

  • 0
    @MichalCharemza: If I remember properly the bounty was put by you: thanks for assigning to my answer. However I would be interested in knowing your feed-back about it, because it is a somehow tough subject to explain.2018-05-05
3

Given to unitary vectors $\bf u$ and $\bf v$, thus two points on the unitary sphere, there are of course infinite paths leading from $\bf u$ to $\bf v$.
A neat and simple (as much as spherical geometry allows) approach I think is that of taking the shortest path, i.e. the path along the great-circle or orthodrome.
That will lay on the plane through the origin and parallel to $\bf u$ and $\bf v$.

2_p_su_sfera_1

The unit normal to that plane (Right_Hand rule $\bf u \to \bf v$) is $ {\bf n} = {{{\bf u} \times {\bf v}} \over {\left| {{\bf u} \times {\bf v}} \right|}} $

It is useful to consider also another unit vector $\bf t$, lying on the plane and normal to $\bf u$ $ {\bf t} = {\bf n} \times {\bf u} $ which already normalized by definition.

Note that the right handed ref. system $x,y,z$ transforms into the right handed ref. system $\bf u, \bf t, \bf n$.
If we put these last three vectors as the columns of a matrix, we obtain $ \left( {\begin{array}{c|c|c} {\bf u} & {\bf t} & {\bf n} \\ \end{array}} \right) = {\bf T}\quad \Rightarrow \quad \left( {\begin{array}{c|c|c} {\bf u} & {\bf t} & {\bf n} \\ \end{array}} \right) = {\bf T}\left( {\begin{array}{c|c|c} {\bf i} & {\bf j} & {\bf k} \\ \end{array}} \right) $ and $\bf T$ is by definition orthogonal, unitary and with $|\bf T|=1$. Thus it is also $\bf T^{-1}= \bf T^{T}$.

The great circle angle from $\bf u$ to $\bf v$ is given, in absolute value and sign by $ \alpha = \arctan _2 \left( {{\bf v} \cdot {\bf u},\;{\bf v} \cdot {\bf t}} \right) = \arctan _2 \left( {\cos \alpha ,\;\sin \alpha } \right) $ that is we will use both the cosine and sine value to determine $\alpha$.

So $(\cos \alpha, \sin \alpha,0)$ are the coordinates of $\bf v$ in the $(\bf u, \bf t, \bf n)$ sytem, that is we can put $ {\bf v} = {\bf R}_{\,{\bf n}} (\alpha )\;{\bf u} = \left( {\matrix{ {\cos \alpha } & { - \sin \alpha } & 0 \cr {\sin \alpha } & {\cos \alpha } & 0 \cr 0 & 0 & 1 \cr } } \right)\;{\bf u} $ Since we can write $ \begin{array}{l} {\bf v} = \left( {\begin{array}{*{20}c} {\bf u} &| & {\bf t} &| & {\bf n} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = {\bf T}\left( {\begin{array}{*{20}c} {\bf i} &| & {\bf j} &| & {\bf k} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = \\ = {\bf T}\;\left( {\begin{array}{*{20}c} {\bf i} &| & {\bf j} &| & {\bf k} \\ \end{array}} \right)\;{\bf T}^{\, - \,{\bf 1}} \;{\bf T}\;\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = {\bf T}\;{\bf I}\;{\bf T}^{\, - \,{\bf 1}} \;{\bf T}\;\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = \\ = \;{\bf T}\;\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = \left( {\begin{array}{*{20}c} {\bf i} &| & {\bf j} &| & {\bf k} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} {v_{\,x} } \\ {v_{\,y} } \\ {v_{\,z} } \\ \end{array}} \right) \\ \end{array} $ then $ \begin{array}{l} \left( {\begin{array}{*{20}c} {v_{\,x} } \\ {v_{\,y} } \\ {v_{\,z} } \\ \end{array}} \right) = \;{\bf T}\;\left( {\begin{array}{*{20}c} {v_{\,u} } \\ {v_{\,t} } \\ {v_{\,n} } \\ \end{array}} \right) = {\bf TR}_{\,{\bf n}} (\alpha )\;{\bf u}_{u,\,t,\,n} = {\bf TR}_{\,{\bf n}} (\alpha )\;{\bf T}^{\, - \,{\bf 1}} \;{\bf T}\;{\bf u}_{u,\,t,\,n} = \\ = {\bf TR}_{\,{\bf n}} (\alpha )\;{\bf T}^{\, - \,{\bf 1}} \;{\bf T}\;{\bf u}_{x,\,y,\,z} \\ \end{array} $ and finally, with $\bf u, \; \bf v$ expressed in the $(x,y,z)$ ref. system: $ {\bf v} = {\bf T}\,{\bf R}_{\,{\bf n}} (\alpha )\;{\bf T}^{\, - \,{\bf 1}} \,{\bf u} $

As you can see it is a quite fluid and general procedure.

As for the example you give, we have $ \begin{array}{l} {\bf u} = \left( {\begin{array}{*{20}c} 1 \\ 0 \\ 0 \\ \end{array}} \right)\quad \quad {\bf v} = \left( {\begin{array}{*{20}c} 0 \\ {\sqrt 2 /2} \\ {\sqrt 2 /2} \\ \end{array}} \right) \\ {\bf n} = \frac{{{\bf u} \times {\bf v}}}{{\left| {{\bf u} \times {\bf v}} \right|}} = \left( {\begin{array}{*{20}c} 0 \\ { - \sqrt 2 /2} \\ {\sqrt 2 /2} \\ \end{array}} \right)\quad \quad {\bf t} = {\bf n} \times {\bf u} = \left( {\begin{array}{*{20}c} 0 \\ {\sqrt 2 /2} \\ {\sqrt 2 /2} \\ \end{array}} \right) \\ \alpha = \arctan _2 \left( {{\bf v} \cdot {\bf u},\;{\bf v} \cdot {\bf t}} \right) = \arctan _2 \left( {0,\;1} \right) = \pi /2 \\ {\bf T} = \left( {\begin{array}{*{20}c} {\bf u} &| & {\bf t} &| & {\bf n} \\ \end{array}} \right) = \left( {\begin{array}{*{20}c} 1 & 0 & 0 \\ 0 & {\sqrt 2 /2} & { - \sqrt 2 /2} \\ 0 & {\sqrt 2 /2} & {\sqrt 2 /2} \\ \end{array}} \right) \\ {\bf R}_{\,{\bf n}} (\alpha ) = \left( {\begin{array}{*{20}c} {\cos \alpha } & { - \sin \alpha } & 0 \\ {\sin \alpha } & {\cos \alpha } & 0 \\ 0 & 0 & 1 \\ \end{array}} \right) = \left( {\begin{array}{*{20}c} 0 & { - 1} & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right) \\ {\bf T}\,{\bf R}_{\,{\bf n}} (\alpha )\;{\bf T}^{\, - \,{\bf 1}} = \\ = \left( {\begin{array}{*{20}c} 1 & 0 & 0 \\ 0 & {\sqrt 2 /2} & { - \sqrt 2 /2} \\ 0 & {\sqrt 2 /2} & {\sqrt 2 /2} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 0 & { - 1} & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 1 & 0 & 0 \\ 0 & {\sqrt 2 /2} & {\sqrt 2 /2} \\ 0 & { - \sqrt 2 /2} & {\sqrt 2 /2} \\ \end{array}} \right) = \\ = \left( {\begin{array}{*{20}c} 0 & { - \sqrt 2 /2} & { - \sqrt 2 /2} \\ {\sqrt 2 /2} & {1/2} & { - 1/2} \\ {\sqrt 2 /2} & { - 1/2} & {1/2} \\ \end{array}} \right) \\ \end{array} $ and in fact $ \left( {\begin{array}{*{20}c} 0 \\ {\sqrt 2 /2} \\ {\sqrt 2 /2} \\ \end{array}} \right) = \left( {\begin{array}{*{20}c} 0 & { - \sqrt 2 /2} & { - \sqrt 2 /2} \\ {\sqrt 2 /2} & {1/2} & { - 1/2} \\ {\sqrt 2 /2} & { - 1/2} & {1/2} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 1 \\ 0 \\ 0 \\ \end{array}} \right) $

Going your way instead, just for the cited example, you shall first rotate around $z$ by $+\pi/2$ (RH rule), and then around the new $y$ axis, which has become the $-x$, i.e. $x$ axis, by $+\pi/4$ (RH rule again). The matrices are $ {\bf R}_{\,{\bf x}} (\alpha ) = \left( {\begin{array}{*{20}c} 1 & 0 & 0 \\ 0 & {\cos \alpha } & { - \sin \alpha } \\ 0 & {\sin \alpha } & {\cos \alpha } \\ \end{array}} \right)\quad {\bf R}_{\,{\bf y}} (\beta ) = \left( {\begin{array}{*{20}c} {\cos \beta } & 0 & {\sin \beta } \\ 0 & 1 & 0 \\ { - \sin \beta } & 0 & {\cos \beta } \\ \end{array}} \right)\quad {\bf R}_{\,{\bf z}} (\gamma ) = \left( {\begin{array}{*{20}c} {\cos \gamma } & { - \sin \gamma } & 0 \\ {\sin \gamma } & {\cos \gamma } & 0 \\ 0 & 0 & 1 \\ \end{array}} \right) $ they always act on the base reference, and the sign of the angle is according to the RH rule, so $ \begin{array}{l} \left( {\begin{array}{*{20}c} 0 \\ {\sqrt 2 /2} \\ {\sqrt 2 /2} \\ \end{array}} \right) = {\bf R}_{\,{\bf x}} (\pi /4){\bf R}_{\,{\bf z}} (\pi /2)\left( {\begin{array}{*{20}c} 1 \\ 0 \\ 0 \\ \end{array}} \right) = \\ = \left( {\begin{array}{*{20}c} 1 & 0 & 0 \\ 0 & {\sqrt 2 /2} & { - \sqrt 2 /2} \\ 0 & {\sqrt 2 /2} & {\sqrt 2 /2} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 0 & { - 1} & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 1 \\ 0 \\ 0 \\ \end{array}} \right) = \\ = \left( {\begin{array}{*{20}c} 0 & { - 1} & 0 \\ {\sqrt 2 /2} & 0 & { - \sqrt 2 /2} \\ {\sqrt 2 /2} & 0 & {\sqrt 2 /2} \\ \end{array}} \right)\left( {\begin{array}{*{20}c} 1 \\ 0 \\ 0 \\ \end{array}} \right) \\ \end{array} $

2

As is mentioned here, another approach to the problem is to use quaternions. The basic wiki page and the rotation wiki page are very good resources for understanding how these generalizations of complex numbers work. The procedure is as follows:

  1. Compute the cross product of the vectors going to the two points: this will be the axis of rotation, and gets inserted into the $\mathbf{i}, \mathbf{j},$ and $\mathbf{k}$ components of the rotation quaternion.
  2. Compute the dot product of the vectors going to the two points: this allows you to find the angle of rotation needed, which goes into the real part of the quaternion, as well as multiplying the complex parts. The angle is the $\arccos$ of the dot product (recall that $\mathbf{x}\cdot\mathbf{y}=\|x\|\,\|y\|\,\cos(\theta)$, so if $\|x\|=\|y\|=1$, we have $\theta=\arccos(\mathbf{x}\cdot\mathbf{y})$).

So, for your example: you want to find the rotation needed to get from point $\mathbf{v}_1=(1,0,0)$ to point $\mathbf{v}_2=\left(0,\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}\right)$. We compute: \begin{align*} \mathbf{v}_1\times\mathbf{v}_2&=\left(0,-\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}\right)\quad\text{and}\\ \mathbf{v}_1\cdot\mathbf{v}_2&=0. \end{align*} Hence, the angle of rotation is $\theta=\arccos(0)=\dfrac{\pi}{2}.$ From the rotation quaternion wiki page, we see that the necessary rotation quaternion is \begin{align*}q&=\cos\left(\frac{\theta}{2}\right)+(u_x\mathbf{i}+u_y\mathbf{j}+u_z\mathbf{k})\,\sin\left(\frac{\theta}{2}\right)\\ &=\frac{1}{\sqrt{2}}+\left(0\mathbf{i}-\frac{\mathbf{j}}{\sqrt{2}}+\frac{\mathbf{k}}{\sqrt{2}}\right)\frac{1}{\sqrt{2}}\\ &=\frac{1}{\sqrt{2}}+\left(0\mathbf{i}-\frac{\mathbf{j}}{2}+\frac{\mathbf{k}}{2}\right).\end{align*} Now we double-check that the rotation represented by this quaternion actually works, and here's where the fun really begins: quaternion multiplication! The rotation from $\mathbf{v}_1$ to $\mathbf{v}_2$ ought to work as follows: $\mathbf{v}_2=q\mathbf{v}_1q^{-1}.$ Here I'm going to refer to the Wolfram Language (Mathematica), as implemented on the Wolfram Dev Platform. We use the following code:

<

Mathematica produces the answer $\operatorname{Quaternion}\left[0,0,\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}\right]$

Notice here we must use the NonCommutativeMultiply function to get the correct quaternion multiplication. Also notice that for a unit quaternion (which rotation quaternions are), $q^{-1}=\overline{q}$. Finally, notice that we must "quaternion-ify" the vector $\mathbf{v}_1$ as the quaternion $(0,v_{1x},v_{1y},v_{1z})$, and the result is a quaternion which we can "vector-ify" by extracting the last three components. The result, as you can see, is correct.

If you prefer to have the rotation matrix, you can get such an $\mathbf{R}$ as explained on the rotation quaternion wiki page under the section "Quaternion-derived rotation matrix".

1

I interpret the problem statement to mean that we are allowed to specify rotations only around the three orthogonal coordinate axes, and may not rotate around any other axis.

I will also assume we always want to be able to move from one point to the other in no more than two rotations. The problem is almost trivially easy if we are allowed three rotations.

Let the starting point be $(x_1,y_1,z_1)$ and the desired ending point be $(x_2,y_2,z_2).$ We consider the six planes through those two points parallel to the coordinate planes, that is, the six planes whose equations are respectively $x = x_1,$ $y = y_1,$ $z = z_1,$ $x = x_2,$ $y = y_2,$ and $z = z_2.$ These planes partition three-dimensional space into $27$ compartments, including a parallelepiped (rectangular box) of which $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ are diagonally opposite vertices.

A suitable rotation around the $x$ axis can put the image of $(x_1,y_1,z_1)$ anywhere on the circle in the plane $x = x_1$ that is centered on the $x$-axis and passes through $(x_1,y_1,z_1).$ Suppose that circle intersects the circle in the plane $y = y_2$ that is centered on the $y$-axis and passes through $(x_2,y_2,z_2),$ and suppose $(x_3,y_3,z_3)$ is a point of intersection of those two circles. Observe that since one circle lies entirely in the plane $x = x_1$ and the other lies entirely in the plane $y = y_2,$ it must be that $x_3 = x_1$ and $y_3 = y_2.$ Then we can rotate around the $x$-axis to put the image of $(x_1,y_1,z_1)$ at $(x_1,y_2,z_3),$ after which we can rotate around the $y$-axis so that the image of $(x_1,y_2,z_3)$ is $(x_2,y_2,z_2).$ If there is a second distinct point of intersection of the two circles, $(x_1,y_2,z_4),$ then there is another sequence of rotations about the $x$- and $y$-axes that take $(x_1,y_1,z_1)$ to $(x_1,y_2,z_4),$ and then to $(x_2,y_2,z_2).$

In order for us to be able to do the two particular rotations described in the previous paragraph, it is sufficient that the sphere intersects the line given by the pair of equations $x = x_1, y = y_2.$ The number of intersections with that line gives the number of intersections of the two circles. There are a total of six lines (call them $L_1,$ $L_2,$ $L_3,$ $L_4,$ $L_5,$ and $L_6$) given by pairs of equations where the first equation is one of the equations $x = x_1,$ $y = y_1,$ or $z = z_1$ and the second equation is one of the equations $x = x_2,$ $y = y_2,$ or $z = z_2$; provided that the sphere intersects at least one of those lines, some variation of the procedure given in the previous paragraph will take $(x_1,y_1,z_1)$ to $(x_2,y_2,z_2)$ in just two rotations.

To show that the sphere must intersect at least one of the six lines $L_i, 1\leq i\leq 6,$ consider the plane through the four points $(x_1,y_1,z_1),$ $(x_2,y_2,z_2),$ $(x_1,y_1,z_2),$ and $(x_2,y_2,z_1).$ The sphere intersects that plane in a circle that passes through the points $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2).$ At least one of the points $(x_1,y_1,z_2)$ and $(x_2,y_2,z_1)$ lies inside or on that circle, and therefore is inside or on the sphere. The sphere therefore intersects the lines $x = x_1, z = z_2$ and $y = y_1, z = z_2,$ or the lines $x = x_2, z = z_1$ and $y = y_2, z = z_1,$ or all four lines.

The number of distinct ways that we can transform $(x_1,y_1,z_1)$ to $(x_2,y_2,z_2)$ by two rotations around the coordinate axes is equal to the number of distinct intersections of the sphere with the six lines $L_i, 1\leq i\leq 6.$ (A point at the intersection of two of these lines and the sphere counts as one intersection.) The solution is never unique, because (as already seen) at least two of the lines $L_i, 1\leq i\leq 6$ intersect the sphere, and it is not possible for the sphere to be tangent to both lines at one point; hence the two lines give at least two points of intersection, each of which gives a different pair of rotations about the coordinate axes.