<s>[INST] How to define an affine transformation using 2 triangles? I have $2$ triangles ($6$ dots) on a $2D$ plane.
The points of the triangles are: a, b, c and x, y, z
I would like to find a matrix, using I can transform every point in the 2D space.
If I transform a, then the result is x. For b the result is y, and for c the result is z
And if there is a given d point, which is halfway from a to b, then after the transformation the result should be between x and y halfway.

I've tried to solve it according to NovaDenizen's solution, But the result is wrong.
The original triangle:
$$
a =
\left[
\begin{array}{ccc}
-3\\
0\\
\end{array}
\right]
$$
$$
b =
\left[
\begin{array}{ccc}
0\\
3\\
\end{array}
\right]
$$
$$
c =
\left[
\begin{array}{ccc}
3\\
0\\
\end{array}
\right]
$$
The x, y, z dots:
$$
x =
\left[
\begin{array}{ccc}
2\\
3\\
\end{array}
\right]
$$
$$
y =
\left[
\begin{array}{ccc}
3\\
2\\
\end{array}
\right]
$$
$$
z =
\left[
\begin{array}{ccc}
4\\
3\\
\end{array}
\right]
$$
I've created a figure:

I tried to transform the (0, 0) point, which is halfway between a and b, but the result was (3, 3.5) instead of (3, 3)
The T matrix is:
$$\left[
\begin{array}{ccc}
1/3 & 1/6 & 0\\
0 & -1/2 & 0\\
3 & 3,5 & 1\\
\end{array}
\right]$$
 [/INST] The transformation you're looking for has this form:
$$\left[
\begin{array}{ccc}
t_1 & t_2 & t_3\\
t_4 & t_5 & t_6\\
0 & 0 & 1\\
\end{array}
\right]
\left[
\begin{array}{ccc}
a_1 & b_1 & c_1\\
a_2 & b_2 & c_2 \\
1 & 1 & 1 \\
\end{array}
\right]
= \left[\begin{array}{ccc}
x_1 & y_1 & z_1\\
x_2 & y_2 & z_2\\
1 & 1 & 1
\end{array}
\right]
$$
or
$${\bf T A} = {\bf X}$$
so
$${\bf T} = {\bf X}{\bf A}^{-1}$$
Now $\bf T$ is a transformation matrix you can use on any point, like
$${\bf T}\left[\begin{array}{c}a_1\\a_2\\1\end{array}\right] = \left[\begin{array}{c}x_1\\x_2\\1\end{array}\right]$$
It's linear, so it has the halfway point property you were looking for.
$$
{\bf A} = \left[\begin{array}{ccc}
-3 & 0 & 3\\
0 & 3 & 0\\
1 & 1 & 1\\
\end{array}\right]
$$
$$
\left[\begin{array}{ccc|ccc}
-3 & 0 & 3 & 1 & 0 & 0\\
0 & 3 & 0 & 0 & 1 & 0\\
1 & 1 & 1 & 0 & 0 & 1\\
\end{array}\right]
$$
$$
\left[\begin{array}{ccc|ccc}
1 & 0 & -1 & -\frac13 & 0 & 0\\
0 & 3 & 0 & 0 & 1 & 0\\
0 & 1 & 2  & \frac13 & 0 & 1\\
\end{array}\right]
$$
$$
\left[\begin{array}{ccc|ccc}
1 & 0 & -1 & -\frac13 & 0 & 0\\
0 & 1 & 0 & 0 & \frac13 & 0\\
0 & 0 & 2  & \frac13 & -\frac13 & 1\\
\end{array}\right]
$$
$$
\left[\begin{array}{ccc|ccc}
1 & 0 & 0 & -\frac16 & -\frac16 & \frac12\\
0 & 1 & 0 & 0 & \frac13 & 0\\
0 & 0 & 1  & \frac16 & -\frac16 & \frac12\\
\end{array}\right]\\
\text{so } {\bf A}^{-1} = 
\left[\begin{array}{ccc}
-\frac16 & -\frac16 & \frac12\\
0 & \frac13 & 0\\
\frac16 & -\frac16 & \frac12\\
\end{array}\right]$$
$${\bf XA}^{-1} = 
\left[\begin{array}{ccc}
2 & 3 & 4\\
3 & 2 & 3\\
1 & 1 & 1\\
\end{array}\right]
\left[\begin{array}{ccc}
-\frac16 & -\frac16 & \frac12\\
0 & \frac13 & 0\\
\frac16 & -\frac16 & \frac12\\
\end{array}\right]
=
\left[\begin{array}{ccc}
\frac13 & 0 & 3\\
0 & -\frac13 & 3\\
0 & 0 & 1\\
\end{array}\right]
$$
</s>