title: How to find transformation matrix aligning two lines?
body: <p>Given two points in 3D space, A and B, I get a line segment LS. Given two new points A' and B' yielding the line segment LS', I need to find the transformation matrix that transforms LS into LS'. The length of the line segments is assumed to be equal.</p>
  
  <p>I have a theory on how to calculate the matrix, but I would really like some feedback from you excellent folks on whether it is a good theory or if there exists some better approach.</p>
  
  <p>Here's my algorithm:</p>
  
  <ol>
  <li>Let L and L' be the lines parallel to LS and LS'</li>
  <li>Find the point P where L intersects L'</li>
  <li>Find the angle V between L and L'</li>
  <li><p>The final transformation matrix will be:</p>
  
  <p>translate(-P) * rotate(V) * translate(p)</p></li>
  </ol>
  
  <p>Some background for the curious: I'm building this in XNA, though the math problem should be quite general. The line segment is part of a larger structure of connected segments. For each segment I will pre-calculate a transformation matrix per animation frame.</p>