Intersection of a line and a circle
Introduction
In this article it will be explained how to calculate the coordinates of the points () 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
Line equation
Let a, b and c be the line parameters in the general linear equation:
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:
[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 ().
Circle equation
Let be the circle center and r be the circle radius in the general circle equation:
[2]
Intersection points
Given that (equation [1]), means that the coordinates of the intersection points of a non-vertical line and a circle are (if any exists).
When the line is vertical (), the coordinates of the intersection points of a line and a circle are (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] () 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:
Solving this equation for x gives us the x-coordinates xp:
with:
Let :
- 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:
Solving this equation for y gives us the y-coordinates yp:
with:
Let :
- 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.
Task
Calculate the intersection points (if they exist) of and .
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.