2

I originally wanted to derive a general rotation matrix that can transform a given 3-vector into another specified 3-vector of equal length. In failing to do so, I derived a matrix that contains information about the axis and angle of rotation. I wanted to share my matrix and ask for confirmation that such a matrix can always be found for two equal length nonzero 3-vectors.

Although my matrix is not a rotation matrix, I find my matrix to be valuable for its ease of use, especially in comparison to the standard method, or Rodrigues' rotation formula.

Let $\vec{u} = (x,y,z), \vec{v}=(p,q,r)$ . Then the relationship between $\vec{u}$ and $\vec{v}$ can be expressed as $$ \frac{1}{d} \begin{bmatrix} d\cos\theta & -c\sin\theta & b\sin\theta \\c\sin\theta & d\cos\theta & -a\sin\theta \\\ -b\sin\theta & a\sin\theta & d\cos\theta\end{bmatrix} \begin{bmatrix} p \\\ q \\\ r\end{bmatrix}=\begin{bmatrix} x\\y\\z\end{bmatrix} $$ where $d=\sqrt{a^2+b^2+c^2}$, $(a,b,c)$ is orthogonal to the plane containing $\vec{u}$ and $\vec{v}$, and $\theta$ is the angle between $\vec{u}$ and $\vec{v}$.

My derivation is as follows:

Let $\vec{v}=(p,q,r)$ be a non-zero 3-vector. Pick a unit vector $\vec{a}=(a,b,c)$ orthogonal to it.

Then $(x,y,z)=\vec{v}\cos(\theta)+\vec{a}$x$\vec{v}\sin(\theta)$

So

$ \begin{bmatrix} p\cos(\theta) \\\ q\cos(\theta) \\\ r\cos(\theta)\end{bmatrix}+ \begin{bmatrix} (br-cq)\sin(\theta) \\\ (cp-ar)\sin(\theta)\\\ (aq-bp)\sin(\theta)\end{bmatrix}=\begin{bmatrix} x\\y\\z\end{bmatrix} $

I should add that since learning about Rodrigues' rotation formula I now understand how to derive the general rotation matrix that I originally set out to derive.

Simon M
  • 1,037
  • Your thoughts? Hint: $(a,b,c)$ is the cross product of $u$ and $v$. – Kurt G. Aug 01 '23 at 07:03
  • @KurtG. I'm aware. Is the matrix correct? If not, what have I done wrong? – Simon M Aug 01 '23 at 07:06
  • Shall I solve your homework? Show (with whatever technique you are aware of) if / if not that matrix is correct. – Kurt G. Aug 01 '23 at 07:08
  • 2
    @KurtG. It's not homework. I want to derive the general rotation matrix to get from one 3-vector to another 3-vector. I'm doing this for fun and mathematical curiosity. My derivation is simple: define a unit vector t in the direction of v and a unit vector T in the direction of the cross product (a,b,c) x t. tcos(theta)+Tsin(theta) = u/length(u). This expression can then be turned into the 3x3 matrix above by observing that the terms in the expression are linear combinations of the components of v. – Simon M Aug 01 '23 at 07:28
  • There is one exception- a pair of vectors which some of your formula breaks down. Hint: what vector has no direction defined for it? Modifying how the original question is stated should compensate. – nickalh Aug 01 '23 at 08:04
  • @nickalh you mean where both of the vectors are the zero vector? – Simon M Aug 01 '23 at 08:06
  • Yes, adding the word "distinct" vectors, u and v should prevent that breaking your formula. Obviously, if u = 0 = v, then u & v are not distinct. – nickalh Aug 01 '23 at 08:08
  • @nickalh Assuming my matrix is correct, would it be a less computationally taxing alternative to the "standard method" R = I + (\sin\theta) K+(1-\cos\theta)K^2 ? Personally, I like my matrix a lot better – Simon M Aug 01 '23 at 08:13
  • You have rushed to put your "solution" out into the body of the Question and omitted the important context largely supplied by your longish Comment above. There are important applications for orthogonal matrices $M$, i.e. "general rotation matrix" of determinant $1$, that transform one vector to another (necessarily of equal length). Please edit the body of your Question to more clearly setup the problem and your interest in it, even if this is "for fun and mathematical curiosity." – hardmath Aug 09 '23 at 16:15

1 Answers1

2

The standard method to find a rotation matrix that rotates a vector $u$ into $v$ is:

Take as rotation

  • axis $\omega$ the cross product between $u$ and $v\,,$

  • angle $\theta$ the angle between $u$ and $v\,.$

Form the cross product matrix $K$ of $\omega\,.$

Write the rotation matrix as $$ R = I + (\sin\theta) K+(1-\cos\theta)K^2\,. $$

  • Your favourite matrix in OP is not a rotation matrix because its determinant is $\color{red}{\cos\theta}$ which is not always one.

  • To check if your matrix really maps $\vec{v}$ into $\vec{u}$ let's assume for simplicity that these vectors have length one. The rotation axis is the cross product $\vec{v}\times\vec{u}\,:$ $$ \begin{pmatrix}a\\b\\c\end{pmatrix}= \begin{pmatrix}p\\q\\r\end{pmatrix}\times \begin{pmatrix}x\\y\\z\end{pmatrix}= \begin{pmatrix}qz-ry\\ rx-pz\\ py-qx \end{pmatrix} $$ whose length $d$ is $\sin\theta\,.$ Thus, $\frac{\sin\theta}{d}=1\,.$ We also use the scalar product $\vec{v}\cdot\vec{u}\,:$ $$ \cos\theta=xp+yq+zr\,. $$ Let's call your matrix $M\,.$ Then $M\vec{v}$ has the first component \begin{align}\require{cancel} p\cos\theta-c\,q+b\,r&=xp^2+\cancel{ypq+zpr}+xq^2\cancel{-ypq-zpr}+xr^2\\ &=x(p^2+q^2+r^2)=x\,. \end{align} The other components are verified similarly.

  • Conclusion: Your matrix maps two particular vectors $\vec{v},\vec{u}$ into each other but is neither a rotation nor a reflection. In particular it is not length preserving and not angle preserving.

  • To figure out what matrix $M$ is we assume w.l.o.g. that $\vec{u},\vec{v}$ are in the $xy$-plane. Then their cross product is $$ \begin{pmatrix}0\\0\\\sin\theta\end{pmatrix} $$ and the matrix simplifies to $$ M=\begin{pmatrix} \cos\theta &-\sin\theta&0\\ \sin\theta&\cos\theta&0\\ 0&0&\color{red}{\cos\theta}\end{pmatrix}\,. $$ This is obviously a rotation around the $z$-axis by the angle $\theta$ followed (or preceded) by a compression of the $z$-direction by the factor $\color{red}{\cos\theta}\,.$

Kurt G.
  • 17,136
  • Just what I needed. Thanks – Simon M Aug 01 '23 at 07:49
  • What does my matrix represent, and why does it successfully get me from one vector to the other? Is it a rotation combined with a scaling factor of cos(theta)? – Simon M Aug 02 '23 at 07:12
  • I am not even sure if that lovely matrix maps $\vec{v}$ to $\vec{u},.$ I tried numerical examples without success. Happy to be convinced otherwise. Can you show it by performing the matrix multiplication? Regarding your second question: matrices that preserve Euclidean lengths also preserve Euclidean angles and must either be rotations or reflections. The determinant must be $\pm 1,.$ Regarding the scaling factor $\cos\theta,:$ divide by it and see if you get a rotation. – Kurt G. Aug 02 '23 at 07:14
  • https://www.wolframalpha.com/input?i2d=true&i=%7B%7Bcos%5C%2840%290.6423%5C%2841%29%2C-Divide%5B4Sqrt%5B20%5D-2Sqrt%5B3%5D%2C29%5D%2CDivide%5B2Sqrt%5B6%5D-3Sqrt%5B20%5D%2C29%5D%7D%2C%7BDivide%5B4Sqrt%5B20%5D-2Sqrt%5B3%5D%2C29%5D%2Ccos%5C%2840%290.6423%5C%2841%29%2C-Divide%5B3Sqrt%5B3%5D-4Sqrt%5B6%5D%2C29%5D%7D%2C%7B-Divide%5B2Sqrt%5B6%5D-3Sqrt%5B20%5D%2C29%5D%2CDivide%5B3Sqrt%5B3%5D-4Sqrt%5B6%5D%2C29%5D%2Ccos%5C%2840%290.6423%5C%2841%29%7D%7D%7B%7BDivide%5BSqrt%5B20%5D%2CSqrt%5B29%5D%5D%7D%2C%7BDivide%5BSqrt%5B3%5D%2CSqrt%5B29%5D%5D%7D%2C%7BDivide%5BSqrt%5B6%5D%2CSqrt%5B29%5D%5D%7D%7D – Simon M Aug 02 '23 at 07:22
  • Please don't expect me to unravel that. – Kurt G. Aug 02 '23 at 07:29
  • It's a successful numerical example. What ambiguity is there? – Simon M Aug 02 '23 at 07:32
  • Give me two equal length 3-vectors and I'll come back with a verification that the matrix works – Simon M Aug 02 '23 at 07:35
  • let's test out (p,q,r)=(1,0,0), (a,b,c)=(0,0,1), and theta = 90 degrees. The matrix indeed gives me that (x,y,z) must be (0,1,0) – Simon M Aug 02 '23 at 07:38
  • I can't imagine why any numerical examples would've failed as long as you were making sure to pick an (a,b,c) that's orthogonal to your chosen (p,q,r) – Simon M Aug 02 '23 at 07:40
  • We are messing around. The mathematical way to show $M\vec{v}=\vec{u}$ I have outlined in another update of the answer. Please proceed along those lines. – Kurt G. Aug 02 '23 at 08:00
  • I'm unsure what to do about the discrepancy, but can I request that we shift the focus to justifying the derivation of my matrix? I didn't pull the matrix out of nowhere; it follows from the geometric construction of u from components of v – Simon M Aug 02 '23 at 08:14
  • You cannot request that I further check your work. It is time now to do maths. I showed how this works. – Kurt G. Aug 02 '23 at 08:17
  • I'll update the post with a full breakdown of my reasoning for the matrix, complete with exact calculations – Simon M Aug 02 '23 at 08:19
  • @SimonM after flipping the sign of the cross product it is true that $M\vec{v}=\vec{u}$ *but* see my *Conclusion*. – Kurt G. Aug 02 '23 at 08:55
  • This conclusion is exactly what I was wondering about. I now think I understand what I was previously failing to. Thanks for elucidating – Simon M Aug 02 '23 at 08:58
  • You are welcome. We both learned something. – Kurt G. Aug 02 '23 at 08:59
  • Did you previously believe that in order for a matrix to map a vector to an equal length vector then the matrix must have determinant +1 or -1? That's what I thought at first – Simon M Aug 02 '23 at 09:01
  • No. When we have two particular vectors the matrix can be more general. Yours is an example. When we require length preserving for all vectors it can only be a rotation or reflection. I think I said this a couple of times today. – Kurt G. Aug 02 '23 at 09:06
  • If I divide the matrix by (cos(theta))^1/3, then the determinant would be 1. Would this new matrix be a rotation? – Simon M Aug 02 '23 at 09:17
  • A rotation matrix has to have orthogonal columns and rows. Have you checked that ? – Kurt G. Aug 02 '23 at 09:48
  • Just checked. The columns and rows are not orthogonal. I guess it's not a rotation. – Simon M Aug 02 '23 at 09:56
  • I know this much about how to geometrically interpret the (original, unscaled) matrix: if you multiply a vector v by this matrix and that vector v happens to be orthogonal to (a,b,c), then the matrix will rotate v by an angle of theta about the axis (a,b,c). Aside from that, I'm completely lost. I'm curious as to what the matrix does to vectors that don't just conveniently happen to be orthogonal to (a,b,c) – Simon M Aug 02 '23 at 10:00
  • So the matrix rotates the vector by an angle of theta about the axis (a,b,c) as well as scales in the (a,b,c) direction. That would explain why all it does to (a,b,c) is scale it by cos(theta). – Simon M Aug 03 '23 at 01:01