6

I'm creating a simple game and come up with this problem while designing AI for my game: Given a set of N points inside a rectangle in the Cartesian coordinate, i need to find the widest straight path through this rectangle. The path must be empty (i.e not containing any point).

enter image description here

enter image description here

I wonder if are there any efficient algorithm to solve this problem? Can you suggest any keyword/ paper/ anything related to this problem?

EDIT: The rectangle is always defined by 4 points in its corner. I added an image for illustration. the path in the above pictures are the determined by two red lines

Chan Le
  • 2,184
  • 3
  • 23
  • 33

3 Answers3

6

This is the widest empty corridor problem. Houle and Maciel gave an O(n2)-time, O(n)-space algorithm in a 1988 tech report entitled "Finding the widest empty corridor through a set of points", which seems not to be available online. Fortunately, Janardan and Preparata describe this algorithm in Section 4 of their paper Widest-corridor problems, which is available.

some guy
  • 76
  • 1
  • :-? It seems to be quite complicated to me :( Could you please give an explanation on this algorithm? – Chan Le Apr 28 '11 at 02:32
2

Loop through all pairs of points. Construct a line l through the pair. (^1) On each side of l, either there are other points, or not. If not, then there is not a path on that side of l. If there are other points, loop through points calculating the perpendicular distance d from l to each such point. Record the minimum d. That is the widest path on that side of l. Continue looping through all pairs, comparing widest path for that pair with the previous widest path.

This algorithm can be considered naive and runs in O(n^3) time.

Edit: The above algorithm misses a case. At ^1 above, insert: "Construct two lines perpendicular to l through each point of the pair. If there is no third point between the lines, then record distance d between the points. This constitutes a path." Continue the algorithm at ^1. With additional case, algorithm is still O(n^3)

ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
  • I don't think this algorithm works in the case of the equilateral triangle. It would return half the base as the widest path, instead of the height. – Cephron Apr 27 '11 at 04:06
  • 1
    @Cephron, hmm no. It would return the height in three different directions. This algorithm is not affected by the orientation of the points. The line, and therefore the path, is determined by the first two points, and they can be any direction from each other. – ThomasMcLeod Apr 27 '11 at 04:28
  • Ah! Yes, I understand now. I thought you were meaning the path between the pair of points, as opposed to a path on either side of the pair. My bad! – Cephron Apr 27 '11 at 04:53
  • You need three points to determine the path. however, I think there is the case when one pair of point also determine the path. http://i.imgur.com/Zc57K.png – Chan Le Apr 27 '11 at 12:13
  • @Chan, thanks, I missed that one. I added the additional case. – ThomasMcLeod Apr 27 '11 at 14:32
1

Myself, I would start by looking at the Delaunay triangulation of the point set: http://en.wikipedia.org/wiki/Delaunay_triangulation

There appear to be plenty of resources there on efficient algorithms to build this - Fortune's algorithm, at O(n log n), for starters.

My intuition tells me that your widest path will be defined by one of the edges in this graph (Namely, it would run perpendicular to the edge, and its width would be equal to the length of the edge). How to sort the edges, check the candidates and identify the widest path remains. I like this question, and I'm going to keep thinking about it. :)

EDIT 1: My intuition fails me! A simple equilateral triangle is a counter-example: the widest path is shorter than any of the edges in the triangulation. Still thinking...

EDIT 2: So, we need a black-box algorithm which, given two points in the set, finds the widest path through the point set which is bounded by those two points. (Visualize two parallel lines running through the two points; rotate them in harmony with each other until there are no points between them). Let's call the runtime of this algorithm 'R'.

Given such an algorithm, we can do the following:

  1. Build the Delaunay triangulation of the point set : O(n log n)
  2. Sort the edges by width : O(n log n)
  3. Beginning with the largest edge and moving down, use the black box algorithm to determine the widest path involving those two points; storing it as X : O(nR))
  4. Stop when the edge being examined is shorter than the width of X.

Steps 1 and 2 are nice, but the O(nR) is kind of scary. If R turns out to be O(n), that's already O(n^2) for the whole algorithm. The nice thing is that, for a general set of random points, we would expect that we wouldn't have to go through all the edges.

Cephron
  • 1,577
  • 1
  • 19
  • 26
  • If your equilateral triangle is within a rectangle, you would have to include the boundaries of the rectangle, giving you eight triangles and 12 edges. Surely one of those edges is perpendicular to the solution. – JoshRoss Apr 27 '11 at 03:27