0

I would like to find all intersections between straight line (infinite). I'm trying change the Bentley-Ottmann algorithm which works for set of line segments, but I have no idea how to represent infinite straight line properly. The first idea was to determine boundary points which would simulate start and end each of lines, but I suppose it's incorrect solution (how to find "infinite" points?). The next idea is to use equations to represent the straight lines, but I don't know if I can use Bentley-Ottmann algorithm (how to order lines and to add events to schedule?). What's more I probably need to use division to detect intersection of two lines (while solving a set of equations). I would like to avoid it.

Can you give me some advice?

Thanks a lot

oknais
  • 31
  • 4
  • Infinite lines are easy. Solve simultaneous equations that represent the lines. How many dimensions are you dealing with? – Persixty Jan 02 '15 at 12:21
  • Use the 2 straight line equation y = mx + b; then solve! – Alexxx Jan 02 '15 at 12:23
  • What you are trying to solve is known as the line arrangement problem. Specific solutions are known, but not so easy: http://en.wikipedia.org/wiki/Arrangement_of_lines#Algorithms. –  Jan 02 '15 at 21:00

2 Answers2

0

Assuming you are doing this in 2-dimension Euclidean space, you are over-inflating your problem. High schoolers will tell you that lines can be represented by an equation:

y = m*x + b

But it can't represent a vertical line. You can use the more generic equation (see MathWorld):

a*x + b*y = c

In two-dimension Euclidean space, two lines either:

  • Have a single common point; or
  • No common point: they are parallel to each other; or
  • Have infinite numbers of common points: they are the same line.

The first 2 cases are an equation-solve away. The third case is true if:

a1/a2 == b1/b2

(of course you need to handle cases where a2 = 0 or b2 = 0)

0

Forget Bentley Ottman. It's cleverness is for dealing with line segments, which you don't have.

If the lines are infinite, then every pair of non-parallel lines will have exactly one intersection. So if {L1, L2, ... Ln} is the set of all lines, the algorithm is:

for Li, i = 1, 2, ... n-1
  for Lj, j = i+1, ... n
    if Li parallel to Lj, output <i, j, PARALLEL> 
    else output <i, j, intersection(Li, Lj)>

You could include a separate check to fine coincident parallel lines if that's useful.

The most robust way to store arbitrary lines is (as already mentioned), the coefficient triple:

<A, B, C>

such that Ax + By + C = 0. It's handy and good practice to normalize so that A^2 + B^2 = 1. Now [A,B] is the unit normal to the line. With some vector math it's pretty easy to see that the intersection P of two lines g and h is given by a simple cross product:

P = [x/w, y/w], where [x,y,w] = [Ag, Bg, Cg] X [Ah, Bh, Ch]

Note that for parallel (including coincident) lines, you'll get w=0 so the division will fail as you'd expect. You can use very small absolute w values to detect the parallel case above. This is one reason to normalize [A, B]. It makes this test scale-independent.

Gene
  • 46,253
  • 4
  • 58
  • 96