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 struct开发者_开发百科ure of connected segments. For each segment I will pre-calculate a transformation matrix per animation frame.
Instead of finding intersection traslating A to A' would be sufficient, I guess. Then you probably will require 2 rotations, one to make both lines on the same plane, and the other to actually align them.
精彩评论