Skip to content
CoreSource checked

Circle-Line Intersection

Finds where a line crosses, touches, or misses a circle.

Quick Facts

Compact metadata for implementation and discovery.

Category
Geometry
Difficulty
Intermediate
Family
Geometric Intersection
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
4
Code example
Ready
Visualization
Ready

Overview

Circle-line intersection substitutes a line equation into the circle equation and solves the resulting quadratic, or equivalently projects the circle center onto the line and compares distance to the radius.

Core Concepts

circle and line intersectiongeometric intersectiongeometric primitivesgeometry

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(1)

When to Use

  • Use when the line and circle are represented with compatible coordinate units.
  • Use when tangent and near-tangent cases can be handled carefully.

When Not to Use

  • Avoid when a segment or ray is needed but the implementation only handles infinite lines.
  • Avoid when floating-point tolerance has not been defined for tangent cases.

What It Does

  • Computes distance from the circle center to the line
  • Classifies no intersection, tangent, or two intersections
  • Solves for intersection points when they exist

Use Cases

  • Collision and visibility tests
  • Geometric construction routines
  • Ray or segment intersection preprocessing

Inputs

  • Points, segments, polygons, or geometric primitives
  • Query or construction parameters

Outputs

  • Geometric decision, measurement, or constructed structure

Key Formulas (1)

Quadratic substitution

||p0 + t·d − c||2 = r2
||p0 + t*d - c||^2 = r^2

Solves for line parameters where the line reaches the circle radius.

Pseudocode

  1. 1.Represent the line as point p plus direction d
  2. 2.Project circle center onto the line
  3. 3.Compute squared distance from center to the projection
  4. 4.Compare it with radius squared
  5. 5.Return zero, one, or two points using the offset along d

Canonical Example

Input
circle center (0, 0), radius 1, line y = 0
Output
intersection points (-1, 0) and (1, 0)
Explanation
Substituting y = 0 into x^2 + y^2 = 1 leaves x^2 = 1.

Implementation Notes

  • Normalize the line direction or account for its squared length in formulas.
  • Use a tolerance around the discriminant or distance comparison.
  • Test no-hit, tangent, and two-hit cases.

Common Pitfalls

  • Treating a tangent as two distinct intersections.
  • Forgetting to clamp solutions when the input is a segment rather than a line.
  • Using a tolerance that is too large can create false intersections.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show substituting a line into a circle equation and solving the resulting quadratic on a small circle and line intersection example.

Circle-Line Intersection mechanism walkthrough step 1 of 5
Step 1 of 5: Represent the line as point p plus direction d
geometry-mechanism

Notes

Clarify whether the input is an infinite line, ray, or segment before using the intersection result.

Sources (2)

What each reference supports for this entry.

Computational Geometry: Algorithms and Applications

Book

Computational geometry textbook support for Circle-Line Intersection's geometric model, data structures, and robustness concerns.

Open source

Real-Time Collision Detection

Book

Geometric collision reference for Circle-Line Intersection's primitive tests, bounding volumes, and numerical edge cases.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborPoint-to-Segment Distance

Both use geometric intersection ideas for related circle and line intersection problems.

Conceptual neighborOrthogonal Range Search

Both use geometric intersection ideas for related circle and line intersection problems.

Conceptual neighborPoint-Line Distance

Both use geometric intersection ideas for related circle and line intersection problems.

Tags

GeometryComputational Geometry