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
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:
$$\begin{array}{llll}\text{If}& b\xe2\u20300& \text{:}& y=mx+{y}_{0}\\ \text{If}& b=0& \text{:}& x=k\end{array}$$
with:
$$\begin{array}{lll}m=\xe2\u02c6\u2019\frac{a}{b}\text{,}& {y}_{0}=\xe2\u02c6\u2019\frac{c}{b}\text{,}& k=\xe2\u02c6\u2019\frac{c}{a}\end{array}$$
Here m is called the slope or gradient of the line and y_{0} 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\xe2\u02c6\u2019{x}_{m}\right)}^{2}+{\left(y\xe2\u02c6\u2019{y}_{m}\right)}^{2}={r}^{2}\\ \xe2\u2021\u201d\\ {x}^{2}\xe2\u02c6\u20192x{x}_{m}+{{x}_{m}}^{2}+{y}^{2}\xe2\u02c6\u20192y{y}_{m}+{{y}_{m}}^{2}\xe2\u02c6\u2019{r}^{2}=0\end{array}$$
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=\xe2\u02c6\u2019\frac{c}{a}$), the coordinates of the intersection points of a line and a circle are $P=\left(\xe2\u02c6\u2019\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 x_{p}:
$${x}_{p}=\frac{\xe2\u02c6\u2019B\xc2\pm \sqrt{{B}^{2}\xe2\u02c6\u20194AC}}{2A}$$ with: $$A=\frac{{a}^{2}}{{b}^{2}}+1$$ $$B=2\left(\frac{ac}{{b}^{2}}\xe2\u02c6\u2019{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}}\xe2\u02c6\u2019{r}^{2}$$
Let $D={B}^{2}\xe2\u02c6\u20194AC$ :
- If D < 0, then x_{p} has no solutions; line and circle do not intersect.
- If D = 0, then x_{p} has exactly one solution; line is tangent to circle.
- If D > 0, then x_{p} 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 y_{p}:
$${y}_{p}=\frac{\xe2\u02c6\u2019B\xc2\pm \sqrt{{B}^{2}\xe2\u02c6\u20194C}}{2}$$ with: $$B=\xe2\u02c6\u20192{y}_{m}$$ $$C={{x}_{m}}^{2}+{{y}_{m}}^{2}+\frac{2c}{a}{x}_{m}+\frac{{c}^{2}}{{a}^{2}}\xe2\u02c6\u2019{r}^{2}$$
Let $D={B}^{2}\xe2\u02c6\u20194C$ :
- If D < 0, then y_{p} has no solutions; line and circle do not intersect.
- If D = 0, then y_{p} has exactly one solution; line is tangent to circle.
- If D > 0, then y_{p} has two solutions; line and circle intersect at two points.
Task
Calculate the intersection points (if they exist) of $y=3x\xe2\u02c6\u20192$ and ${\left(x\xe2\u02c6\u20196\right)}^{2}+{y}^{2}=36$.
Tips
Take a = âˆ’3, b = 1, c = 2, x_{m} = 6, y_{m} = 0 and r = 6. With the JavaScript application above you can check your calculations.