0

I am trying to understand rotations, and I need to understand what it takes to rotate vectors from a certain position on the unit sphere to another.

Let's say I am on $p=e_x$ and I want to go to $p'=\frac{1}{\sqrt{3}}(e_x + e_y + e_z)$.

If I want to go from $e_x$ to $e_x + e_y$, I can set up the unit vector $u = e_z$, and the quaternion $q_1 = \cos (\pi/8) + \sin (\pi/8) (0 i + 0j + 1k)$ and perform $p'' = q_1pq_1'$ where $p'' = 0 + 1/\sqrt{2}i+1/\sqrt{2}j+0k$.

How do I go from $p''$ to $p'$? How does one solve this inverse problems of rotation, where I have to go from $(\theta_1, \phi _1)$ to $(\theta _2, \phi _2)$?

Any advice you have would be appreciated!

megamence
  • 299

4 Answers4

1

A simple way to find the rotation matrix is using a geometric approach.

In 2D you can express a vector $(r, \theta)$ (in polar coordinates) in cartesian basis $(e_x, e_y)$ as:

$$v' = r \cos \alpha \ e_x + r \sin \alpha \ e_y$$

$r = \|v'\|$

$\alpha = \cos^{-1}(\frac{v' \cdot e_x}{r})$

Since $e_y$ is a 90 degree rotation of $e_x$ we can rewrite the vector as:

$$v' = r \cos \alpha \ e_x + r \sin \alpha \ R_{90} e_x$$

Where $R_{90}$ is a rotation matrix that rotates a vector 90 degrees.

Now, instead of expressing $v'$ in the canonical basis $(e_x, e_y)$ we can change the basis to other orthonormal basis, say $(v, R_{90} v)$. Assumming $r = 1$.

$$v' = \cos \theta \ v + \sin \theta \ R_{90} v$$

Where

$\theta = \cos^{-1}(v' \cdot v)$

In 3D one can do the same.

$$v' = \cos \theta \ v + \sin \theta \ \frac{(v \times v') \times v}{\|v \times v'\|}$$

We can simplify this since:

$\cos \theta = v' \cdot v$

$\sin \theta = \|v \times v'\|$

Then

$$v' = (v' \cdot v) \ v + (v \times v') \times v$$

We can express in matrix form as:

$$v' = ((v' \cdot v) \ I + [v \times v']_{\times}) v$$

Where $I$ is the identity matrix and $[v \times v']_{\times}$ is the cross product matrix of the vector $v \times v'$. So we can write:

$$v' = R v$$

$$R = (v' \cdot v) \ I + [v \times v']_{\times}$$

And that is the rotation matrix you are looking for. Just need to compute one dot product and one cross product of the input unit vectors. No need to compute $\sin$ and $\cos$ explicitly.

The above expression agrees with the Euler-Rodrigues formula i.e., the Euler-Rodrigues reduces to the formula we derived when $v$ and $v'$ are two vectors in the same plane i.e., orthogonal to the rotation axis (see https://en.m.wikipedia.org/wiki/Euler%E2%80%93Rodrigues_formula)

The Euler-Rodrigues formula is the folowing:

$$v' = v + 2 a \ w \times v + 2 \ w \times (w \times v)$$

Where in our case:

$a = \cos \frac{\theta}{2}$

$w = \sin \frac{\theta}{2} \ \frac{v \times v'}{\|v \times v'\|}$

If you replace those $a$ and $w$ and apply some trig identities you will get the expression we derived.

If you are familiar with quaternions you will find this familiar as the parameter for Euler-Rodrigues formula agree with unit quaternion's components.

1

We want to rotate $p = e_x$ to $p' = \frac1{\sqrt 3}(e_x+e_y+e_z)$. If we're using quaternions, the most useful way to formulate this rotation is with the exponential function: $$ v \mapsto e^{\theta P/2}ve^{-\theta P/2}. $$ Here, $v$ is any vector represented as an imaginary quaternion, $\theta$ is the angle between $p$ and $p'$, and $P$ is a unit imaginary quaternion representing the plane containing $p, p'$. The components of $P$ are the components of $\frac{p\times p'}{|p\times p'|}$, i.e. the unit normal of the plane of $p,p'$. Since $P^2 = -1$, this works just like it does with complex numbers: $$ e^{\theta P/2} = \cos\theta/2 + P\sin\theta/2. $$ We could compute $\theta$ from $p\cdot p' = \cos\theta$, but alternatively we could use the half-angle formulas $$ \cos\theta/2 = \pm\sqrt{\frac12+\frac12p\cdot p'},\quad \sin\theta/2 = \pm\sqrt{\frac12-\frac12p\cdot p'}. $$ Since $0\leq\theta < \pi$ is the angle between $p,p'$ we always choose $+$ for both. Then $$ p\cdot p' = \frac1{\sqrt 3},\quad P = \frac1{\sqrt2}(-j + k), $$ so we see that the rotation quaternion is $$\begin{aligned} q &= e^{\theta P/2} = \sqrt{\frac{\sqrt3+1}{2\sqrt3}} + \sqrt{\frac{\sqrt3-1}{2\sqrt3}}\frac1{\sqrt2}(-j + k) \\ &= \sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(-j + k) \end{aligned}$$ with $e^{-\theta P/2} = \bar q$ (the conjugate of $q$). We can then confirm that $$\begin{aligned} qp\bar q &= \left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(-j + k)\right]i\left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(j - k)\right] \\ &= i\left[\sqrt{\frac{3+\sqrt3}6} + \sqrt{\frac{3-\sqrt3}6}\frac1{\sqrt2}(j - k)\right]^2 \\ &= i\left[\frac{3+\sqrt3}6 + 2\frac{\sqrt{(3+\sqrt3)(3-\sqrt3)}}6\frac1{\sqrt2}(j-k) - \frac{3-\sqrt3}6\right] \\ &= i\left[\frac1{\sqrt3} + \frac1{\sqrt3}(j-k)\right] \\ &= \frac1{\sqrt3}(i + j + k). \end{aligned}$$


In the same way, we can see that to go from $p'' = \frac1{\sqrt2}(j + k)$ to $p' = \frac1{\sqrt3}(i + j + k)$ we need $$ \cos\theta' = p''\cdot p' = \frac2{\sqrt 6},\quad P' = \frac1{\sqrt2}(j - k),\quad $$$$\begin{aligned} q' &= e^{\theta'P'/2} = \sqrt{\frac{\sqrt6+2}{2\sqrt6}} + \sqrt{\frac{\sqrt6-2}{2\sqrt6}}\frac1{\sqrt2}(j-k) \\ &= \sqrt{\frac{3+\sqrt6}6} + \sqrt{\frac{3-\sqrt6}6}\frac1{\sqrt2}(j-k), \end{aligned}$$ and of course we achieve this rotation by $v \mapsto q'v\bar q'$.

0

You can use a Housholder transformation to reflect $p$ to $p'$. As a vector $v_1$ perpendicular to the reflection hyperplane you can take the normalization of $p-p'$. Then find any vector $v_2$ orthogonal to $p'$ (e.g. by Gram-Schmidt) and reflect about the hyperplane perpendicular to $v_2$. The composition of these to reflections will be a rotation mapping $p$ to $p'$.

Thomas Preu
  • 2,084
0

Here is yet another way to do this via the orthogonal group and its Lie algebra of skew-symmetric matrices. However, one must recognise that in practice the approach above via quaternion seems to involve less computation. We will calculate a few scalar products, then form matrices and multiply them together.

Suppose you have two unit vectors $p,q\in \mathbb{S}^{n-1}$ in $\mathbb{R}^n$ and want to rotate $p$ onto $q$. I will specialise to $n=3$ and your concrete examples below but let's do the general case first. Let's fix the notation that $\theta$ is the angle between the two vectors, i.e. $\cos\theta = \langle p,q\rangle$.


Case 1: $p=\pm e_n$

You can represent \begin{equation*} q = \cos(\theta) e_{n} + \sin(\theta) \begin{pmatrix} \bar{u} \\ 0 \end{pmatrix} = \begin{pmatrix} \sin(\theta)\bar{u} \\ \cos(\theta) \end{pmatrix} \in\mathbb{R}^{n} \end{equation*} for some unit vector $\bar{u}\in \mathbb{S}^{n-2}$. In fact, we can calculate $\bar{u}$ by projecting $q$ onto the $(e_1-\ldots-e_{n-1})$-plane and then normalising, i.e. \begin{equation*} \bar{u} = \frac{\sum_{i=1}^{n-1} \langle q, e_i\rangle e_i}{\big\|\sum_{i=1}^{n-1} \langle q, e_i\rangle e_i\big\|}. \end{equation*} Let \begin{equation*} X = \begin{pmatrix} 0 & \theta \bar{u} \\ -\theta \bar{u}^{T} & 0 \end{pmatrix} \in \mathfrak{o}(n). \end{equation*} We will not manually use this matrix later but I left it here to maybe help undestand where the next magic matrix comes from. For the record, the matrix $\tfrac{1}{\theta}X$ is the infinitesimal direction in the tangent space of $\operatorname{O}(n)$ in which we need to follow the geodesic from $e_n$ to $q$. The parameter $\theta$ tells us "how far we need to travel" that geodesic.

Using the exponential map (here it is just defined via its power series) we can calculate that \begin{equation*} Q = \exp(X) = \begin{pmatrix} \big(\operatorname{Id}_{n-1} - \bar{u}\otimes \bar{u}\big)+\cos(\theta)\bar{u}\otimes \bar{u} & \sin(\theta) \bar{u} \\ -\sin(\theta) \bar{u}^{T} & \cos(\theta) \end{pmatrix} \in \operatorname{O}(n) \end{equation*} and, in fact, $q=Qp = Qe_n$.


Case 2: $p\neq \pm e_n$

We can reduce this case to the previous one by rotating $p$ to $e_n$ first. Following the above steps, we obtain the rotation \begin{equation*} Q_{0} = \exp(X_{0}) = \begin{pmatrix} \big(\operatorname{Id}_{n-1} - \bar{u}_{0}\otimes \bar{u}_{0}\big)\cos(\theta_{0})\bar{u}_{0}\otimes \bar{u}_{0} & \sin(\theta_{0}) \bar{u}_{0} \\ -\sin(\theta_{0}) \bar{u}_{0}^{T} & \cos(\theta_{0}) \end{pmatrix} \in \operatorname{O}(n) \end{equation*} where $\theta_{0} = \arccos \langle p, e_n\rangle$ and $\bar{u}_{0}\in\mathbb{S}^{n-2}$ is as above. Then, by Case 1, $p = Q_{0}e_n$, i.e. $e_n = Q_{0}^Tp$.

Now rotate also the point $q$ by (the inverse of) this initial rotation and define $q^\prime = Q_{0}^Tq$. Notice that $\langle e_n, q^\prime\rangle = \langle p, q\rangle = \cos\theta$ because $Q_{0}$ is an orthogonal matrix.

Once again we are reduced to Case 1 by now rotating $e_n$ to $q^\prime$. We obtain \begin{equation*} Q = \exp(X) = \begin{pmatrix} \big(\operatorname{Id}_{n-1} - \bar{u}\otimes \bar{u}\big)+\cos(\theta)\bar{u}\otimes \bar{u} & \sin(\theta) \bar{u} \\ -\sin(\theta) \bar{u}^{T} & \cos(\theta) \end{pmatrix} \in \operatorname{O}(n) \end{equation*} where we carefully recalculated $\bar{u}\in\mathbb{S}^{n-2}$ by the same formula but using $q^\prime$ instead of $q$.

Having done all of this, we see that $Q_{0}^Tq = q^\prime = Qe_n = QQ_{0}^Tp$ and thus $R=Q_{0}QQ_{0}^T$ is the rotation which rotates $p$ onto $q$, i.e. \begin{equation*} q = Q_{0}QQ_{0}^Tp. \end{equation*}


Concrete example for $n=3$

Let $p = \begin{pmatrix} \tfrac{1}{\sqrt{2}} \\ \tfrac{1}{\sqrt{2}} \\ 0 \end{pmatrix}$ and $q = \begin{pmatrix} \tfrac{1}{\sqrt{3}} \\ \tfrac{1}{\sqrt{3}} \\ \tfrac{1}{\sqrt{3}} \end{pmatrix}$. Then $\theta_{0} = \arccos \langle p, e_3\rangle = \tfrac{\pi}{2}$ and $\bar{u}_{0} = \begin{pmatrix} \tfrac{1}{\sqrt{2}} \\ \tfrac{1}{\sqrt{2}} \end{pmatrix}$. Thus, \begin{equation*} Q_{0} = \begin{pmatrix} \tfrac{1}{2} & -\tfrac{1}{2} & \tfrac{1}{\sqrt{2}} \\ -\tfrac{1}{2} & \tfrac{1}{2} & \tfrac{1}{\sqrt{2}} \\ -\tfrac{1}{\sqrt{2}} & -\tfrac{1}{\sqrt{2}} & 0 \end{pmatrix}. \end{equation*} For sanity, you may check that $Q_{0}$ is orthogonal and maps $e_3$ to $p$. Now let's calculate $q^\prime = Q_{0}^Tq = \begin{pmatrix} -\tfrac{1}{\sqrt{6}} \\ -\tfrac{1}{\sqrt{6}} \\ \tfrac{2}{\sqrt{6}} \end{pmatrix}$.

We now need to use the above procedure to get $Q$. Remember that for this we need $\theta = \arccos \langle e_3, q\rangle = \arccos \langle p, q\rangle = \arccos \tfrac{2}{\sqrt{6}}$. We also need to calculate $u$ by projecting $q^{\prime}$ onto the $(e_1-e_2)$-plane and normalising, i.e. $\bar{u} = \begin{pmatrix} -\tfrac{1}{\sqrt{2}} \\ -\tfrac{1}{\sqrt{2}} \end{pmatrix}$. Plugging this into the expression for $Q$, we obtain \begin{equation*} Q = \begin{pmatrix} \frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{\sqrt{6}} \\ -\frac{1}{2}+\frac{1}{\sqrt{6}} & \frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{\sqrt{6}} \\ \frac{1}{\sqrt{6}} & \frac{1}{\sqrt{6}} & \tfrac{2}{\sqrt{6}} \end{pmatrix}. \end{equation*} Finally, we can find the rotation we are looking for: \begin{equation*} R = Q_{0}QQ_{0}^T = \begin{pmatrix} \frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{\sqrt{6}} \\ -\frac{1}{2}+\frac{1}{\sqrt{6}} & \frac{1}{2}+\frac{1}{\sqrt{6}} & -\frac{1}{\sqrt{6}} \\ \frac{1}{\sqrt{6}} & \frac{1}{\sqrt{6}} & \tfrac{2}{\sqrt{6}} \\ \end{pmatrix}. \end{equation*} You may want to manually check that indeed $q= Rp$.

In this special case $R$ happens to coincide with $Q$ but in general this is not true!

Sven Pistre
  • 1,390
  • 9
  • 24