Calculating a circle from three points

Say we have three points:

$$ \begin{align} A &= (x_a, y_a)\\[5px] B &= (x_b, y_b)\\[5px] C &= (x_c, y_c) \end{align} $$

We can draw two lines through these points, forming chords Q and R; we know that the perpendicular bisectors of these two chords (say we call these Q' and R') will meet at the centre of the circle. It's then pretty easy to work out the radius using Pythagoras. First things first, the equation of a line in point slope form is:

$$ y - y_1 = m(x - x_1) $$

Where M is the slope of the line, and (x1, y1) is any point on the line. We know a point on each bisector, it's the midpoint of its associated chord:

$$ \begin{align} Q\prime(x_1,y_1) &= \left({x_a + x_b \over 2},{y_a + y_b \over 2}\right)\\[5px] R\prime(x_1,y_1)&=\left({x_b+x_c \over 2},{y_b+y_c \over 2}\right) \end{align} $$

Calculate the slopes of the chords:

$$ \begin{align} m_q&={y_a-y_b \over x_a-x_b}\\[5px] m_r&={y_b-y_c \over x_b-x_c} \end{align} $$

We can then invert these to get the slopes of the bisectors

$$ \begin{align} m_q\prime&={-1 \over m_q}\\[5px] m_r\prime&={-1 \over m_r} \end{align} $$

We can put the midpoint coordinates and the bisector slopes to form the following linear equations for the bisectors:

$$ y_q-{y_a+y_b \over 2}={-1 \over m_q}\left(x - {x_a+x_b \over 2}\right) $$

Therefore:

$$ \begin{align} y_q &= {-1 \over m_q}\left(x-{x_a + x_b \over 2}\right)+{y_a + y_b \over 2}\\ y_r &= {-1 \over m_r}\left(x-{x_b + x_c \over 2}\right)+{y_b + y_c \over 2} \end{align} $$

Where the two lines intersect we have the centre of the circle, therefore:

$${-1 \over m_q}\left(x-{x_a + x_b \over 2}\right)+{y_a + y_b \over 2} = {-1 \over m_r}\left(x-{x_b + x_c \over 2}\right)+{y_b + y_c \over 2}$$

We can solve for X:

$$ \begin{align} -{1 \over m_q}\left(x-{x_a + x_b \over 2}\right)+{y_a + y_b \over 2} &= {-1 \over m_r}\left(x-{x_b + x_c \over 2}\right)+{y_b + y_c \over 2}\\[5px] -{x \over m_q} + {x_a + x_b \over 2m_q}+{y_a+y_b \over 2} &= -{x \over m_r} + {x_b + x_c \over 2m_r}+{y_b+y_c \over 2}\\[5px] -{x \over m_q} + {x \over m_r} &= {x_b + x_c \over 2m_r}+{y_b+y_c \over 2}-{x_a + x_b \over 2m_q}-{y_a+y_b \over 2}\\[5px] -{m_rx + m_qx \over m_qm_r} &= {m_qx_b + m_qx_c + m_qm_ry_b + m_qm_ry_c - m_rx_a - m_rx_b - m_qm_ry_a - m_qm_ry_b \over 2m_qm_r}\\[5px] -{m_rx + m_qx \over m_qm_r} &= {m_q(x_b + x_c) + m_qm_r(y_c - y_a) - m_r(x_a + x_b) \over 2m_qm_r}\\[5px] {2m_qm_r(-m_rx+m_qx)\over m_qm_r} &= m_q(x_b + x_c) + m_qm_r(y_c - y_a) - m_r(x_a + x_b)\\[5px] 2(m_q-m_r)x &= m_q(x_b + x_c) + m_qm_r(y_c - y_a) - m_r(x_a + x_b)\\[5px] x &= {m_q(x_b + x_c) + m_qm_r(y_c - y_a) - m_r(x_a + x_b) \over 2(m_q-m_r)}\\ \end{align} $$

With x we can now calculate y using the general linear equation below and by substituting in the known values

$$ y - y_1 = m(x - x_1) $$

AN EXAMPLE

$$ \begin{align} A&=(2,1)\\[5px] B&=(0,5)\\[5px] C&=(-1,2) \end{align} $$

$$ \begin{align} m_q&={1-5 \over 2-0}={-4 \over 2} = -2\\[5px] m_r&={5-2 \over 0+1}={3 \over 1} = 3 \end{align} $$

$$ \begin{align} x&={m_q(x_b+x_c)+m_qm_r(y_c-y_a)-m_r(x_a+x_b) \over 2(m_q-m_r)}\\[5px] x&={-2(0-1)-6(2-1)-3(2+0) \over 2(-2-3)}\\[5px] x&={-10 \over -10}\\[5px] x&=1 \end{align} $$

$$ \begin{align} y-y_1&=m(x-x_1)\\[5px] y-3&={1 \over 2}(1-1)\\[5px] y-3&=0\\[5px] y&=3 \end{align} $$

$$ \begin{align} R&=\sqrt{(c_x-x_1)^2+(c_y-y_1)^2}\\[5px] R&=\sqrt{(1-2)^2+(3-1)^2}\\[5px] R&=\sqrt{1^2+2^2}\\[5px] R&=\sqrt{5} \end{align} $$

$$(x-1)^2+(y-3)^2 = 5$$