1

I need a little help.

I rotated the vector $s$ using the rotation matrix $R$ and got a new vector $S$.

Now I want to reconstruct the rotation matrix from vectors $s$ and $S$ using the Rodrigues formula.

https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula See Matrix Notation

The algorithm is standard: I calculate the angle between the vectors $\theta$, the axis of rotation $k$ and the rotation matrix $Q$ using the Rodrigues formula.

enter image description here

Resulting matrix $Q$ does not match the original one $R$. Why? Am I wrong somewhere?

dtn
  • 731
  • 1
  • 6
  • 19

2 Answers2

3

Given two vectors $s$ and $S$, there are multiple rotations taking $s$ to $S$. given $R$ such that $Rs=S$, we can choose any rotation $R'$ such that $R's=s$ and $RR'$ will also satisfy $(RR')s=S$.

More information is needed to uniquely determine the original rotation.

Edit: determining $R$ from two pairs of vectors

First, note that the cross product $\times$ is preserved up to sign by rotations: $$ R(u\times v)=\begin{cases} (Ru)\times(Rv) & R\text{ is a proper rotation} \\ -(Ru)\times(Rv) & R\text{ is an improper rotation} \end{cases} $$ Suppose we have vectors $s,t,S,T$ with $s,t$ linearly independent and we know that $Rs=S$ and $Rt=T$ for some rotation $R$. Since $s,t$ are linearly independent, $s,t,s\times t$ forms a basis for $\mathbb{R}^3$. The same is true of $S,T,S\times T$, since rotations preserve liner independence. Thus we have $$ R[s,t,s\times t]=[S,T,\pm S\times T] $$ where $[u,v,w]$ is the matrix whose columns are vectors $u,v,w$. Since bases form invertible matrices, we have $$ R=[S,T,\pm S\times T][s,t,s\times t]^{-1} $$ where choosing $+$ will give a proper rotation and choosing $-$ will give an improper rotation.

Kajelad
  • 14,951
  • what more information is required? – dtn Jul 10 '21 at 18:31
  • 1
    @dtn Anything which fixes this additional rotation $R'$. For instance, adding a second pair of vectors $t,T$, linearly independent from $s,S$ respectively, will result in only two possible rotations, one proper and one improper. Adding a third pair $u,U$ such that $s,t,u$ form a basis will uniquely determine $R$ among all rotations, proper and improper. – Kajelad Jul 10 '21 at 18:52
  • along with this vector there are two others, they are shifted relative to each other by 120 degrees and rotate simultaneously at the same angles. it turns out something like an inverted pyramid with apex in the center of coordinates. is this situation suitable? – dtn Jul 10 '21 at 18:58
  • 1
    @dtn I'm not quite sure what you're trying to describe here. If you have vectors $s,t,S,T$ such that $s,t$ are linearly independent, $Rs=S$, and $Rt=T$, then there are two possible values for $R$. – Kajelad Jul 10 '21 at 19:04
  • could you demonstrate with a simple computational example what you mean? apparently, I did not quite understand you correctly. – dtn Jul 10 '21 at 19:06
  • 1
    @dtn As a simple example, take$$s=\begin{pmatrix}1\0\0\end{pmatrix},\ \ \ t=\begin{pmatrix}0\1\0\end{pmatrix},\ \ \ S=\begin{pmatrix}-1\0\0\end{pmatrix},\ \ \ T=\begin{pmatrix}0\-1\0\end{pmatrix}$$There are exactly two rotations which take $s,t$ to $S,T$ respectively: a $180^\circ$ rotation about the $z$-axis and an inversion. – Kajelad Jul 10 '21 at 19:15
  • 1
    @dtn You can compute the two possibilities using cross products. I've added a section explaining the computation. – Kajelad Jul 10 '21 at 19:29
  • I think I'm starting to understand, but what will the formalism look like if we add one more pair of vectors? $s,t,z$ and $S,T,Z$ – dtn Jul 10 '21 at 19:32
  • 1
    In that case, you don't need to complete the bases using cross products, and can just use $R[s,t,u]=[S,T,U]$ and thus $R=[S,T,U][s,t,u]^{-1}$. – Kajelad Jul 10 '21 at 19:33
  • is the rotation matrix unique and true in this case? – dtn Jul 10 '21 at 19:35
  • 1
    @dtn Yes. Note that you have to assume a priori that there exists a rotation $R$ which takes $s,t,u$ to $S,T,U$, but under this assumption it is unique. – Kajelad Jul 10 '21 at 19:49
  • in my problem there are just three "initial vectors" and their three final positions are known and I just need to find such a matrix that transforms them from the initial to the final one. did you talk about this at the very beginning, about additional conditions? – dtn Jul 10 '21 at 19:54
  • I tested your method and it seems to work. I liked that apart from pairs of vectors, I don't need to know anything else. I didn't like it - if vectors have zero elements, sometimes the matrix is non-invertible. How can I get around this issue? https://ibb.co/yYXkdjZ – dtn Jul 11 '21 at 05:19
1

$ \def\m#1{\left[\begin{array}{r}#1\end{array}\right]} \def\s#1{{\sqrt #1}} \def\ss#1#2{{\sqrt\frac{#1}{#2}}} \def\o{{\tt1}} \def\tr{\operatorname{Tr}} $Your main problem is that you did not calculate the correct axis-angle!

The unit vector representing the axis should be unaffected by the rotation matrix, however multiplying your $k$ vector by the $R$ matrix yields $$\eqalign{ R\cdot k &= \m{0.354 & 0.612 & 0.707 \\ 0.354 & 0.612 & -0.707 \\ -0.866 & 0.500 & 3.062e{-17}}\cdot\m{0.707 \\ 0.707 \\ 0.000} = \m{0.683 \\ 0.683 \\ -0.259} \ne k \\ }$$ The correct axis-angle are $$\eqalign{ \theta &= 1.5878, \qquad k &= \m{ 0.60364 \\ 0.78668 \\ -0.12943} \\ }$$ The Rodrigues formula with these parameters will reproduce the rotation matrix.

The other problem that you're fighting is round-off error in the rotation matrix itself.
The exact rotation matrix is $$ R = \frac 14\m{ \s{ 2}&\s{6}& \s{8} \\ \s{ 2}&\s{6}&-\s{8} \\ -\s{12}&\s{4}& 0 \\ }\\ $$ The most reliable way to obtain the axis is to calculate the Eigenvalue decomposition of $R$. It will have one real eigenvalue (equal to unity) and two imaginary eigenvalues (conjugate pairs). The eigenvector corresponding to unity is the axis of rotation.

The angle can be reliably calculated using the simple formula $$\theta = \operatorname{acos}\left(\frac{\tr(R)-\o}{2}\right)\\$$


Update

Here's a way to compute the axis of rotation which doesn't require an Eigenvalue Decomposition.

$$\eqalign{ {\tt(1)}\quad &\lambda &= \tr(R) - \o \\ {\tt(2)}\quad &s &= \{random\;vector\} \\ {\tt(3)}\quad &v &= \left(R^T+R-\lambda I\right)s \\ {\tt(4)}\quad &{\rm if}&\,v\approx 0,\;{\rm goto\,step\,}{\tt(2)} \\ {\tt(5)}\quad &k &= \frac{\pm v}{\|v\|} \\ }$$ You can choose $s=\m{0\\0\\1}$ in Step $(\tt2)$, if you wish.

greg
  • 35,825
  • thanks for the answer! tell me, is it possible to calculate the axis-engle, knowing only the vectors? if not, what is required besides the two vectors? – dtn Jul 11 '21 at 03:48
  • 1
    @dtn Yes, it's possible. I updated the answer to outline such a method. – greg Jul 11 '21 at 11:33
  • Thank you for your qualified and clear answer. I see that you are proposing an iterative procedure. But it was not possible to get away from the matrix R in this method. I would like to see a way that assumes knowledge of only two vectors, well, or a basis of three initial vectors and three final ones, as it is done in another answer. – dtn Jul 11 '21 at 12:09
  • 1
    @dtn It's not iterative. In fact, it's quite rare to obtain $v=0$ for an arbitrary $s$ vector. So at most two iterations are needed, but usually a single pass will suffice. – greg Jul 11 '21 at 12:55
  • 1
    @dtn As for your idea to eliminate $R$, given an orthonormal vector pair ${u,v}$, the following matrix will rotate between them $$\eqalign{ R &= I + (vu^T-uv^T) - (uu^T+vv^T) \ Ru &= v,\quad R^Tv = u \ }$$ You should also read this question. – greg Jul 11 '21 at 13:17