0

Given a (non-convex) Polygon $P$ and a straight line segment $S$ in $\mathbb{R}^2$, where $S$ and $P$ are disjoint, I am looking for an efficient algorithm to find a point $s$ on $S$ which has the maximum distance from $P$ among all points on $S$ (and the actual distance, which is then trivial, of course).

To be clear, the distance $dist(s,P)$ between one point $s$ and $P$ is the minimum distance between $s$ and all points in $P$ (which I can calculate by a standard point-to-polygon algorithm). So another way to write this formally is:

"Determine $max(min(|p-s| : p \in P) : s \in S)$ (and the related points)".

Note the point of maximum distance can be somewhere in the middle of $S$:

enter image description here

I have checked some standard resources (including this site) and books from computational geometry, but had no luck so far. If $S$ is described as a parametric curve $c(t)$ where $t \in [0,1]$, this is the problem of finding the global maximum of $dist(c(t),P)$ in $[0,1]$, so it would even help me if someone has an idea how to split $[0,1]$ into subintervals where each subinterval contains only a local maximum. That would allow me to apply a standard numerical maximum search algorithm to each of the subintervals.

Any ideas?

Doc Brown
  • 210

4 Answers4

2

Hint:

If I am right, the Euclidean distance map to a polygon is made of planar and conic patches (along edges and around vertices respectively). Their construction is analogue to that of the Voronoi diagram of the polygon. (But strangely, the case of the Voronoi diagram on the outside of a filled polygon seems to never have been addressed.)

The case of a convex polygon is easy. That of a concave one, much less.

If you project the line segment S onto this map, you will traverse line segments and hyperbolas. As the concavity is downward, the searched maximum will occur either at the intersection of patches or at the segment endpoints.

Could be solved with a version of Fortune's sweepline algorithm, adapted to polygons, if that exists...

  • Ok, this is seems to be a start. However, construction of those hyperbolas does not look simple. – Doc Brown Jan 18 '19 at 14:44
  • @DocBrown: you don't have to worry about the hyperbolas, but you must construct the edges of the Voronoi diagram. Most probably doable in time O(N Log N). –  Jan 18 '19 at 14:51
  • Thinking about it, it seems the Voronoi diagram of the edges of a polygon does not consist just of one dimensional curves, it will contain 2-dimensional parts of the plane (quite different from a Voronoi diagram of a finite set of points), Or maybe I misunderstood you? – Doc Brown Jan 18 '19 at 15:08
  • @DocBrown: all 2D Voronoi diagrams are planar graphs that define a partition of the plane. By the way, you don't consider the VD of the edges but of the whole polygonal region (most probably the same outside, but you don't have to worry about the inside). –  Jan 18 '19 at 15:12
0

Not an answer but a request for clarification.

I would have considered this as the maximum distance:

enter image description here

Do you mean the maxmin distance where the maximum is taken over the line segment points ?

  • Yes, I meant what you called maxmin distance. If you read my question more careful again, you will find it all written in there. – Doc Brown Jan 18 '19 at 11:05
0

After thinking a while about the problem, it seems I found an answer for my own question. For S having endpoints $s_1$ and $s_2$, let

$f(t) := dist(c(t),P)$ for $t \in [0,1]$, where $c(t) = s_1 + (s_2-s_1) \times t, t \in[0,1]$

As written in the question, the task is to find the global maximum of $f$. Furthermore, let $E_1, ... , E_n$ be the edges of $P$, and $f_i(t):=dist(c(t),E_i)$ the distance function which correspond to the edge $E_i$ . Since $S$ and $P$ are disjoint, f can be written as

$f(t) = \min\{f_i(t) :i=1...n\}$

Since $E_i$ and $S$ are line segments, each $f_i$ is either monotone or unimodal, so except for the edge case where $E_i$ and $S$ are parallel, it has exactly one local minimum $t_{m,i} \in [0,1]$. This minimum is easy to calculate, since it will always be reached at one of the end points of either $E_i$ or $S$. (For the parallel case, $f_i$ will reach its minimum on an interval $[t_{m1,i}, t_{m2,i}] \subset [0,1]$, and one can replace $t_{m,i}$ by the two points $t_{m1,i}, t_{m2,i}$ in the following.)

Now, if $f$ has a local minimum in $[0,1]$, then it must be also a local minimum of $f_i$ for at least one $i\in\{1...n\}$. So the set $M:=\{t_{m,i} | i=1,...,n\}$ is a superset of all local minima of $f$. And since each local maximum of a continuous function on $\mathbb{R}$ is separated from the previous and the next local maximum by a local minimum betweem them, one can sort $M$ in ascending order and use the result to split up the interval $[0,1]$ into subintervals, where each one contains one local maximum of $f$ at most. These subintervals then can be searched for the value $t_{M,i}$ which maximizes $f$ by a Golden-section search. The final result then is the $t_{M,i}$ which maximizes $f(t_{M,i})$.

Since the numerical search will still involve lots calculations for determining $dist(p,P)$ for several points $p \in S$, a further speed-up can be achieved by presorting the edges $E_1, ... , E_n$ by their distance from $S$. So when $d_k=min(dist(p,E_1)$, $dist(p,E_2)$, ..., $dist(p,E_k))$ is calculated already for one $k$, and $dist(S,E_{k+1})$ is bigger than $d_k$, the minimum distance calculation of $dist(p,P)$ can be stopped, since the further edge distances won't change $d_k$ any more.

Doc Brown
  • 210
-1

Edit: Since the poster clarified himself, the below is irrelevant to his new formulation of the problem. I'll leave it since it solves the old formulation: $\max_{s \in S}{\max_{p \in P}{d(s,p)}}$.

Measure all distances between the polygon's vertices and the line segment's endpoints, pick the maximum. The algorithm works in $O(V)$, there cannot be a faster one since you need to at least iterate over the vertices to get the correct answer.

lightxbulb
  • 2,047
  • Sorry, but this wrong. The point which has the maximum distance can be somewhere in the middle of the segment. – Doc Brown Jan 18 '19 at 10:32
  • Can you provide a counterexample? – lightxbulb Jan 18 '19 at 10:34
  • I think you are incorrect, consider a triangle formed by the line segment and a non-collinear point, the max distance is not on the inside of the line segment, you can prove it. @Doc Brown – lightxbulb Jan 18 '19 at 10:39
  • I added an image. The problem cannot be easily reduced to endpoints of segments. Note the corresponding points on the polygon's edge are no endpoints of any edge as well. – Doc Brown Jan 18 '19 at 10:44
  • @Doc Brown I think I misread your question then, I thought you wanted to find a point on $S$, such that $max_{s \in S}{max_{p \in P}{d(s,p)}}$. Please edit your question to formalize the objective (which I think is): $\max_{s \in S}{min_{p \in P}{d(s,p)}}$. – lightxbulb Jan 18 '19 at 10:53
  • I already wrote about taking the maximum over the minimum distances, but if you think it helps to repeat myself ... see my edit (sigh). – Doc Brown Jan 18 '19 at 11:10
  • Thank you. It's a lot easier to understand when you formalize it. – lightxbulb Jan 18 '19 at 11:13