# How to calculate the intersection points of two circles?

The aim of this page is to calculate the coordinates on the intersection points between two circles $$C_1$$ and $$C_2$$.

Here are our hypotheses:

• center of circle $$C_1$$ is $$P_1 = (x_1, y_1)$$
• center of circle $$C_2$$ is $$P_2 = (x_2, y_2)$$
• radius of circle $$C_1$$ is $$r_1$$
• radius of circle $$C_2$$ is $$r_2$$

Our goal is to calculate the coordinates of the intersection points $$P_3$$ and $$P_4$$ as a function of $$P_1$$, $$P_2$$, $$r_1$$ and $$r_2$$.

## Intermediate steps

Here are the intermediate steps for computing the intersection points:

## Distance between centers

Let's start by calculating the $$d$$, the distance between the centers. By applying the Pythagorean theorem we can write:

$$d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 } \label{eq:d}$$

## Checking cases

According to the values of $$d$$, we now have five cases:

• if $$d > r_1 + r_2$$ the circles are too far apart and do not intersect;
• if $$d < | r_1 - r_2 |$$ one circle is inside the other and do not intersect;
• if $$d = 0$$ and $$r_1 = r_2$$ the circles are merged and there are an infinite number of points of intersection;
• if $$d = r_1 + r_2$$ there is a single intersection point;
• if $$d < r_1 + r_2$$ there are two intersection points.
$$d > r_1 + r_2$$ $$d < \lvert r_1 - r_2 \rvert$$
$$d = 0$$ and $$r_1 = r_2$$ $$d = r_1 + r_2$$

## Calculating a and b

To calculte the distance $$a$$ let's start by writing $$h$$ as a function of $$a$$ and $$b$$ . In the right triangles $$P_1 P_5 P_3$$ the Pythagorean theorem gives:

$$r_1^2 = h^2 + a^2 \label{eq:h1}$$

We can apply the theorem in the right triangle $$P_2 P_5 P_3$$:

$$r_2^2 = h^2 + b^2 \label{eq:h2}$$

By substituting \eqref{eq:h2} to \eqref{eq:h1} we get the following equation:

$$r_1^2 - r_2^2 = a^2 - b^2 \label{eq:ab}$$

Since $$d = a +b$$, we can write the folowing system of two equations:

$$\left\{ \begin{split} & r_1^2 - r_2^2 = a^2 - b^2 \\ & d = a +b \end{split} \right.$$

By injecting $$b = d-a$$ in equation \eqref{eq:ab}, we obtain the following relation:

$$r_1^2 - r_2^2 = a^2 - (d-a)^2$$

The $$–a^2$$ terms on each side cancel out. You can then solve for $$a$$:

$$\begin{split} r_1^2 - r_2^2 &= a^2 - d^2 - a^2 + 2ad \\ r_1^2 - r_2^2 &= - d^2 + 2ad \\ 2ad & = r_1^2 - r_2^2 + d^2 \end{split}$$

We get :

$$a = \dfrac{r_1^2 - r_2^2 + d^2 }{2d}$$

Similarly in the triangle $$P_2 P_5 P_3$$ :

$$b = \dfrac{r_2^2 - r_1^2 + d^2 }{2d}$$

All of these values are known:

• $$r_1$$ and $$r_2$$ are the radius of the circles
• $$d$$ has been calculated by equation \eqref{eq:d}

## Calculation of h

Once $$a$$ and $$b$$ are know, it becomes easy to calculate the length $$h$$ by apoplying the Pythagorean theorem in the right triangles $$P_1 P_5 P_3$$

$$r_1^2 = h^2 + a^2$$

$$h = \sqrt{ r_1^2 - a^2 }$$

## Coordinates of P5

The next step is to calculate the coordinates of $$P_5$$.

Since the vectors $$\vec{P_1P_5}$$ and $$\vec{P_1P_2}) \ are colinear, we can write:  \vec{P_1P_5} = \dfrac{a}{b} \times \vec{P_1P_2}  We can deduce the coordinates of \( P_5$$:

$$\begin{split} x_5 &= x_1 + \dfrac{a}{d} \times (x_2 - x_1) \\ y_5 &= y_1 + \dfrac{a}{d} \times (y_2 - y_1) \end{split}$$

## Vectors P5P3 and P5P4

The second to last step is the calculation of vectors $$\overrightarrow{P_5P_3}$$ and $$\overrightarrow{P_5P_4}$$ . Let's consider the vector $$\overrightarrow{P_1P_2}$$ given by the following relation:

$$\overrightarrow{P_1P_2} = \begin{pmatrix} x_2 - x_1 \\ y_2 - y_1 \end{pmatrix}$$

By multiplying this vector by a rotation matrix around the z-axis, we can calculate the perpendicular vectors:

Clockwise

$$\overrightarrow{P_1P_2}^{\bot \circlearrowright} = \begin{pmatrix} 0 && 1 \\ -1 && 0 \end{pmatrix} \times \begin{pmatrix} x_2 - x_1 \\ y_2 - y_1 \end{pmatrix} = \begin{pmatrix} y_2 - y_1 \\ x_1 - x_2 \end{pmatrix}$$

Counterclockwise

$$\overrightarrow{P_1P_2}\ {}^{\bot \circlearrowleft} = \begin{pmatrix} 0 && -1 \\ 1 && 0 \end{pmatrix} \times \begin{pmatrix} x_2 - x_1 \\ y_2 - y_1 \end{pmatrix} = \begin{pmatrix} y_1 - y_2 \\ x_2 - x_1 \end{pmatrix}$$

We already calculated the norm of vector $$\lVert \vec{P_1P_2} \rVert = d$$ and norm of vectors $$\lVert \vec{P_5P_3} \rVert = \lVert \vec{P_5P_4} \rVert = h$$.

By applyting the ratio $$\frac{h}{d}$$ to the vectors $$\overrightarrow{P_1P_2}^{\bot}$$ we can deduce the expressions of vectors $$\overrightarrow{P_5P_3}^{\bot}$$ and $$\overrightarrow{P_5P_4}^{\bot}$$:

$$\overrightarrow{P_5P_3}^{\bot} = \dfrac{h}{d} \times \overrightarrow{P_1P_2}^{\bot \circlearrowleft} =\begin{pmatrix} \dfrac{h(y_2 - y_1)}{d} \\ \dfrac{h(x_1 - x_2)}{d} \end{pmatrix}$$

$$\overrightarrow{P_5P_4}^{\bot} = \dfrac{h}{d} \times \overrightarrow{P_1P_2}^{\bot \circlearrowright} =\begin{pmatrix} \dfrac{h(y_1 - y_2)}{d} \\ \dfrac{h(x_2 - x_1)}{d} \end{pmatrix}$$

## Intersection points

Once the vectors $$\overrightarrow{P_5P_3}$$ and $$\overrightarrow{P_5P_4}$$ are known, the coordinates of $$P_3$$ and $$P_4$$ can be deduced by translating $$P_3$$ from these vectors. We finally get:

$$P_3 =\begin{pmatrix} x_5 - \dfrac{h(y_2 - y_1)}{d} \\ y_5 + \dfrac{h(x_2 - x_1)}{d} \end{pmatrix}$$

and

$$P_4 =\begin{pmatrix} x_5 + \dfrac{h(y_2 - y_1)}{d} \\ y_5 - \dfrac{h(x_2 - x_1)}{d} \end{pmatrix}$$

We can even rewrite this answer:

$$\begin{split} x &=& x_5 ~\pm~ \dfrac{h(y_2 - y_1)}{d} \\ y &=& y_5 ~\pm~ \dfrac{h(x_2 - x_1)}{d} \end{split}$$

Here is the Matlab script used to check the results from this page:

circle_circle_intersections.m