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.
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.
Here's my algorithm:
- Let L and L' be the lines parallel to LS and LS'
- Find the point P where L intersects L'
- Find the angle V between L and L'
The final transformation matrix will be:
translate(-P) * rotate(V) * translate(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.