1

Let P be a simple, but not necessarily convex, polygon and q an arbitrary point not necessarily in P.

Design an efficient algorithm to find a line segment originating from q that intersects the maximum number of edges of P.

In other words, if standing at point q, in what direction should you aim a gun so the bullet will go through the largest number of walls?

A bullet through a vertex of P gets credit for only one wall.

An O(n log n) algorithm is possible. n is the number of vertices or edges, as it is a polygon, number of edges roughly equals to number of vertices.

this is the same as this this question however I was not able to understand the answer, more specifically the answer did not seem to involve q, also the head and butts thing was not clear as each point on a polygon would be a head and a butt as each point is attached to two edges, if that makes sense. Thanks

Community
  • 1
  • 1
seanrodda
  • 35
  • 4

1 Answers1

2

So any optimal answer that does not intersect the polygon near any vertex will have a fellow optimal answer that nearly intersects a vertex of the polygon.

That is, if you have a line going through 10 "walls" and it is not near a vertex you can translate it in some direction towards a vertex while still keeping 10 walls intersected.

By this reasoning you only have to search for solutions that pass near verticies.

So sort the verticies (nlogn) and then search each possible line segment that nearly intersects one (3n). You can do this without recalculating the full set of intersections on each candidate line, because as the line moves from one vertex to another it either adds or loses 2 walls (or remains the same). You can track this incremental change.at constant time at each step.

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319