How to estimate rotation matrix.

633 Views Asked by At

I have a three dimensional vector say $ A =[a_1,a_2,a_3]$. I want a rotational matrix $R$ to project this to a vector $[0,0,1]$; This means the rotation matrix $R$ is such that $RA=[0,0,1]$. I need to estimate the rotation matrix $R$ from the vector $A$, this means the element of the rotation matrix needs to be linear combination of $a_1,a_2, a_3$. Any suggestion would be helpful.

2

There are 2 best solutions below

2
On BEST ANSWER

I'm not sure if this meets all of your robustness requirements, but this is what I came up with:

To rotate a vector $A$ so that its tip is aligned with the positive $z$-axis, we can make use of the following rotation matrices about the coordinate axes: \begin{align} R_z(\theta) &= \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \\ R_y(\phi) &= \begin{bmatrix} \cos \phi & 0 & \sin \phi \\ 0 & 1 & 0 \\ -\sin \phi & 0 & \cos \phi \end{bmatrix} \end{align} where $R_z(\theta)$ should be interpreted as rotating the $xy$-plane counter-clockwise by $\theta$ from the vantage point of the positive $z$-axis, and $R_y(\phi)$ should be interpreted as rotating the $xz$-plane counter-clockwise by $\phi$ from the vantage point of the positive $y$-axis.

Define $\theta$ and $\phi$ from $A = [a_1, a_2, a_3]$ like this: \begin{align} \theta &= \operatorname{atan2}(a_2,a_1) \\ \phi &= \cos^{-1}(a_3 / |A|) \end{align}

That is, $\theta$ is the counter-clockwise angle $A$ makes with positive $x$-axis when projected into the $xy$-plane, $\phi$ is the angle $A$ makes with the positive $z$-axis, and $|A|$ is the length of $A$. Given by $\sqrt{a_1^2 + a_2^2 + a_3^2}$

Note that although I employ a division here, it should be stable since $|A| \geq a_3$; that is, the denominator is not small compared to the numerator.

Then the rotation matrix you're looking for can be generated by the following composition: $$ R_z(\theta) \cdot R_y(-\phi) \cdot R_z(-\theta) $$ Intuitively, this revolves $A$ onto the $xz$-plane, then rotates it up so it's aligned with the positive $z$-axis, then twists $A$ in place so that it is back in its original orientation before being revolved onto the $xz$-plane.

When simplified, this composition yields $$ \begin{bmatrix} (\cos \phi - 1) \cos^2 \theta + 1 & (\cos \phi - 1)\cos \theta \sin \theta & -\sin \phi \cos \theta \\ (\cos\phi-1)\cos\theta \sin\theta & (1-\cos\phi)\cos^2\theta + \cos\phi & -\sin\phi \sin\theta \\ \sin\phi \cos\theta & \sin\phi \sin\theta & \cos\phi \end{bmatrix} $$

0
On

The axis of rotation is perpendicular to both $r$ and $1_z$ and is thus proportional to $s=1_z\times r$.

Now $r$ and $s$ form an orthogonal frame with $t:=r\times s$ (before rotation), and $1_z$ and $t$ form an orthogonal frame with $u:=u\times t$ (after rotation).

The rotation applies $r,s,t$ to $t,s,u$, so that the matrix is

$$[t,s,u][r,s,t]^{-1}.$$

To make it a true rotation matrix, normalize all columns. This avoids any trigonometry.