Find transform matrix that transforms one line segment to another

2.3k Views Asked by At

I have two line segments, one with points $P_1=(x_1,y_1,1), P_2=(x_2,y_2,1)$ and other with points $P_3=(x_3,y_3,1), P_4=(x_4,y_4,1)$. I need to find transform matrix $$M=\left(\begin{array}{ccc} a & b & c\\ d & e & f\\ 0 & 0 & 1 \end{array}\right)$$ so that $$M\cdot P_1 = P_3$$ $$M\cdot P_2 = P_4.$$

Also, transform should equally scale points along X and Y axis.

I have tried it in following way:

$$M= \left(\begin{array}{ccc} \cos\alpha & -\sin\alpha & 0\\ \sin\alpha & \cos\alpha & 0\\ 0 & 0 & 1 \end{array}\right) \left(\begin{array}{ccc} 1 & 0 & h\\ 0 & 1 & v\\ 0 & 0 & 1 \end{array}\right) \left(\begin{array}{ccc} s & 0 & 0\\ 0 & s & 0\\ 0 & 0 & 1 \end{array}\right).$$ Then I have system of four equations in four unknowns, which is not trivial to solve. I have tried to solve it with Mathematica, however, it gives answer in very messy form.

I'm wondering, is there any more elegant way to solve this problem and short expressions for matrix coefficients ($a,b,c,d,e,f$)?