Given three points $(x_1,y_1)$, $(x_2,y_2)$, and $(x_3,y_3)$, if $$\frac{y_2-y_1}{x_2-x_1} \neq \frac{y_3-y_2}{x_3-x_2} \neq \frac{y_1-y_3}{x_1-x_3},$$ then there will be a circle passing through them. The general form of the circle is $$x^2 + y^2 + dx + ey + f = 0.$$ By substituting $x = x_i$ and $y = y_i$, there will be a system of equation in three variables, that is:
\begin{align*} \begin{pmatrix} x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \\ x_3 & y_3 & 1 \\ \end{pmatrix} \begin{pmatrix} d \\ e \\ f \end{pmatrix} &= \begin{pmatrix} -\left(x_1^2+y_1^2\right) \\ -\left(x_2^2+y_2^2\right) \\ -\left(x_3^2+y_3^2\right) \end{pmatrix}. \end{align*}
Solving this system gives the solution \begin{align*} d &= \frac{(x_3^2 + y_3^2 -x_1^2+y_1^2)}{x_1 - x_3} - e\left(\frac{y_1 - y_3}{x_1 - x_3}\right) \\ e &= \frac{(x_3^2 + y_3^2 -x_2^2+y_2^2)(x_1-x_3) - (x_3^2 + y_3^2 -x_1^2+y_1^2)(x_2-x_3)}{(y_2-y_3)(x_1-x_3) - (y_1-y_3)(x_2-x_3)} \\ f &= \frac{-(x_3^2 + y_3^2)(x_1-x_3) - (y_1-y_3)x_3}{x_1 - x_3} - e\left(\frac{y_3(x_1 - x_3) - x_3(y_1 - y_3)}{x_1 - x_3}\right) \end{align*}
As there are a lot of things going around, the solution is prone to errors. Maybe this solution also has an error.
Is there a better way to solve for the equation of the circle?