Line Segment Intersection
Based on Chapter 2 of Computational Geometry: Algorithms and
Applications by Mark de Berg
Prof. Raúl Manzanilla
March 12, 2025
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 1 / 13
Introduction
Computational geometry deals with geometric problems using
algorithms.
One fundamental problem is determining if two line segments
intersect.
Applications include computer graphics, geographic information
systems (GIS), and robotics.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 2 / 13
Problem Definition
Given two line segments, determine if they intersect.
If they do, compute the intersection point.
The naive approach checks all pairs, leading to O(n2 ) complexity.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 3 / 13
Geometric Properties
Two line segments (p1 , q1 ) and (p2 , q2 ) intersect if:
Their endpoints are on opposite sides of each other’s supporting lines.
Special cases include collinear segments that overlap.
Orientation test using the cross product:
Orientation(p, q, r ) determines if r is left, right, or collinear with
respect to p and q.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 4 / 13
Orientation Test
Given three points (p, q, r ), the determinant of the matrix:
1 1 1
A = px qx rx is
py qy ry
1 1 1 1 0 0
det(A) = px qx rx = px qx − px rx − px
py qy ry py qy − py ry − py
= (qx − px ) · (ry − py ) − (qy − py ) · (rx − px )
> 0 : Counterclockwise
det(A) = < 0 : Clockwise
=0 : Collinear
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 5 / 13
Orientation Test
p q
Counterclockwise orientation
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 6 / 13
Sweep Line Algorithm
Efficient approach for detecting intersections among multiple
segments.
Uses a vertical sweep line moving from left to right.
Stores active segments in a balanced data structure.
The sweep line algorithm systematically processes events in increasing
x-order.
Key events:
1 Segment start: When the left endpoint of a segment is encountered,
it is added to the active set.
2 Segment end: When the right endpoint of a segment is encountered,
it is removed from the active set.
3 Intersection point: When two segments in the active set intersect, an
event is scheduled at the intersection.
The active segments are stored in a balanced binary search tree
(BST), ordered by their y-coordinates at the sweep line.
The BST enables efficient insertion, deletion, and neighbor queries to
detect potential intersections.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 7 / 13
Bentley-Ottmann Algorithm
O((n + k) log n) complexity, where k is the number of intersections.
Utilizes an event queue (sorted endpoints and intersections) and a
balanced tree (to track active segments).
Efficiently finds all intersection points.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 8 / 13
Algorithm Steps
1 Insert segment endpoints into an event queue.
2 Process events:
If a segment starts, add it to the active set.
If a segment ends, remove it.
If segments swap order, check for new intersections.
3 Maintain active segments in a balanced tree.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 9 / 13
Complexity Analysis
Naive method: O(n2 )
Bentley-Ottmann: O((n + k) log n)
Practical improvements depend on implementation details.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 10 / 13
Applications
Geographic Information Systems (GIS) for road intersections.
VLSI design in microelectronics.
Motion planning in robotics.
Computer graphics and rendering.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 11 / 13
Conclusion
Line segment intersection is a fundamental problem in computational
geometry.
The sweep line algorithm provides an efficient solution.
Optimizations depend on the number of segments and expected
intersections.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 12 / 13
References
M. de Berg, O. Cheong, M. van Kreveld, and M. Overmars,
Computational Geometry: Algorithms and Applications.
Additional references on geometric algorithms.
Prof. Raúl Manzanilla Line Segment Intersection March 12, 2025 13 / 13