Let $\textbf{u} = (u_x,u_y,u_z)^T$ such that $\left\lVert \textbf{u} \right\rVert = 1$, and $\textbf{n} = (0,0,1)^T$. I'm trying to work out a rotation matrix $R$ such that

$$ \textbf{n} = R \textbf{u} $$

Given that $$ R = I + \sin(\theta)K + (1-\cos(\theta))K^2 $$

Where $K$ is the skew matrix built upon the rotation axis $\textbf{k}$. I'd do something like the following:

I'd exploit $\cos(\theta) = \textbf{n} \cdot \textbf{u} = u_z$, from there I can work out $\theta$, later I'd define $\textbf{k} = \textbf{u} \times \textbf{v}$. I'll stick these two into the Rodrigues formula and I should get $R$.

Is this procedure correct?


Figured out that since $u_z = \cos(\theta)$ we have $\sin(\theta) = \sqrt{1-u_z^2}$ therefore the rotation matrix is

$$ R = I + \sqrt{1-u_z^2} K + (1-u_z)K^2 $$


Your method is good, but the only remark that there are infinitely many rotations that transform one vector $\mathbf{u}$ into other vector $\mathbf{n}$ (see also derive quaternion from rotation matrix, via eigenvector for discussion about relationship of axis and value for rotation angle).
Method of Stijn should provide more solutions.

The other simple solution is for example to rotate about axis $ \mathbf{r}= \mathbf{u}+\mathbf{n}$ by the angle $\pi$ ( draw a picture and you'll see what I mean). If you want now to use Rodrigues formula, the vector $ \mathbf{r}$ requires normalization to unit length, name normalized vector $\hat{ \mathbf r}$.
For this case rotation matrix has a particularly simple form $R=2\hat{ \mathbf r}\hat{ \mathbf r}^T-I$.

The other more general method is to use the equation $N=RU$.
Matrix $N$ can be simply identity matrix $I$ - the last its column is just $\mathbf{n}$ vector, and $U$ is composed from the columns $[ \mathbf{u}_\perp \ \ \mathbf{u}×\mathbf{u_\perp} \ \ \mathbf{u}]$,
where $\mathbf{u}_\perp$ is any unit length vector perpendicular to $\mathbf{u}$.

In this case $I=RU$ and consequently $R=U^{−1}$.

Notice that here you have some degree of freedom in the choice of $\mathbf{u_\perp}$, one of them it can be normalized $\mathbf{n}×\mathbf{u}$.

  • $\begingroup$ by "good" you mean "correct"? $\endgroup$ – user8469759 Feb 13 '18 at 15:01
  • $\begingroup$ @user8469759 Yes, be only cautious with the sign of $\theta$ as $\cos\theta=u_z$ has two solutions $\pm\theta_z$. Check which value is correct. Of course as I've said there are many other rotation matrices that can transform one vector into the other. To have a single solution you need to have at least two non-collinear vectors transformed simultaneously.. $\endgroup$ – Widawensen Feb 13 '18 at 15:56
  • $\begingroup$ @user8469759 However the most straightforward method is to use for transformation $3$ linearly independent vectors ( for example you can take 3 orthogonal vectors to each otherl) , name them $n_1,n_2, n_3$ and appropriately $u_1,u_2, u_3$. Name matrices constructed from these vectors (as columns) $N$ and $U$. Then $N=RU$ and $R$ is simply $=NU^{-1}$. You can use this method also for your case - 1 vector transformed into 1 vector - extending artificially set of vectors.. $\endgroup$ – Widawensen Feb 13 '18 at 16:09
  • $\begingroup$ How about what I reported in my update? $\endgroup$ – user8469759 Feb 13 '18 at 16:39
  • $\begingroup$ @user8469759 Ok, only , $\sin(\theta)=-\sqrt{1-u_z^2}$ can also give $\cos(\theta)=u_z$ $\endgroup$ – Widawensen Feb 13 '18 at 16:43

I think you are on the right track in principle. However, there is what I believe to be a significantly simpler way to solve this problem.

Rotation matrices are orthogonal matrices with determinant equal to one. If we write the rotation matrix $R$ in the form $$R = \begin{pmatrix}{\bf r}_1^T \\ {\bf r}_2^T \\{\bf r}_3^T \end{pmatrix},$$ where ${\bf r}_1$, ${\bf r}_2$, and ${\bf r}_3$ are three vectors, the equations we want to solve reduce to $${\bf r}_1^T {\bf u} = {\bf r}_2^T {\bf u} = 0, \quad {\bf r}_3^T {\bf u} = 1.$$ In other words, we need to find two vectors ${\bf r}_1$ and ${\bf r}_2$ that are orthogonal to ${\bf u}$, and one vector ${\bf r}_3$ with inner product one with ${\bf u}$.

To make sure that $R$ is orthogonal, these three vectors need to be orthogonal to each other, and have length one. Doing so, $R$ is orthogonal, and its determinant will be $\pm1$. You can then always make sure it is equal to one, by interchanging what you call ${\bf r}_1$ and ${\bf r}_2$, since this flips the sign of the determinant of $R$.

This reduces the problem to some linear equations that you can easily solve. In particular, ${\bf r}_3$ you can just take to be ${\bf u}$, since $||{\bf u}||=1$.

  • $\begingroup$ I don't see you using the information of the $\textbf{n}$ vector. $\endgroup$ – user8469759 Feb 13 '18 at 15:03
  • $\begingroup$ The vector ${\bf n}$ has a one in its third component, which is what tells us ${\bf r}_3^T {\bf u} =1$, and the zeroes in ${\bf n}$ tell us ${\bf r}_1^T {\bf u} ={\bf r}_2^T {\bf u} =0$. In general, by writing $R$ as a set of three row vectors, doing the matrix multiplication we get the equations ${\bf r}_i^T {\bf u} = {\bf n}_i$, for $i=1,2,3$, where ${\bf n}_i$ denotes the $i$th component of ${\bf n}$. $\endgroup$ – Stijn Feb 13 '18 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.