Advertisement Jump to content
Sign in to follow this  

Finding the transformation matrix from one line to another

This topic is 4934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(2D) I have two line segments A and B. The start and end point of each line is not neccessarly 0, they are free floating, unrelated lines with parameters x0, y0, x1, y1 representing their endpoints. I want to find the the 2D (3*3) transformation matrix that translates, rotates and scales line A to line B. Can anyone help me please?

Share this post

Link to post
Share on other sites
you can do it only by using a matrix that transforms from Line1xOrthogonal of that line to the newlinexnewOrthogonal. All your points not on the line will also be transformed and be placed in relation to the line...

cx, cy is the startpoint,
ax, ay is the endpoint relatively to the center (ax= realendpointx-cx, ay=realendpointy-cy) and
bx, by is the Orthogonal with bx= ay, by= -ax (90°CW rotated)

the matrix will then be:

ax bx cx ax ay cx
ay by cy or without bx,by: ay -ax cy
0 0 1 0 0 1
this transforms from x=0 to 1 onto the line and y=0 to 1 onto the Orthogonal
(0, 0) => line startpoint, (1,0) => line endpoint (the third component, w is 1)

you need the extra Orthogonal to get the inverse of that matrix (otherwise you lose one degree of freedom and the determinant of the matrix becomes 0 => no inverse)

ive decided to not give you a formula for the inverse because that will become a bit complicated and you can google for such a formula...

all you have todo now is to get the matrix for line1->objspace->line2, where line1->objspace is the inverse of the above matrix with line1 coordinates and objspace->line2 is the above matrix with line2 coordinates

edit: codetag
edit2: tangent replaced with orthogonal

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!