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]$$

There is a neat formula for your case
$$
\vec{P}(p_1; p_2) = (-1)
\frac{
    \det
        \begin{pmatrix}
            0   & \vec{x} & \vec{y} & \vec{z} \\
            p_1 & a_1     & b_1     & c_1     \\
            p_2 & a_2     & b_2     & c_2     \\
            1   & 1       & 1       & 1       \\
        \end{pmatrix}
}{
    \det
        \begin{pmatrix}
            a_1 & b_1 & c_1 \\
            a_2 & b_2 & c_2 \\
            1   & 1   & 1   \\
        \end{pmatrix}
},
$$
where $p_1$ and $p_2$ are coordinates of the point you are mapping.
Here's how it works (plugging in initial points)
$$
\vec{P}(p_1; p_2) = (-1)
\frac{
    \det
        \begin{pmatrix}
            0   & \vec{x} & \vec{y} & \vec{z} \\
            p_1 & -3      & 0       & 3       \\
            p_2 & 0       & 3       & 0       \\
            1   & 1       & 1       & 1       \\
        \end{pmatrix}
}{
    \det
        \begin{pmatrix}
            -3  & 0   & 3   \\
            0   & 3   & 0   \\
            1   & 1   & 1   \\
        \end{pmatrix}
} =
\frac{\vec{z} - \vec{x}}{6} p_1 +
\frac{2 \vec{y} - \vec{x} - \vec{z}}{6} p_2 +
\frac{\vec{x} + \vec{z}}{2} =
$$
now I plug in the final points
$$
= \frac{1}{6} \left[
    \begin{pmatrix} 4 \\ 3 \end{pmatrix} -
    \begin{pmatrix} 2 \\ 3 \end{pmatrix}
\right] p_1 +
\frac{1}{6} \left[
  2 \begin{pmatrix} 3 \\ 2 \end{pmatrix} -
    \begin{pmatrix} 2 \\ 3 \end{pmatrix} -
    \begin{pmatrix} 4 \\ 3 \end{pmatrix}
\right] p_2 +
\frac{1}{2} \left[
    \begin{pmatrix} 2 \\ 3 \end{pmatrix} +
    \begin{pmatrix} 4 \\ 3 \end{pmatrix}
\right]
$$
Simplification yields
$$
\vec{P}(p_1; p_2) =
\begin{pmatrix} 1/3 \\ 0 \end{pmatrix} p_1 +
\begin{pmatrix} 0   \\ -1/3 \end{pmatrix} p_2 +
\begin{pmatrix} 3   \\ 3 \end{pmatrix}
$$
Or you can write that in canonical form
$$
\vec{P}(p_1; p_2) =
\begin{pmatrix}
1/3  & 0    \\
0    & -1/3
\end{pmatrix}
\begin{pmatrix} p_1 \\ p_2 \end{pmatrix} +
\begin{pmatrix} 3 \\ 3 \end{pmatrix}
$$
For more details on how this all works you may check "Beginner's guide to mapping simplexes affinely", where authors of the equation elaborate on theory behind it. In the guide there is exactly the same 2D example solved as the one you are interested in.
The same authors recently published "Workbook on mapping simplexes affinely"  (ResearchGate as well). They discuss many practical examples there, e.g. show that the same equation may be used for color interpolation or Phong shading. You may want to check it if you want to see this equation in action.
