Line Intersection Detector

Draw line segments and find their intersections using computational geometry

Instructions

Click twice on the canvas to draw a line segment. Continue clicking to add more segments. The detector will automatically find and highlight all intersection points.

0
Line Segments
0
Intersections
Complete Line Segments
Current Drawing
Intersection Points
Endpoints

Help

How to Use
  • Draw segments: Click twice on the canvas to create a line segment
  • Add more segments: Keep clicking to add additional line segments
  • View intersections: Red dots automatically appear where segments intersect
  • Clear canvas: Use the "Clear All" button to start over
  • Undo: Remove the most recently drawn segment
Line Intersection Algorithm

This app uses computational geometry to detect line segment intersections:

  • Basic approach: Checks all pairs of line segments for intersections
  • Intersection test: Uses vector cross products and parametric equations
  • Time complexity: O(n²) for n line segments (naive approach)
  • Practical optimization: Bentley-Ottmann sweep line algorithm can achieve O((n + k) log n) where k is the number of intersections
Applications
  • Computer Graphics: Rendering, clipping, hidden surface removal
  • CAD Systems: Detecting overlaps in engineering drawings
  • GIS: Map overlay operations, route planning
  • Robotics: Path planning and collision detection
  • Game Development: Collision detection, ray casting
Mathematical Background

Two line segments intersect if:

  • Orientation test: The segments straddle each other (opposite orientations)
  • Parametric form: Each segment can be expressed as P = P1 + t(P2 - P1) where 0 ≤ t ≤ 1
  • Intersection point: Solve the system of parametric equations to find the intersection coordinates
  • Cross product: Used to determine if points are on opposite sides of a line
Special Cases
  • Parallel segments: No intersection unless collinear
  • Collinear segments: May overlap (not detected as point intersection)
  • Endpoint touching: Counted as intersection
  • Degenerate segments: Single points (length 0) are handled