Partially Walking a Polygon

Deciding two-guard walkability of an n -sided polygon is a well-understood problem. We study the following more general question: How far can two guards reach from a given source vertex while staying mutually visible, in the (more realistic) case that the polygon is not entirely walkable? There can be Θ( n ) such maximal walks, and we show how to ﬁnd all of them in O ( n log n ) time. 2012 ACM Subject Classiﬁcation Theory of computation → Design and analysis of algorithms


Introduction
We address the following structural question on polygons: How many adjacent ear triangles can be cut off from a polygon W , starting from a given vertex s?This question was originally motivated by optimizing so-called triangulation axes, a recently introduced skeletal structure for simple polygons [1].An equivalent formulation of the problem, which is of interest in its own right, reads as follows: How far can two guards reach when they are to walk on W 's boundary, starting from s in different directions and staying mutually visible?Visibility problems of this kind have been studied already in the 1990s, where Icking and Klein [6] gave an O(n log n) time algorithm for deciding two-guard walkability of an n-sided polygon W , from a source vertex s to a target vertex t.A few years later, Tseng et al. [7] showed that one can find, within the same runtime, all vertex pairs (s, t) such that W is two-guard walkable from s to t.Their result was improved to optimal O(n) time by Bhattacharya et al. [3].The algorithm in [6] actually provides a walk for W in case of its existence but, on the other hand, only a negative message is returned in the (quite likely) case that the polygon is not entirely walkable.
The present paper elaborates on 'how far' in the latter case a polygon W is two-guard walkable -a natural question that has not been considered in the literature to the best of our knowledge.Such maximal walks are not unique, in general, which complicates matters.We present a strategy that finds, in O(n log n) time, all possible maximal walks that initiate at a given source vertex s of W .A preliminary version of this paper appeared in [2].For an account of related visibility questions on polygons, we refer to the survey article by Urrutia [8] on art gallery problems.

Preliminaries
We start with introducing the concepts and notations needed later in our considerations.Throughout, we let W denote a simple polygon in the plane with n vertices, one of them being tagged as a source vertex, s.For two points x and y on the boundary, ∂W , of W , we write x < y if x is reached before y when walking on ∂W from s in clockwise (CW) direction.For a vertex p of W , p + denotes the CW successor vertex of p on ∂W .Similarly, p − denotes the CW predecessor vertex of p on ∂W .When p is a reflex vertex (that is, a vertex where the interior angle in W is greater than π), then the two 'ray shooting points' for p in W can be defined, namely, For(p) as the first intersection point with ∂W of the ray from p − through p, and Back(p) as the first intersection point with ∂W of the ray from p + through p; consult Figure 1.
According to the aforementioned relation between walks and triangulations, we are only interested in discrete and straight walks.That is, the guards when moving on ∂W directly 'jump' from a vertex to the respective neighboring vertex (only one guard is allowed to move at a time), and they never backtrack.A walk in W is now defined as a diagonal (l, r) of W , l < r, such that the first guard can move CW from s to l, and the second guard can move CCW from s to r, while staying visible to each other at each step.An obvious condition for W to be walkable till (l, r) is that the two boundary chains from s to l and to r, respectively (call them L and R), are co-visible in W .That is, each vertex on L is visible from some vertex on R, and each vertex on R is visible from some vertex on L.
To characterize walkability, we will need a few more concepts, first introduced in [6].We say that W forms a forward deadlock at a pair (p, q) of its reflex vertices if we have Back(q) < p < q < For(p).
Finally, W forms a CW wedge at (p, q), if p < q and there exists no vertex x of W with q < For(q) < x < Back(p).
(A CCW wedge is defined in a symmetric way.)See Figure 1 where these geometric concepts are illustrated.
It is not hard to see that the two guards cannot pass beyond deadlocks and wedges without losing visibility.This will be made specific in Section 4.Moreover, in the work [6] it has been shown that these obstacles to walkability are indeed the only ones.By adapting their result to our setting we get: Theorem 1.Let (l, r), l < r, be a diagonal of W , and denote with Q the polygon bounded by (l, r) and the two chains L and R defined above.Then (l, r) is a walk in W iff the following three conditions are satisfied: (1) L and R are co-visible in Q, (2) Q neither forms a forward deadlock nor a backward deadlock (p, q) with p ∈ L and q ∈ R, unless p or q is in {l, r}, (3) Q forms no CW wedge on L, and no CCW wedge on R. Back(q) For(p) Back(p) For(q) For(q) Back(p) q s The line segment lr enables a CW wedge (p, q) in the shaded polygon Q.

Extremal walks and obstacles
Given a polygon W , our intention is to explore how far W is walkable from the source vertex s.That is, we want to find extremal positions for a diagonal (l, r) in W such that (l, r) is still a valid walk.A necessary (but not sufficient) condition is that (l, r) cannot be extended by a single guard move.More adequately, a walk (l, r) in W is termed maximal if there is no other walk (l , r ) in W such that l ≥ l and r ≤ r.For finding maximal walks, we will apply Theorem 1, but we have to do so with care since conditions (1) to (3) refer to a (yet unknown) polygon Q, rather than to the input polygon W as in [6].
To this end, for (1) we observe that the chains L and R are co-visible in Q iff they are co-visible in W : The line segment lr lies entirely within W , so the part of ∂W different from ∂Q does not obstruct the view within Q.
Concerning (2), we notice that forward deadlocks formed by Q do not depend on the shape of ∂W \ ∂Q, and thus trivially are also forward deadlocks formed by W .By contrast, for a backward deadlock (p, q) formed by Q, the points For(q) and Back(p) in Q may not be the same as in W . (Namely, if at least one of them lies on lr).But since these points are larger than p and smaller than q, (p, q) is also a backward deadlock in W .
No such property holds for the wedges in (3), however.A wedge (p, q) formed by Q is not necessarily also formed by W : The segment lr can obstruct the view to vertices x on ∂W \ ∂Q that prevent (p, q) from being a wedge in W . Figure 2 illustrates this situation.
Fortunately though, such 'induced' wedges cannot occur as long as the co-visibility condition is satisfied: Proof.Without loss of generality, let the induced wedge, (p, q), be a CW wedge; see Figure 2 again.Then for the reflex vertex p we have p < Back(p), and because (p, q) is induced by lr we also have r > Back(p).But this implies that the vertex p + (which belongs to the chain L) is not visible from any point on the CCW chain from p to r.In particular, p + is not visible from any vertex on the chain R, which ranges from s to r.
In summary, we can conclude that it suffices to consider the obstacles formed by the input polygon W , rather than the obstacles formed by Q.
For maximal walks, obstacles with extremal positions are relevant (in case of the presence of obstacles at all, which we will assume in the sequel).A minimal CW wedge on the chain L is a wedge (p, q) on L where the vertex q is smallest possible.For a minimal CCW wedge (p, q) on R, in turn, the vertex p has to be largest possible.Such extremal wedges need not be unique.A representative can be found in O(n log n) time, by a simple adaption of an algorithm given in [7], which finds all non-redundant wedges of a polygon.(We therefore do not elaborate on the details here.) A deadlock (p, q) (either forward or backward) is called minimal if there is no other such deadlock (p , q ) with p ≤ p and q ≥ q.The minimal backward deadlock is unique, by the following property: Observation 3. If (p, q) and (p , q ) are two backward deadlocks with p < p and q < q , then (p, q ) is a backward deadlock as well.
To find this minimal deadlock, we simply let p and q run through the reflex vertices of W , starting from s in CW and CCW direction, respectively, until the deadlock inequalities for p as well as for q are fulfilled at the same time.This can be done in O(n) time, if W has been preprocessed accordingly in O(n log n) time using ray shooting; see Chazelle et al. [4].
Minimal forward deadlocks, on the other hand, are not unique in general.This is one of the reasons why maximal walks need not be unique.In fact, W can contain Θ(n) minimal forward deadlocks (p i , q i ); see the figure below for i = 1, 2, 3.The following algorithm reports all of them.The points on ∂W relevant for this task are the reflex vertices p of W plus their ray shooting points For(p).We assume their availability in cyclic order around W .

Algorithm MFD for all relevant points x in CCW order from s do if x = For(p) and p < x then
Insert p into a CW sorted list F else if x is a reflex vertex q then Search F for the smallest p with Back(q) < p if p exists and is unmarked then Mark p Report the forward deadlock (p, q) end if end if x = next relevant point Delete from F all vertices p with p ≥ x In a nutshell, the algorithm scans the boundary of W in counterclockwise direction, maintaining reflex vertices with forward rayshots on the scanned part of the boundary in a CW sorted list.When a reflex vertex is encountered, this list is used to search for forward deadlocks formed by the current vertex and vertices in the list.Lemma 4. Algorithm MFD reports all minimal forward deadlocks (p, q) in W , and no other pair.
Proof.Let (p, q) be a minimal forward deadlock.Then q is reflex and q < For(p) holds.So the list F contains p when q is processed, by the CCW order of processing.Moreover, because (p, q) is minimal, p is the smallest vertex in F with Back(q) < q, and p is unmarked.Therefore, the algorithm will report (p, q).Conversely, assume that (p, q) gets reported.Then we know Back(q) < p, and because p is in F we know q < For(p).Also, p < q holds by the deletion criterion in the last line.Therefore (p, q) is a forward deadlock.Concerning minimality, observe first that there cannot be a forward deadlock (p , q ) with p < p and q ≥ q.Otherwise, F contains p when (p, q) is reported, because we have q ≤ q < For(q ).Because of p < p, the algorithm would have reported (p , q) rather than (p, q), or nothing at all if p is marked.There also is no forward deadlock (p , q ) with p = p and q > q.Otherwise, because of q > q, (p , q ) has been reported already.So p = p is marked, and (p, q) does not get reported.
The algorithm can be implemented to run in O(n log n) time.It scans O(n) relevant points, each being processed in constant time apart from the actions on F , which take O(n log n) time in total when a balanced search tree for F is used.

Constraints from obstacles
Minimal wedges and deadlocks, and also the required co-visibility, give rise to constraints on the vertices l and r for a maximal walk (l, r) in the polygon W .We will discuss the constraints on l in some detail.The situation for r is symmetric.
We have to distinguish between absolute and conditional constraints.Among the former is the list below.The first two constraints stem from the co-visibility of L and R, and have been taken from [6].For the last two constraints, compare Figure 1.
(1) For each reflex vertex p with p > For(p): l ≤ p.
(3) For the minimal CW wedge (p, q) on L: l ≤ q. (4) For the minimal backward deadlock (p, q): l ≤ p.The conditional constraints read as follows: For convenience, we subsume the absolute constraints ( 1) -( 4) into a single one, l ≤ x (where x is the smallest right-hand side value), and turn it into a conditional constraint: Finally, the minimal forward deadlocks lead to absolute constraints which deserve special attention.Whereas in the case of a backward deadlock (p, q), neither guard can walk beyond these vertices, we have the following observation for the avoidance of a forward deadlock: Observation 5. To avoid the forward deadlock (p, q), only one of the bounds l ≤ p and r ≥ q needs to hold.Assume now that k minimal forward deadlocks (p 1 , q 1 ), . . ., (p k , q k ) exist, and let the vertices p i be sorted in CW order.Lemma 6.Each of the following k + 1 pairs of bounds for (l, r) avoids all minimal forward deadlocks: (p 1 , s), (p 2 , q 1 ), . . ., (p k , q k−1 ), (s − , q k ).
Proof.By minimality of the considered deadlocks, we know that the vertices q i will be sorted in CW order as well.So, for each index i ≥ 2, Observation 5 tells us that the constraint l ≤ p i avoids the deadlocks (p i , q i ), . . ., (p k , q k ), and the constraint r ≥ q i−1 avoids the remaining deadlocks (p 1 , q 1 ), . . ., (p i−1 , q i−1 ).Moreover, the constraint l ≤ p 1 suffices to avoid all k deadlocks, and r ≥ s is trivially fulfilled.The same is true for r ≥ q k and l ≤ s − , respectively.
In summary, there are O(n) constraints in total, which can be identified in O(n log n) time by the results in Section 3.

Computing all maximal walks
Section 4 tells us that the goal is to fulfill the constraints in (I) -(IV) simultaneously, though for each of the bounding pairs in Lemma 6 separately.This gives all possible maximal walks -granted the visibility of the reported vertex pairs.But let us come back to the issue of visibility later in this section.For a fixed bounding pair (a, b), the constraint satisfaction problem can be transformed into the following standard form: For two variables l and r, with absolute bounds a and b, respectively, we have two sets of conditional constraints: Namely, a set C L containing constraints for l, of the form r ≥ y i =⇒ l ≤ x i and a set C R containing constraints for r, of the form l ≤ x j =⇒ r ≥ y j .
We may assume that all x-values and y-values are in {0, 1, . . ., n}.That is, the vertices w 0 , w 1 , . . ., w n of W , w 0 = w n = s, are identified with their indices.This is no loss of generality, because only their relative positions (rather than the geometric positions) on ∂W matter.We want to compute the (unique) maximal pair (l, r) such that l ≤ a, r ≥ b, and all constraints c ∈ C L ∪ C R are fulfilled.
We say that a constraint c i ∈ C L is active at a value r if r ≥ y i holds.Similarly, a constraint c j ∈ C R is active at l if we have l ≤ x j .The constraint fulfilling algorithm, CFF, now simply alternates in scanning through the sorted sets C L and C R (in ascending order of y i -values, and in descending order of x j -values, respectively), and adjusts the values of l and r according to the constraints that become active.In the figure below, active/inactive constraints are indicated with full/dashed arrows.

60:9
polygon is the vertex v, which can be 'approached' by the (mutually visible) guards in two different ways.
In Section 3 we have seen that minimum forward deadlocks can lead to Ω(n) different maximal walks.On the other hand, the number of maximal walks trivially cannot exceed n, because no two of them can have the same l-vertex, or the same r-vertex, by maximality.
Algorithm MAXWALKS provides each maximal walk in the form of a target pair (l, r), but the algorithm does not specify the way the two guards actually move on ∂W .Such a movement can be computed in O(n) additional time: Since we know that the subpolygon Q of W defined by s and (l, r) is entirely walkable, we can simply apply the algorithm in [6] to the polygon Q (which has already been preprocessed with W ).
Notice, however, that a fixed target pair (l, r) may still leave the guards different ways to perform the walk.Different ways to triangulate W from s to (l, r) then result.For example, in the polygon example in Algorithm MAXWALKS, it would be possible to include one more diagonal with endpoint r into the solid-line trianguation, namely, the diagonal rx.The dual of any such triangulation has to be a path, though, as the triangulation is constructed by repeatedly cutting off adjacent ear triangles, one triangle per guard step.

2 .
Assume that the diagonal lr of W induces a wedge in the polygon Q bounded by lr and the chains L and R. Then L and R are not co-visible.