Intersection of a line and a circle

Introduction

In this article it will be explained how to calculate the coordinates of the points ( P = x p y p ) 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:

a x + b y + 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:

If b ≠ 0 : y = m x + y 0 If b = 0 : x = k with:
m = − a b , y 0 = − c b , k = − c a [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 = x m y m be the circle center and r be the circle radius in the general circle equation:

x − x m 2 + y − y m 2 = r 2 ⇔ x 2 − 2 x x m + x m 2 + y 2 − 2 y y m + y m 2 − r 2 = 0 [2]

Intersection points

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

When the line is vertical ( x = − c a ), the coordinates of the intersection points of a line and a circle are P = − c a y p (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 = m x + 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 + B x + C = 0

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

x p = − B ± B 2 − 4 A C 2 A with: A = a 2 b 2 + 1 B = 2 a c b 2 − x m + a b y m C = x m 2 + y m 2 + 2 c b y m + c 2 b 2 − r 2

Let D = B 2 − 4 A C :

Intersection with vertical line

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

y 2 + B y + C = 0

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

y p = − B ± B 2 − 4 C 2 with: B = − 2 y m C = x m 2 + y m 2 + 2 c a x m + c 2 a 2 − r 2

Let D = B 2 − 4 C :

Task

Calculate the intersection points (if they exist) of y = 3 x − 2 and x − 6 2 + y 2 = 36 .

Tips

Take a = −3, b = 1, c = 2, xm = 6, ym = 0 and r = 6. With the JavaScript application above you can check your calculations.