0

I want to rotate the vector (1.1, 0.1, 0.1) to align with the vector (1, 0, 0), and in general I want the formula to rotate one vector onto another. I'm aware of the Rodriguez formula for rotating a vector, but for my case I'm doing an animation so I want to visualize the 3 rotations separately one at a time, so I'm just trying to use the basic 3 rotation matrices. Before I can do that, I need to find the 3 angles between the two vectors corresponding to the x, y, and z rotation matrices.

The formula I found was to get their dot product, divide by their magnitudes, and then take the inverse cosine of that value, and that gives you the angle between the two vectors that I can use to rotate them. Since I'm doing 3 rotations I thought it made sense to do that for just the x, y, and z portions of the vector so I can get the angles I need to rotate them in x, y, and z.

With edge cases like rotating to (1, 0, 0) it doesn't work for the y or z portions because they're 0 so the dot product is obviously 0, which means I only have an x rotation and I'm missing the y and z rotations. Additionally, the signs of the angles don't seem to be right. I get the same results whether the angle is 90° to the left or 90° to the right, but in that case I'd want the angle 90°, and 270°. I'm guessing this is because the cos^-1 function goes from pi to 0, but I'm not sure how to account for this.

This page seemed to give the answer closest to what I want and shows it is possible, but obtaining the angles is the part I'm having trouble with.

infact
  • 3
  • You only need two rotations around axes. For example rotate $(1.1,0.1,0.1)$ around the $x$-axis to about $(1.1,0.14142,0)$ and then around the $z$-axis to about $(1.10905,0,0)$ – Henry Mar 27 '23 at 18:31
  • Hi @Henry , thanks for the comment, I completely forgot how rotations work for a second because I'm very tired, you're absolutely correct. I'd like to ask you how you obtained the first rotation about the x-axis? – infact Mar 27 '23 at 18:38
  • @theGrey's answer shows how to do it. $\begin{pmatrix} 1 & 0 & 0\ 0 &\cos(\frac\pi4)&-\sin(\frac\pi4)\ 0&\sin(\frac\pi4)&\cos(\frac\pi4)\end{pmatrix}$ works here – Henry Mar 27 '23 at 18:59
  • @theGrey's answer is probably what you requested. But since you mentioned visualization using animation, may I suggest to consider also Slerp (spherical linear interpolation, https://en.wikipedia.org/wiki/Slerp#Geometric_Slerp), which will transition from one vector to the other with constant angular velocity, in the shortest arc path. – Number Mar 27 '23 at 19:08

1 Answers1

2

If I understood correctly what you are asking, I think Givens rotations are the way to go.

Let $v = (v_1,v_2,v_3)$, we start by rotating $v$ onto the subspace spanned by $e_1,e_2$. We can operate directly on the last two coordinates: $w = (v_2,v_3)$, we seek a rotation matrix $\begin{pmatrix}c&-s\\ s& c\end{pmatrix}$ with $c =\cos\theta, s=\sin\theta$ for some angle $\theta$ which we don't even need to compute, such that $$\begin{pmatrix}c&-s\\ s& c\end{pmatrix}\begin{pmatrix}v_2\\ v_3\end{pmatrix}=\begin{pmatrix}||w||\\0\end{pmatrix}$$

(norm is preserved by orthogonal maps).

Solving the system you get $c =v_2/||w||, s=-v_3/||w||$, with those values you get

$$\begin{pmatrix} 1 & 0 & 0\\ 0 &c&-s\\ 0&s&c\end{pmatrix}\begin{pmatrix}v_1\\v_2\\v_2\end{pmatrix} = \begin{pmatrix}v_1\\ \sqrt{v_2^2+v_3^2} \\0\end{pmatrix}$$

Apply a similar argument to annihilate the second coordinate of the new vector.

Now what if you want to rotate a vector $v$ to align it with another arbitrary vector $u$? Recall that the matrices you are using are orthogonal, therefore easy to invert, you can rotate $v$ in $e_1$ and $e_1$ in $u$.

theGrey
  • 303