# Intersection of a line and a circle

## Introduction

In this article it will be explained how to calculate the coordinates of the points ($P=\left({x}_{p},{y}_{p}\right)$) where a line and a circle intersect. The required equations will be derived and an interactive application is provided to calculate the intersection points of a given line and circle. A line and a circle have no intersection points, one intersection point (line is tangent to circle) or two intersection points ðŸ™„.

## JavaScript application

Input mode:
Line parameters:

Circle parameters:

Circle with center M = (xm , ym) and radius r:

P1 =

P2 =

## Line equation

Let a, b and c be the line parameters in the general linear equation:

$ax+by+c=0$

We can rewrite this general form of the equation to the so called slope-intercept form, which is generally the form for representing an equation of a straight line in the Euclidean plane:

with:
$\begin{array}{lll}m=âˆ’\frac{a}{b}\text{,}& {y}_{0}=âˆ’\frac{c}{b}\text{,}& k=âˆ’\frac{c}{a}\end{array}$ [1]

Here m is called the slope or gradient of the line and y0 is called the y-intercept. If b = 0, the line is a vertical line ($x=k$).

## Circle equation

Let $M=\left({x}_{m},{y}_{m}\right)$ be the circle center and r be the circle radius in the general circle equation:

$\begin{array}{c}{\left(xâˆ’{x}_{m}\right)}^{2}+{\left(yâˆ’{y}_{m}\right)}^{2}={r}^{2}\\ â‡”\\ {x}^{2}âˆ’2x{x}_{m}+{{x}_{m}}^{2}+{y}^{2}âˆ’2y{y}_{m}+{{y}_{m}}^{2}âˆ’{r}^{2}=0\end{array}$ [2]

## Intersection points

Given that $y=-\frac{a}{b}x-\frac{c}{b}$ (equation [1]), means that the coordinates of the intersection points of a non-vertical line and a circle are $P=\left({x}_{p},-\frac{a}{b}{x}_{p}-\frac{c}{b}\right)$ (if any exists).

When the line is vertical ($x=âˆ’\frac{c}{a}$), the coordinates of the intersection points of a line and a circle are $P=\left(âˆ’\frac{c}{a},{y}_{p}\right)$ (if any exists).

### Intersection with non-vertical line

A point where a line and circle intersect (or touch) must be a point belonging to both the line and the circle. Substituting line equation [1] ($y=mx+{y}_{0}$) in circle equation [2] yields an equation in which x represents the x-coordinates of the intersection points (if any exists). Substitution results in an equation of the form:

$A{x}^{2}+Bx+C=0$

Solving this equation for x gives us the x-coordinates xp:

${x}_{p}=\frac{âˆ’BÂ±\sqrt{{B}^{2}âˆ’4AC}}{2A}$ with: $A=\frac{{a}^{2}}{{b}^{2}}+1$ $B=2\left(\frac{ac}{{b}^{2}}âˆ’{x}_{m}+\frac{a}{b}{y}_{m}\right)$ $C={{x}_{m}}^{2}+{{y}_{m}}^{2}+\frac{2c}{b}{y}_{m}+\frac{{c}^{2}}{{b}^{2}}âˆ’{r}^{2}$

Let $D={B}^{2}âˆ’4AC$ :

• If D < 0, then xp has no solutions; line and circle do not intersect.
• If D = 0, then xp has exactly one solution; line is tangent to circle.
• If D > 0, then xp has two solutions; line and circle intersect at two points.

### Intersection with vertical line

Substituting vertical line equation x = k in circle equation [2] results in an equation of the form:

${y}^{2}+By+C=0$

Solving this equation for y gives us the y-coordinates yp:

${y}_{p}=\frac{âˆ’BÂ±\sqrt{{B}^{2}âˆ’4C}}{2}$ with: $B=âˆ’2{y}_{m}$ $C={{x}_{m}}^{2}+{{y}_{m}}^{2}+\frac{2c}{a}{x}_{m}+\frac{{c}^{2}}{{a}^{2}}âˆ’{r}^{2}$

Let $D={B}^{2}âˆ’4C$ :

• If D < 0, then yp has no solutions; line and circle do not intersect.
• If D = 0, then yp has exactly one solution; line is tangent to circle.
• If D > 0, then yp has two solutions; line and circle intersect at two points.

Calculate the intersection points (if they exist) of $y=3xâˆ’2$ and ${\left(xâˆ’6\right)}^{2}+{y}^{2}=36$.