# Algorithm for computing the plane that passes through three arbitrary points

I'm writing a computer graphics library, and I'd like to compute the plane that passes through three arbitrary points, $p$, $q$ and $r$. I'm defining the plane in the form of $Ax + By + Cz + D = 0$.

My algebra is rather rusty, but I suspect this is a job for some simultaneous equations I'll need to solve a system of equations:

$$0 = \begin{cases} Ax_p + By_p + Cz_p + D \\ Ax_q + By_q + Cz_q+ D \\ Ax_r + By_r + Cz_r + D \end{cases}$$

How would I efficiently find the values of $A$, $B$, $C$ and $D$ with respect to $p$, $q$ and $r$?

-
The problem is called "solving a system of linear equations" and it is easy to find libraries which do this for you. Alternatively, you can implement this algorithm yourself. –  Fabian Dec 23 '12 at 5:29
Cheers. I updated the question and am looking at you link. I'm using an obscure new language, hence me having to write the library myself. –  bjz Dec 23 '12 at 5:36
It is not hard to implement it yourself. Use Gauss' algorithm to bring it to row echelon form and then use back-substitution. –  Fabian Dec 23 '12 at 5:40

Consider the points $p$, $q$, $r$.

step 1 Construct the line from $p$ to $q$, i.e. $PQ=q-p$ and line from $p$ to $r$, i.e. $PR=r-p$

step 2 Find the cross product of lines $PQ=(x_1 , x_2 , x_3)$ and $PR=(y_1 , y_2 , y_3)$ \begin{align} n=\begin{vmatrix}i & j & k \\ x_1 & x_2 & x_3 \\ y_1 & y_2 & y_3\end{vmatrix} \end{align} This will be the normal line to the plane (perpendicular). $i,j,k$ are the co-ordinate axes. So if you get $n_1i+n_2j+n_3k$, then $(n_1,n_2,n_3)$ is the desired normal point.

step 3 Construct the normal equation of the plane \begin{align} n_1(x-a)+n_2(y-b)+n_3(x-c)=0 \end{align} where $(a,b,c)$ can be the co-ordinates of any of the points $p,q,r$(reference point).

-