Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the intersection points of all the line segments

Given a list of line segments, the easiest way to find the intersection points is to loop through the line segment list, check whether they are intersecting and record the intersection point if they do.

But the runtime of this method is O(n^2), which is very inefficient. Is there any other algorithm that could speed up this process?

like image 702
Graviton Avatar asked Nov 08 '10 15:11

Graviton


People also ask

How do you find the intersection of a segment?

Parameterization of line segments Define b = q1 - p1 and x = (s,t). If the solution of the linear system A*x = b is in the unit square, then the segments intersect. If the solution is not in the unit square, the segments do not intersect.

How do you find all points of intersection?

We calculate it by solving the equation f(x) = 0 . When the graphs of y = f(x) and y = g(x) intersect , both graphs have exactly the same x and y values. So we can find the point or points of intersection by solving the equation f(x) = g(x).

How many points of intersection is 5 lines?

The maximum number of points of intersection when 5 lines are drawn in a plane, as shown, is 10 points.

How many points of intersection are possible for 2 lines?

Two distinct lines will always intersect in at most one point.


1 Answers

The Bentley-Ottmann Algorithm may be what you are looking for.

like image 103
finnw Avatar answered Oct 18 '22 21:10

finnw