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

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

so...
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 cxay 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
T2k

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015755
×