# Solving a linear system of equations in 3 unknowns

I am having trouble solving this linear system of equations to get $$\theta_1$$ and $$\theta_2$$ as functions of $$x$$ and $$y$$ where $$x_1, x_2, x_3$$ and $$y_1, y_2, y_3$$ are constants:

$$\theta_1\cdot x_1 + \theta_2\cdot x_2 + \theta_3 \cdot x_3 = x$$

$$\theta_1\cdot y_1 + \theta_2\cdot y_2 + \theta_3 \cdot y_3 = y$$

$$\theta_1 + \theta_2 + \theta_3 = 1$$

By using the condition $$\theta_3 = 1-\theta_1 - \theta_2$$ i have got to the following two-by-two system of equations:

$$\theta_1(x_1-x_3) + \theta_2(x_2-x_3) = x - x_3$$

$$\theta_1(y_1-y_3) + \theta_2(y_2-y_3) = y - y_3$$

Can anyone help me as to how to proceed from here? Also, I have just been using brute-force so far and would like to know if there is an easier or more sophisticated way of solving this system as the above two equations look very similar.

Any help would be greatly appreciated, thanks guys!

• You are trying to compute the barycentric coordinates of $(x,y)$ relative to the triangle spanned by the $(x_k,y_k)$. What exactly is the problem of inverting the $3\times 3$ matrix? Or solve the reduced $2\times 2$ system? No one is saying that the solution has to look nice, or at least nicer than the Cramer solution formulas. Commented Nov 21, 2018 at 17:30

You can rewrite your system of equations in the following form: $$\begin{bmatrix} x_1 & x_2 & x_3\\ y_1 & y_2 & y_3\\ 1 & 1 & 1 \end{bmatrix}\begin{bmatrix} \theta_1 \\ \theta_2 \\ \theta_3 \end{bmatrix} = \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$
If the matrix containing the $$x_i$$ and $$y_i$$ is invertible, you can find a unique solution for your $$\theta_i$$ as:
$$\begin{bmatrix} \theta_1 \\ \theta_2 \\ \theta_3 \end{bmatrix} = \begin{bmatrix} x_1 & x_2 & x_3\\ y_1 & y_2 & y_3\\ 1 & 1 & 1 \end{bmatrix}^{-1}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$
which you can calculate either directly or by using numerics. If your matrix is not invertible, then you do not have a unique solution and may have either no solution at all or an infinite number of solutions depending on the image of the matrix containing the $$x_i$$'s and $$y_i$$'s.