# After deriving a new coordinate via sequential linear transforms, how can I map translations back to the original coordinates?

I have a Bezier curve, defined with coordinates $P_1, P_2, P_3, P_4$ and apply a sequence of linear tranformations that turn these into $(0,0), (0,s), (s,s)$ and a fourth "free" coordinate (all coordinates are extended with a $z=1$ as a shortcut to do full 2D transforms)

To effect this, I'm applying the following operations:

1. translate by ${P_1}_x, {P_1}_y$ to set the curve origin to (0,0) using matrix:

$$\left [ \begin{matrix} 1 & 0 & -{P_1}_x \\ 0 & 1 & -{P_1}_y \\ 0 & 0 & 1 \end{matrix} \right ]$$

1. This generates a new set of coordinates $U_1...U_4$, which I then X-shear to align the new point 2 with x=0:

$$\left [ \begin{matrix} 1 & -\frac{{U_2}_x}{{U_2}_y} & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{matrix} \right ]$$

1. This generates a new set of coordinates $V_1...V_4$, which get scaled so that the final points 1 through 3 will lie on (0,0), (0,s) and (s,s), where $s$ will usually be 1, but might not be so is kept symbolic:

$$\left [ \begin{matrix} \frac{s}{{V_3}_x} & 0 & 0 \\ 0 & \frac{s}{{V_2}_y} & 0 \\ 0 & 0 & 1 \end{matrix} \right ]$$

1. This generates a new set of coordinates $W_1...W_4$, which get Y-sheared to effect the final alignment of point 3 onto (s,s):

$$\left [ \begin{matrix} 1 & 0 & 0 \\ \frac{s - {W_3}_y}{{W_3}_x} & 1 & 0 \\ 0 & 0 & 1 \end{matrix} \right ]$$

Which generates a the final set of four coordinates, of which the first three are the fixed coordinates (0,0), (0,s) and (s,s), and the fourth is the "free" coordinate $F$:

$$F = \left ( \begin{matrix} \frac { s \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \\ \frac{s(-y_1+y_4)}{-y_1+y_2} + \frac { \left ( s - \frac{s(-y_1+y_3)}{-y_1+y_2} \right ) \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \end{matrix} \right )$$

Which works brilliantly to directly compute the mapped fourth coordinate. However, I'm also interested in manipulating this "resultant coordinate" and update the original point 4 accordingly, and have no idea how to invert the mapping.

Given a translated mapped coordinate (by some distance $(d'_x,d'_y)$):

$$F' = \left ( \begin{matrix} d'_x + \frac { s \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \\ d'_y + \frac{s(-y_1+y_4)}{-y_1+y_2} + \frac { \left ( s - \frac{s(-y_1+y_3)}{-y_1+y_2} \right ) \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \end{matrix} \right )$$

I'd love to know how to map that back to a $(d_x,d_y)$ value for the original point 4.

$$F' = \left ( \begin{matrix} d'_x + \frac { s \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \\ d'_y + \frac{s(-y_1+y_4)}{-y_1+y_2} + \frac { \left ( s - \frac{s(-y_1+y_3)}{-y_1+y_2} \right ) \left ( -x_1 + x_4 - \frac{(-x_1+x_2)(-y_1+y_4)}{-y_1+y_2} \right ) } { -x_1+x_3-\frac{(-x_1+x_2)(-y_1+y_3)}{-y_1+y_2} } \end{matrix} \right )$$
$$T_1^{-1} \cdot T_2^{-1} \cdot T_3^{-1} \cdot T_4^{-1} \cdot F'$$
$$\left ( \begin{matrix} \frac{-dy \cdot x_1 + (-dx+dy)x_2 + dx \cdot x_3 + s \cdot x_4)}{s} \\ \frac{-dy \cdot y_1 + (-dx+dy)y_2 + dx \cdot y_3 + s \cdot y_4)}{s} \end{matrix} \right )$$