Skip to main content
100%

line-intersection

✓ Published0🌍 Public
Aapburnes
Last edited May 25, 2016
Created on May 25, 2016

This interactive visualization demonstrates the Bentley–Ottmann algorithm for finding line segment intersections. Users can drag endpoints to move lines, click to add new line segments, and right-click to remove them. The algorithm efficiently computes intersections using a sweep line rather than checking all pairs, achieving O(n log n + I log n) complexity. The right panel displays the current x-ordering of lines as the sweep progresses. Built with SVG and D3, the visualization updates in real time as users manipulate the line segments.

AI-generated description

The Bentley–Ottmann algorithm finds all the intersections that occur in a set of line segments. Drag the endpoints of the line to move, click to add and right click to remove.

Instead of calculating the intersection of every pair of segments, which would require O(n²) comparisons for a set of n lines, the algorithm uses a sweep line. Starting at the top of the screen and moving down, it keeps track of the order of the lines' x positions at the current y position (represented by the figure on the right). As lines start, end or intersect, new pairs of lines become adjacent in the x ordering and are checked for intersections.

A set of lines with I intersections ends up only requiring O(n log n + I log n) operations. Computational Geometry: Algorithms and Applications, chapter 2 has a proof and a more detailed explanation.

forked from <a href='http://bl.ocks.org/1wheel/'>1wheel</a>'s block: <a href='http://bl.ocks.org/1wheel/464141fe9b940153e636'>line-intersection</a>

forked from <a href='http://bl.ocks.org/apburnes/'>apburnes</a>'s block: <a href='http://bl.ocks.org/apburnes/68f69b32d86f6d987ddfd0e2c48d2872'>line-intersection</a>

forked from <a href='http://bl.ocks.org/apburnes/'>apburnes</a>'s block: <a href='http://bl.ocks.org/apburnes/c0d53f70215d4a49a200d24a5c0e6b3a'>line-intersection</a>

forked from <a href='http://bl.ocks.org/apburnes/'>apburnes</a>'s block: <a href='http://bl.ocks.org/apburnes/42118e82a0756867276c9afe5567e0c5'>line-intersection</a>

forked from <a href='http://bl.ocks.org/apburnes/'>apburnes</a>'s block: <a href='http://bl.ocks.org/apburnes/70b94260e227098fcca7caa069768655'>line-intersection</a>

forked from <a href='http://bl.ocks.org/apburnes/'>apburnes</a>'s block: <a href='http://bl.ocks.org/apburnes/29954d6dd6659485a402273b5dd8f3f4'>line-intersection</a>

Similar vizzes