[Math] Matrix representation of affine transformation that maps a given line segment to another given line segment

linear-transformations

Given two line segments $(x_1,y_1),(x_2,y_2)$ and $(x_3,y_3),(x_4,y_4)$, I am looking for a matrix representation of (one, as I understand there can be many?) affine transformation that takes the first line segment to the second. (Also, just to be clear, I want it to map $(x_1,y_1)$ to $(x_3,y_3)$, not the/any other mapping that flips the order.)

(I realize that I can work out the translation of the first segment back to origin, then rotation through the difference of angles, scaling by the ratio of the lengths, and then translating up to the second segment's location. I'm just thinking that this might be a standard thing people want to be able to do (I need it for a computer program I am working on) and the general form of this matrix is already worked out, but I haven't found it due to not being 100% sure of what terms to google. I also have a vague recollection that there is a clever shortcut that prevents having to go through all the steps I described, but my matrix-fu is quite weak, unfortunately.)

Update: I am going to see what I can do using the examples at https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations showing the method of augmenting the vector with a 1 and the $n$x$n$ with a zero row and the translation vector as a column. I will post whatever I come up with as an answer if nothing else shows up here–I just want to let people know I'm making an attempt, in case that changes their desire to work on it either way.

Best Answer

We need to find a transformation that maps the segments. It is sufficient to restrict the search to affine maps and to map only the end points $$ z_1=\left[\matrix{x_1\\y_1}\right]\ \mapsto w_1=\left[\matrix{x_3\\y_3}\right],\quad\text{and}\quad z_2=\left[\matrix{x_2\\y_2}\right]\ \mapsto \ w_2=\left[\matrix{x_4\\y_4}\right]. $$ Case I: $\text{rank}\,[z_1\ z_2]=2$. Then the linear transformation $$ w=Az\qquad\text{where}\qquad A=[w_1\ w_2]\cdot [z_1\ z_2]^{-1} $$ does the job.

Case II: $z_1\parallel z_2$, but $z_1\ne z_2$. Then we need to consider an affine map $w=Az+z_0$ to shift the $w$-vectors. Let $\lambda z_1+\mu z_2=0$. Then $$ \left\{ \begin{array}{lcl} \lambda Az_1+\lambda z_0&=&\lambda w_1,\\ \mu Az_2+\mu z_0&=&\mu w_2,\\ \end{array} \right.\quad\Rightarrow\quad \underbrace{A(\lambda z_1+\mu z_2)}_{=0}+(\lambda+\mu)z_0=\lambda w_1+\mu w_2. $$ It gives $z_0=\frac{\lambda w_1+\mu w_2}{\lambda+\mu}$. Note that $\lambda+\mu\ne 0$ by the assumption that $z_1\ne z_2$. With this $z_0$ any $A$ that maps only one end point, i.e. $Az_1=w_1-z_0$ would suffice (not unique).

Case III: $z_1=z_2$ is trivial. If $w_1=w_2$ (point-to-point) then any $A$ with $Az_1=w_1$ works. If $w_1\ne w_2$ (point-to-segment) then no such transformation (even non-linear) exists.

Related Question