The mapping between Cartesian coordinates $(x, y)$ and Barycentric coordinates $(u, v, w)$ corresponding to a triangle with vertices $(x_0, y_0)$, $(x_1, y_1)$, and $(x_2, y_2)$ is trivial.
By definition, $u + v + w = 1$, and they directly correspond to the weights of their corresponding vertices. Using the formulae shown in this answer,
$u$ corresponds to the weight of vertex $(x_1, y_1)$,
$v$ corresponds to the weight of vertex $(x_2, y_2)$, and
$w = 1 - u - v$ corresponds to the weight of vertex $(x_0, y_0)$.
Because the mapping is linear, this is also linear interpolation between the three vertices. It can be generalized to any simplex in $K$ dimensions, using $K+1$ barycentric coordinates. In 1D, the simplex is a line segment; in 2D, a triangle; in 3D, a tetrahedron; and so on.
From Barycentric to Cartesian coordinates we have
$$\left\lbrace \begin{aligned}
x &= u x_1 + v x_2 + w x_0 \\
y &= u y_1 + v y_2 + w y_0 \\
\end{aligned} \right .$$
by definition; applying $w = 1 - u - v$ we get
$$\left\lbrace \begin{aligned}
x &= x_0 + u (x_1 - x_0) + v (x_2 - x_0) \\
y &= y_0 + u (y_1 - y_0) + v (y_2 - y_0) \\
\end{aligned} \right .$$
In practice, we often use first vertex and the two edge vectors from it instead, i.e.
$$\left\lbrace \begin{aligned}
x_u &= x_1 - x_0 \\
y_u &= y_1 - y_0 \\
\end{aligned} \right . , \quad \left\lbrace \begin{aligned}
x_v &= x_2 - x_0 \\
y_v &= y_2 - y_0 \\
\end{aligned} \right . \tag{1a}\label{1a}$$
so that the $u$ axis is along the line between vertices $0$ and $1$, $v$ axis along the line between vertices $0$ and $2$, and the $w$ axis between vertices $1$ and $2$. Then,
$$\left\lbrace \begin{aligned}
x &= x_0 + u x_u + v x_v \\
y &= y_0 + u y_u + v y_v \\
\end{aligned} \right . \tag{1b}\label{1b}$$
The inverse is
$$\left\lbrace \begin{aligned}
u &= \frac{(x - x_0) y_v - (y - y_0) x_v}{x_u y_v - x_v y_u} \\
v &= \frac{(y - y_0) x_u - (x - x_0) y_u}{x_u y_v - x_v y_u} \\
\end{aligned} \right.$$
where the divisor, $x_u y_v - x_v y_u$, is twice the area of the triangle, so if the triangle is degenerate (a line or a point), the divisor is zero, and there is no solution.
If you have many points to map to a given triangle, you can save significant computing effort by calculating
$$\left\lbrace \begin{aligned}
u_0 &= \frac{y_0 x_v - x_0 y_v}{x_u y_v - x_v y_u} \\
u_x &= \frac{y_v}{x_u y_v - x_v y_u} \\
u_y &= \frac{-x_v}{x_u y_v - x_v y_u} \\
\end{aligned} \right., \quad \left\lbrace \begin{aligned}
v_0 &= \frac{x_0 y_u - y_0 x_v}{x_u y_v - x_v y_u} \\
v_x &= \frac{-y_u}{x_u y_v - x_v y_u} \\
v_y &= \frac{x_u}{x_u y_v - x_v y_u} \\
\end{aligned} \right. \tag{2a}\label{2a}$$
because then we have
$$\left\lbrace \begin{aligned}
u &= u_0 + x u_x + y u_y \\
v &= v_0 + x v_x + y v_y \\
\end{aligned} \right. \tag{2b}\label{2b}$$
and we have a very nice symmetry, too, between the two mapping operations.
In object-oriented programming languages like Python or C++, create a class to represent a triangle. (In C, consider using a structure with room for the twelve precalculated parameters.) Whenever the Cartesian coordinates for the triangle are defined or modified, recalculate or update $x_0$, $y_0$, $x_u$, $y_u$, $x_v$, $y_v$, $u_0$, $u_x$, $u_y$, $v_0$, $v_x$, and $v_y$, and the class can map between Cartesian and Barycentric coordinates with just four multiplications and four additions per operation: extremely lightweight and efficient!
In $K$ dimensions, each mapping operation involves $K^2$ multiplications and additions, but is still quite lightweight and efficient.