开发者

How to find transformation matrix aligning two lines?

开发者 https://www.devze.com 2022-12-21 20:40 出处:网络
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\'.

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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消