Use a matrix to rotate a vector in the direction of another vector

223 Views Asked by At

I have two 3D vectors, say A and B, that are perpendicular to each other in an arbitrary plane in 3D space. A and B share origin point P. I would like to rotate vector A in this plane (pivoting about point P) towards vector B by a certain number of degrees $\theta$ (or away from B if $\theta$ is negative). I would like to do this via a transformation matrix, but I'm having some trouble crafting one on my own. How would I go about this?

4

There are 4 best solutions below

2
On BEST ANSWER

You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $\mathbf u = A/\|A\|$ and $\mathbf v = B/\|B\|$ form an orthonormal basis for their common plane. If you rotate $\mathbf u$ through an angle $\theta$ toward $\mathbf v$, you get $\mathbf u\cos\theta+\mathbf v\sin\theta$, so to rotate $A$ toward $B$, simply multiply this by $\|A\|$, i.e., $$A\cos\theta + {\|A\|\over\|B\|} B\sin\theta.$$

If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $\mathbf n = {A\times B\over\|A\times B\|}$, the right-handed normal to the plane of rotation, and designate by $\mathbf N$ its “cross-product matrix” $$\mathbf N = \begin{bmatrix}0&-n_z&n_y\\n_z&0&-n_x\\-n_y&n_x&0\end{bmatrix}.$$ The corresponding rotation matrix is then $$\mathbf R = \mathbf I + (\sin\theta)\mathbf N + (1-\cos\theta)\mathbf N^2.$$

0
On

Hint:

first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) \times (B/|B|)$, through the corresponding transformation matrix T;

then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle

finally multiply by $T^{-1}$

0
On

First replace $A$ by $A/\|A\|$, and similarly for $B$, so that they're unit vectors.

Compute $C = A \times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^{-1}$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!

Now let $$ R = M S M^{-1} = M S M^t $$ where $$ S = \pmatrix{c & -s & 0 \\ s & c & 0 \\ 0 & 0 & 1} $$ where $c = \cos \theta$ and $s = \sin \theta$, and $R$ is the rotation matrix that you want.

NB: Note that if $\theta$ is in degrees, then you need to use $c = \cos (\pi * \theta / 180)$, and similarly for $s$, where $\sin$ and $\cos$ denote the usual functions that work on angles expressed in radians.

0
On

We can proceed as follow

  1. Fix a basis $\mathcal{B}=\{v_1,v_2,v_3\}$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.
  2. Then write the rotation matrix $R_\mathcal{B}$ with respect to that basis (we can use the standard rotation matrix).
  3. Then with respect to the canonical basis, indicating with $M=[v_1\,v_2\,v_3]$ we have

$$w_\mathcal{B}=R_\mathcal{B}v_\mathcal{B} \implies M^{-1}w=R_\mathcal{B}M^{-1}v\implies w=MR_\mathcal{B}M^{-1}v=Rv$$