title: Rotation and direction of a vector in 3D space - Inverse Order
body: <p>I have two vectors in 3D-space, <code>S</code> (Start) and <code>T</code> (Target), and I want to find the Rotation Matrix (RM) that allows such transformation.</p>
  
  <p>I know that by computing the <strong>cross product</strong> <code>S × T</code> I get the rotation axis. The angle between <code>S</code> and <code>T</code> is given by <code>tan⁻¹(||S × T||, S·T)</code>, where <code>S·T</code> is the <strong>dot product</strong> between S and T.</p>
  
  <p>This gives me the rotation vector <code>rotvec = [S x T; angle]</code> (the cross product is normalized). Then by using function  <a href="https://www.mathworks.com/help/sl3d/vrrotvec2mat.html" rel="nofollow noreferrer">vrrotvec2mat</a> (in MATLAB) or <a href="https://matthew-brett.github.io/transforms3d/reference/transforms3d.axangles.html" rel="nofollow noreferrer">transforms3d.axangles.axangle2mat</a> (in Python) I can obtain the rotation matrix that corresponds to the transformation from <code>S</code> to <code>T</code>.</p>
  
  <p>In my application <code>T</code> is given by the <strong>dot product</strong> <code>RM·D</code>, where is <code>D</code> is a <code>3x1</code> vector. <strong><em>My goal</strong> is to find RM</em>. I know <code>S</code>, <code>T</code> and <code>D</code>, but I am having trouble to understand the math behind this.</p>
  
  <p>In practice I want to find a RM between <code>S</code> and <code>T'</code>, where <code>T'</code> is the target vector before <code>D</code> (the direction) has been applied.</p>
  
  <p><em>A little more context</em>:  I want to obtain body joint angles from 3D points in the camera coordinate system.</p>