views:

179

answers:

1

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:

  1. Let L and L' be the lines parallel to LS and LS'
  2. Find the point P where L intersects L'
  3. Find the angle V between L and L'
  4. 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.

+1  A: 

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.

tafa
Yes, that should work, and thinking of it, probably safer: my initial algorithm will get into problems if LS and LS' is parallel.
Peter Lillevold