4
$\begingroup$

We are given a convex polygon $C = \{P_1, P_2, \dots, P_n\}$, where the points are ordered either clockwise or counter-clockwise. Additionally, we have a point $P_\text{new} = (x, y)$ that lies outside the convex hull. The goal is to find the point $P_i$ in $C$ that is closest to $P_\text{new}$ in a logarithmic time complexity. ($O(\log n)$.)

Convex polygon and a point

We can't use sorting because that would take $O(n \log(n))$ time, and also we can't use binary search because of the shape of a convex hull and we might delete the half that contains the answer.

$\endgroup$
7
  • $\begingroup$ Why would you want to use sorting if the points are already ordered clockwise? $\endgroup$ Commented Nov 28 at 2:07
  • $\begingroup$ "can't use sorting because that would take $O(n\log(n))$ time" So what is the time limit on preprocessing? Is it known whether the order is clockwise? $\endgroup$
    – greybeard
    Commented Nov 28 at 9:38
  • 1
    $\begingroup$ (Pondering that, I think a promising special case is a regular polygon with an odd number of vertices/edges. Try finding a solution here, and generalising.) $\endgroup$
    – greybeard
    Commented Nov 29 at 8:01
  • 1
    $\begingroup$ (@JohnKemeny: is there an efficient "Ternary" Search for "bimodal" functions? I suggested regular $2n+1$gons assuming distance to external points unimodal there. (There may still be two points of minimal distance - they will be adjacent.)) $\endgroup$
    – greybeard
    Commented Dec 2 at 8:14
  • 1
    $\begingroup$ Essentially identical at MATHEMATICS@SE: Algorithm to find the point in a convex polygon closest to an external point. $\endgroup$
    – greybeard
    Commented Dec 3 at 20:06

2 Answers 2

1
$\begingroup$

Start of an answer:
Given $P_{new}$ outside

  1. a regular $(2n+1)$gon (simple case):
    Pick an edge $e$ and its vertices $v_a$ and $v_b$.
    If their distances to $P_{new}$ are equal,
    either both are closest to $P_{new}$, or the vertex $v_{oe}$ opposite to $e$ is.
    Else the closest vertex is between $v_{oe}$ and the closer of $v_a$ and $v_b$, to be found using binary search.
  2. part of a regular polygon:
    Start with a wedge-shaped third of a regular polygon with lots ( $n - 1$) of vertices on the outcircle and one incident to the centre. Now move "the tip vertex" $v_t$ a bit closer to the segment; $P_{new}$ is somewhere between $v_t$ and the centre. For good measure, move every third vertex slightly inward (such that it is just outside the chord through its neighbours).
    What makes this case look hard?
    Start at one of the vertices moved inward, say, $v_i$, the next counter-clockwise from the one opposite to $v_t$:
    both its neighbours will be farther from $P_{new}$. Worse, the ninth in both directions, while local minima of distance too, will be farther than $v_i$, too.
$\endgroup$
1
  • $\begingroup$ (I mistakenly thought I had an idea for case 2.) $\endgroup$
    – greybeard
    Commented Dec 3 at 19:52
1
$\begingroup$

Let's at first find a polygon edge, closest to the external (relative to the polygon) query point q. Then, if we really need, we will be able to choose one of the edge ends.

The algorithm is based on external bisectors - rays, which originate at each polygon vertex and divide the angle (which is more than 180 grad) into two equal angles. These bisectors never intersect because of the convexity of the polygon. The guiding vector of such a bisector can be calculated as a half-sum of external normal vectors for two adjacent edges. The closest edge (which we are looking for) together with its two bisectors defines a part of plane, where the query point lies. polygon-with-closest-edge

We will call such a part of plane a cut wedge - because its vertex was cut by the polygon boundary. In general, we can consider cut wedges, consisting of a polyline (part of the polygon boundary) and two bisectors at its ends. We will need to check if the query point lies inside such a cut edge, but fortunately we don't need to traverse the polyline to perform these checks for each edge - we already know that the query point is outside the polygon. So, we can verify that the query point lies inside the cut wedge checking only its two bisectors. If the point is inside, we construct a trial bisector in the middle of the polyline, and check one of "halves". cut-wedge-and-binary-search

So, this a binary search, which starts with a pair of complementary cut wedges (for example, with bisectors, originating from $p_0$ and $p_{n/2}$) and ends when the cut wedge, containing the query point, shrinks to a single edge.

$\endgroup$
6
  • $\begingroup$ Does this also find the closest point if it lies on the opposite side of the polygon? $\endgroup$ Commented yesterday
  • $\begingroup$ @JohnKemeny - you mean almost parallel bisectors, intersecting far after the opposite side, right? Yes, thank you for this notion $\endgroup$
    – HEKTO
    Commented yesterday
  • $\begingroup$ @JohnKemeny - additional check for half plane, defined by the polyline ends. It looks like it's enough to make the algorithm work for your counterexample $\endgroup$
    – HEKTO
    Commented yesterday
  • $\begingroup$ Opposite side is an odd notion, the finite part of the wedge (parted by the chord) may be formal enough. $\endgroup$
    – greybeard
    Commented yesterday
  • $\begingroup$ (Oops. While bisectors through adjacent vertices will alway intersect if there ore no more than two collinear vertices, I am not convinced "bisectors from opposite sides" alwas will. (Start wit three bisectors :)) $\endgroup$
    – greybeard
    Commented yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.