1

Is it possible to find an upper and lower tangent line to a convex hull in $log(n)$ time where $n$ is number of points on a convex hull? I have just done it in linear time where I checked for upper tangent line if orientation of $S,i,i+1$ is greater than zero (anti-clockwise) and if orientation of $S,i,i-1$ is greater than zero as well. Same for lower tangent line where I checked if its clockwise orientation. $S$ is a point from where I want my tangent line to go, $i$ is a point on a convex hull and $i-1$,$i+1$ are its neighbours. This is the only source I've found so far [Link]$_1$ and I really can't understand the algorithm for now.

Exzone
  • 235
  • 2
  • 11

1 Answers1

3

Let's assume that the convex polygon $P$ is defined as an ordered list $(p_0,p_1,...,p_{n-1})$ of points, and for each such point $p \in P$ we are able in $O(1)$ time to find a previous point $Prev(p)$ and a next point $Next(p)$ according to this order, taking into account that:

$$Prev(p_0)=p_{n-1}$$ $$Next(p_{n-1})=p_0$$

The binary search over this list is very similar to a binary search over a regular array - on each step you have a $p_{min}$ point, a $p_{max}$ point and a $p_{mid}$ point. You check some condition on the $p_{mid}$ point and then choose a $[p_{min},p_{mid}]$ interval or a $[p_{mid},p_{max}]$ interval for the next step.

The condition you want to check is the following one. In order for the $p_{mid}$ point to be the tangential point for all lines going through the query point $S$, both neighbors of the $p_{mid}$ point must be on the same side of the line, connecting the point $S$ and the $p_{mid}$. You'll have to choose, which side of this line is right and which side is wrong - this will define, which tangent line you'll get (upper or lower). So, if the previous point $Prev(p_{mid})$ is on the wrong side, then you choose the left interval. Similarly, if the next point $Next(p_{mid})$ is on the wrong side of this line, then you choose the right interval for the next step. This algorithm will stop on one of two tangential points if and only if the point $S$ is located outside of the polygon $P$.

The algorithm doesn't need any preprocessing of the convex polygon $P$ and nevertheless finds tangential points for any query point, located outside of the polygon, in $O(\log n)$ time.

HEKTO
  • 3,173
  • 16
  • 19