Visibility Simple Polygon 1987
Visibility Simple Polygon 1987
11
tant? The answer is that the set of all shortest paths has Because there is only one shortest path from s to any ver-
more structure than the set of single-edge paths. Once we tex, this set of paths does indeed form a tree. The edges
have found the set of all shortest paths from one vertex, of the shortest path tree partition the interior of P into
we can exploit the structure to find similar sets for the regions we call funnels.
other vertices efficiently.
In outline, our algorithm is the following: We begin
by representing all shortest paths from some arbitrary ver-
tex vr in a structure called the shortest path map. From
this structure we can find the vertices visible from vr in
constant time apiece. Let vr be the vertex of P counter-
clockwise of vl. The shortest path map for us is similar to
that for vr, and we can build one from the other in time
S
proportional to the number of differences between them.
We proceed around the boundary of P, constructing the Figure 1. The shortest path tree is the union of
shortest path map of each vertex from that belonging to the shortest paths from a source vertex s to all
its clockwise neighbor. At each step we obtain all visibility other vertices.
edges from the current vertex.
We build the first shortest path map by triangulat- Each polygon edge m has an associated funnel. The
ing P, then running the linear algorithm of Guibas et shortest path from s top, A(s,P), shares edges with A(S, q)
al. [GHLST]. The triangulation algorithm of Tarjan and for part of its length; at some vertex a (called the apex
Van Wyk takes O(n log log n) time [TV], which dominates of the funnel) the two paths part and proceed separately
the initialization cost. to their destinations. The two paths cannot rejoin, once
separated, since shortest paths inside P are unique. The
After the initial shortest path map has been built,
funnel is bounded by the edge m (called the base of the
the rest of the algorithm runs in O(m) time. Each trans-
funnel) and the two funnel paths a(a, p) and ?r(a, q). Be-
formation of one shortest path map into another takes
cause P is simple, each of the funnel paths is inward con-
time proportional to the number of differences between
vex: it bulges in toward the funnel region. See Figure 2
them, and, as Section 4 shows, the total number of dif-
for an example of a funnel. Note that the apex of the
ferences between adjacent shortest path maps is O(m).
funnel may be s, and that the funnel can degenerate into
Altogether, our algorithm takes time O(m + n log logn).
a single segment: if a = p, then n(a,q) = W.
This is slightly suboptimal when m = o(n log log n), but
it is still a significant improvement over earlier methods.
12
and Stolfi (GS]. The algorithms of Section 3 must be able
to find the base of a region in constant time, so we aug-
ment each region in the subdivision with a pointer to its
base. The data structure lets us find the neighbors of s in
SPM(s) in time proportional to their number. Therefore,
once we have SPM(s), we can find the visibility edges that
have s as an endpoint in constant time per edge.
s
3. Constructing shortest path maps
Figure 3. Each funnel is broken into triangular
regions by extending the edges on the sides of We use the shortest path maps described in the preceding
the funnel. section to find the visibility graph of P. To find the poly-
gon vertices visible from a particular vertex v, we con-
Although the shortest path map partions the inte- struct SPM(u). All the vertices visible from v are con-
rior of P into triangles, it is generally not a triangulation. nected to v by edges of SPM(v). The n polygon vertices
Polygon vertices may lie on edges of the triangular re- give n shortest path maps; taken together, these give us
gions. Furthermore, although the apex of each triangular the visibility graph.
region is a vertex of P, the other two vertices of the tri-
If we constructed each shortest path map individu-
angle need not be polygon vertices. They may instead be
ally, we would spend G(n) time on each one, and it would
intersections of the funnel base with extended edges from
take e(n2) time to find the visibility graph. However, we
the funnel sides.
can save time by building the shortest path map for an ar-
If the shortest path map were larger than O(n), build- bitrarily selected vertex ~1, then transforming it to get all
ing it would be a bottleneck for our algorithm. This po- the other shortest path maps. Once we have SPM(vl), we
tential problem does not arise: both the shortest path modify it to produce SPM(u2), where up is the counter-
tree and the shortest path map have a linear number of clockwise neighbor of ur along the polygon boundary. We
edges. Each node of the shortest path tree is a vertex of repeat this operation for all the vertices, working counter-
P; because P has n vertices, the shortest path tree has clockwise around the polygon.
n - 1 edges. Every edge of the shortest path map is either
We construct SPM(q) using the algorithm of Guibas
an edge of the shortest path tree or an extension of such
et al. [GHLST]. Their method first triangulates the poly-
an edge. Each edge of the shortest path tree has at most
gon, then builds SPM(v1) in additional linear time. (Sec-
one extension; an extension splits one base edge in two.
tion 3.2 describes the algorithm in more detail.) The
Including the (possibly split) edges of P, a linear number
triangulation step dominates the running time, since it
of edges bound the regions of the shortest path map.t
takes O(nloglogn) time using the algorithm of Tarjan
In our visibility graph algorithm, we use n different and Van Wyk [TV].
shortest path maps, each with a different source vertex.
We now turn to the general step of the algorithm, the
To distinguish between different shortest path maps, we
construction of one shortest path map from that of an ad-
use the notation SPM(s) to refer to the shortest path map
jacent vertex. We show in this section that the construc-
with s as its source vertex.
tion takes time proportional to the number of differences
In SPM(s), the regions with s as their apex include between the two shortest path maps. The next section
all the points inside P that are visible from s. The polygon shows that the number of differences, summed over all
vertices connected to s by edges of SPM(s) include all neighbor pairs, is proportional to the size of the visibility
the vertices visible from s. (Two of the neighbors of e in graph.
SPM(s) are not visible from s: edges of SPM(s) connect
Let s and t be adjacent polygon vertices, e clockwise
.9to its neighbors on the boundary of P, but our definition
of t. Given SPiU(s), we produce SPM(t) by adding and
of visibility does not count these as visible points.)
deleting edges. The following lemma characterizes the
We represent SPM(s) using a standard subdivision part of the subdivision that we change.
representation, such as the winged-edge data structure of
Baumgart [B] or the quad-edge data structure of Guibas Lemma 1. Let s and t be adjacent vertices of P, and let
e be an edge of SPM(s) that does not belong to SPM(t).
t By an argument that relates the number of single Then there is a point v in the interior of e such that any
edge funnels in the shortest path tree to the number of neighborhood of v includes points that are visible from
vertices on the sides of funnels, we can show that the the interior of 3.
shortest path map has at most 3n - 6 edges. Thii bound
Pro& The edge e separates two regions of
is tight.
SPM(s), and hence [(~,a) # [(s,b) for a and b
on opposite sides of e. Because e does not belong
to SPM(t), we can pick a point u in the interior
of e that is not part of an edge of SPM(t). Then
for o and b on opposite sides of e and sufficiently
close to u, we have I(t,a) = I(t, b). By possi-
bly interchanging a and b, we can insure that
+, a) # +, a).
Now consider the shortest path tree of a.
Since f(t,a) # r(s,a), a is the apex of the fun-
nel associated with segment 3. The funnel is
evidence that some part of the interior of 2 is
visible from a. Any ray with source a and di- Figure 4. Because vt is visible from 3 and v is
rection strictly in the angle formed by I(s, a), a, not, I(s,v) # I(s,u’). This implies that 3 is an
and I(t,a) must hit the interior of 3 before it edge of &f(s).
hits any other part of P. 1
If a is counterclockwise of b, then the inte-
The part of P visible from at least one point in the rior of P(Z) lies to the right of &. An argument
interior of z is a connected subpolygon, which we denote similar to the preceding one shows that & is an
by P(z). The preceding lemma shows that SPM(s) and edge of SPM(t). 1
SPM(t) differ only inside P(iZ) and on its boundary. The
following lemma characterizes the boundary of P(i?). We want to transform SPM(s) into SPM(t) in time
proportional to the number of edges that must be changed
Lemma 2. The boundary of P(q is made up of edges of to get from one to the other. Lemma 1 shows that no edges
SPM(s) and SPM(t). Any edge a that is on the bound- need to be changed outside P(3). The following subsec-
ary of P(Z) but not on the boundary of P has one end- tions present two dissimilar algorithms for performing the
point, say a, that lies on the paths to b from s and t: transformation.
it is both l(8,b) and l(t,b). If 4 is clockwise of b on the
boundary of P, then 3 belongs to SPM(s); otherwise, it 3.1. A sweeping-path algorithm
belongs to SPM(t).
The first transformation algorithm might be called
Proof: The edges of P belong to both SPM(s) a “sweeping-path” algorithm. It moves a point p from
and SPM(t); thus the polygon edges on the f to s along the boundary of the subpolygon P(q, the
boundary of P(Z) belong to both shortest path region in which’one shortest path map must be replaced
maps. We therefore consider only boundary by another. We think of the point as being connected
edges of P(Z) in the interior of P. to s and t by two rubber bands inside P, the shortest
A point u in the interior of such an edge is paths r(s,p) and r(t,p). As the point moves, it drags
not visible from 2, since it is not in the interior the two paths along with it, and the paths sweep over the
of P(q. As noted in the proof of Lemma 1, we subdivision inside P(Z). The algorithm uses the sweeping
must have I(s,u) = I(t,u). Let us define a to be paths to change SPM(s) into SPM(t). The algorithm
I(s,u). The point a is an endpoint of the edge maintains the following invariant: on and to the right of
that contains v; let b be the other endpoint. The r(t,p), the subdivision represents SPM(t); to the left of
shortest paths from b to s and t must go through a(s,p), the subdivision represents SPM(s); between the
u, and so a is both l(s,b) and I(t,b). two paths, there are no edges.
Suppose that a is clockwise of b. This means The algorithm updates the subdivision when p visits
that the interior of P(q lies to the left of z. vertices of sPkf(8) or SPM(t). ,Ifu is a vertex of sPhf(s),
Let u’ be a point just to the left of v, inside all the edges,of ~(8, v) are edges of SPM(s). When p visits
P(i$. (See Figure 4.) Because u’ is visible from u, the algorithm deletes the last edge of the path ~(8, u),
3, the two shortest paths ~(6, u’) and a(& u’) unless it is also an edge of SPM(t). (An edge may belong
intersect only at v’. Vertex a is on or to the to both shortest path maps only if it is a boundary edge of
right of m(t, v’), so l(s, v’) # a. This holds for vt P(g.) Similarly, when p visits a vertex v of SPM(t), the
distinct from v but arbitrarily close to it. Since algorithm adds the last edge of ~r(t,v) to the subdivision,
I(s, v) = a, the segment a is an edge of SPM(s); unless it is already an edge of SPM(s). This procedure
it separates two regions of SPM(s). considers just once each edge that must be changed.
14
When the algorithm adds or dcletcs an +,cr, it may The movement of p fits in with the edge addition and
have to make other changes to the subdivision. Suppose deletion scheme outlined above. Whenever p moves along
that the algorithm deletes an edge of SPM (s) when p vis- an extension edge of SPM(s), the edge still belongs to the
its u. If u is a vertex of SPh4(s) but not of P, then v subdivision. When p moves along an extension edge of
splits a polygon edge; the algorithm must merge the two SPM(t), the edge has just been added to the subdivision.
pieces back into one. Similarly, when the algorithm adds
an edge of SPM(t) to the subdivision, it may have to split
a polygon edge: if p is not at a polygon vertex, the nlgo-
rithm splits the polygon edge on which p lies. Adding and
deleting edges changes regions in the crtrrcnt subdivision;
we must update the base pointer in each clrangcd rrgion.
This is not hard: whenever a pointer ncctls Lo be changed,
the new base is incident to p.
How do we represent p and the two paths in a discrete
algorithm? The point p does not move continuously along
s t
the boundary of P(Z), but in discrete jumps from one
vertex of SPM(s) or SPM(t) to the next such vertex. Ue- Figure 5. P(Z) is bounded by polygon edges
cause the shortest paths to intermediate vertices on z(s,p) and by extension edges. The left extension edge
and r(t,p) are unique, the movement of p changes *(s,p) is an edge of SPM(t); the right edge belongs to
and r(t,p) only at the ends nearer p. Thus we can rep- SPM(s).
resent the two paths as stacks of polygon vertices. The
stacks do not include p; the top of the stack for r(s,p) is We can tell which edge p should follow when it leaves
I(s,p), and the top of the stack for r(t,p) is f(t,p). a vertex; we need to know when to stop its motion along
We have described the basic idea of the algorithm, as the edge. We break the problem into two subproblems.
well as its data structures. We now describe the actions We consider moving p along extension edges below; here
necessary to move p aloug the boundary of P(&). These we show how to move p along edges of P that are visible
can be broken down into several intcrrc!latc*tl ta.sks. The from ai. When moving along such an edge, p should stop
hardest two tasks arc deciding which cdgc 1’ :~hr~r~Itl follow at the first vertex of SPM(s) or .SPM(l) on the edge. It is
when it leaves a vrrtex and deriding whrn it. shotllti stop CILS~to dctcct vcrticcs of SYM(s): they arc vertices of the
moving along the edge. IIy referring to the two shortest subdivision left of T(S, p). Recognizing vertices of SPM(t)
paths x(s,p) and r(t,p), the algorithm can make these that are not vertices of SPM(s) is more difficult.
decisions in constant time apiece. A simpler task is that of The problem we need to solve is quite specific: given
maintaining the stacks that represent the shortest paths. a point p on the boundary of P(g such that the poly-
We show how t,o perform these tasks, taking into account gon edge counterclockwise of p is visible from 3, find the
the possibility of degeneracies in P. We then combine the first vertex of SPM(s) or SPM(t) counterclockwise of p
costs of these operations to bound the algorithm’s running along the edge. Let q be the first vertex of SPM(s) coun-
time. terclockwise of p; it is part of the subdivision. We need
The region visible from the interior of 3, P(z), is to determine whether any vertices of SPM(t) lie in the
bounded by polygon edges and by extension edges of the interior of edge W.
types shown in Figure 5. The algorithm for following its We begin by characterizing vertices of S&X(t) that
boundary is simple: p moves counterclockwise along the lie between p and q, assuming that at least one exists. Let
polygon boundary whenever doing so leaves both shortest u be such a vertex, chosen closest to p if there are several
paths ~(s,p) and x(t,p) inward convex. When moving such vertices. Vertex w is an endpoint of an extension edge
along the polygon boundary would cause one of these two e. The edge separates two regions of SPM(t); v lies on the
paths to violate inward convexity, as at vcrtires u and tu in base of both. The apexes of the two regions lie on the line
Figure 5, p moves along an extension edge. It moves along containing e. Because u is not a polygon vertex, the two
edges of SPM(s) when moving away from it and along apexes cannot be coincident.
edges of SPM(t) when moving toward st, as specified by First consider the case in which the apex to the right
Lemma 2. In Figure 5, when p advances from vu,it moves of e is closer to u than the apex to the left, as in Fig-
along the extension of the edge from l(s,v) through u. ure 6(a). (W e d efi ne right and left by assuming that e is
When p advances from w, it moves along the extension directed away from t.) Because p lies on the boundary of
edge between w and I(t,w). the region on the right, the last two vertices of r(t,p) lie
15
on the segment z of Figure 6(a). (In degenerate cases
several polygon vertices may lie on a.) Hence II can be
determined as the intersection of the ray through the last
two vertices on r(t,p) with the edge W.
V V
e e (4 (b)
h b Figure 7. The circled points are vertices of
SPM(t) that do not appear in the subdivision
left of ~(8, p). They are detected when the algc+
a a rithm tries to move p along the polygon bound-
T -7 ary to q. (Vertices I and r are the last polygon
vertices on r(s,p) and x(&p), respectively. Ver-
(a> (b) tex u is the predecessor of r on n(t,p).) In (a),
the circled vertex is the intersection of W with
Figure 6. The point v is a vertex of SPM(t) that
the extension of d. Vertex r is removed from
lies between p and q, the vertex of SPM(s) that
dt,d-~n 04, P cannot move past the intersec-
follows p on the boundary of P. Figures (a) and
tion of rl with w (circled) without violating the
(b) show the two configurations of SPM(t) that
inward convexity of a(t,p).
give rise to such a vertex.
shortest path map edges. It stores with every shortest
Now consider the case in which the apex to the left of path map region a pointer to the base edge of the region.
e is closer to v than the apex to the right, as in Figure 6(b). Then when it needs to move along an extension edge, it
Because ~(5, v) cannot lie to the left of the polygon vertex skips from the first vertex to the base, or vice versa. In
b or to the right of r(t,v), it must go through b. Thus b Figure 8, p moves directly from v to u and from w to z.
is I(s,v). The region of SPM(t) to the right of e has a as If there are intermediate vertices on the extension edge
its apex; that is, I(t,p) = a. Because there are no vertices (which can be checked in constant time), the edges along
of SPM(s) between p and q, the last vertex on ~(.s,p), the extension are the same in both SPM(s) and SPM(t).
I(s,p), is either equal to b or to a polygon vertex in the If there are no intermediate vertices, the edge is added or
interior of ;;i;. (Because H is visible from 3, I(s,p) cannot deleted in constant time.
be a. It is not equal to b only in the case of degeneracies.)
11
Bence v can be determined as the intersection of the ray
through f(t,p) and I(s,p) with the edge W.
To detect vertices of SPA-f(t) on the edge R, we only
need to compute two intersections. If the ray through the
last two vertices on x(t, p) intersects m, or the ray through
l(t,p) and I(s,p) intersects j%j, then we move p to the
intersection farthest clockwise; it is a vertex of SPM(t).
Otherwise we move p to q. (If l(t,p) = t, the first ray is
undefined and its intersection does not exist. If either ray
hits W, the ray farther clockwise hits W without hitting
s t
any other part of P first; this is because the quadrilateral
determined by p, q, l(s,p), and l(t,p) is free of polygon Figure 8. In degenerate cases, multiple polygon
points.) See Figure 7 for an example of these intersections. vertices may lie on one extension edge on the
We have described how the algorithm moves p along boundary of P(q. None of the shortest path
an edge visible from 3; we now describe how it moves map edges along this edge needs to be changed,
p along an extension edge. Extension edges require care so the algorithm skips over them.
because they may have multiple polygon vertices along
them, even though no shortest path map edges need to The shortest paths ?r(s,p) and r(t,p) are not hard
be changed. This degenerate case is depicted in Figure 8. to maintain. They change only when p passes through a
The algorithm handles extension edges specially to avoid vertex of SPM(s) or SPM(t). When p reaches a vertex of
having to visit many vertices when changing only a few SPM(t) of the type shown in Figure 7(a), then r, the last
16
vertex of ~(t,p), is popped off the top of its stack. When
p advances from u along edge Zij and q is to the right of
$, then II is pushed onto the stack for z(t,p). Change :
to the stack for r(s,p) are made analogously. The t 3
shortest paths change only in these four situations.
The algorithm runs in time proportional to the num-
ber of vcrticcs p visits. The ouly vcrticcs p visits where
the algorithm does not modify the current subdivision
are base endpoints of extension edges on the boundary Figure 9. The funnel belonging to diagonal jpj is
of P(q. Each vertex where the algorithm does change split in two to get the funnels for p and w.
the subdivision is incident to at most one such extension
edge. Thus we have the following theorem. Because the polygon is subdivided into triangles, the
Theorem 1. The sweeping-path algorithm computes algorithm splits a funnel in two when it enters a region.
SPM(t) from SPM(s) in time proportional to the number However, funnel-splitting works equally well if the polygon
of differences between the two shortest path maps. is subdivided into convex polygons with more than three
sides. When the algorithm crosses a diagonal to enter a
convex subpolygon with k sides, it splits the diagonal’s
3.2. A depth-first search algorithm funnel into k - 1 subfunnels.
Our second transformation algorithm is a depth-first Each region of a shortest path map is convex, so we
search algorithm; it is based on the shortest path map can run the algorithm of Guibas et al. in SPM(s) in-
construction of Guibas et al. [GHLST]. Because it uses stead of in a triangulation. Because SPM(s) has vertices
finger search trees [GMPR](HuM], it may be harder to {*hat do not belong to P, this construction produces ex-
implement than the sweeping-path algorithm. The idea ?ra edges that we then have to delete. A second potential
of the depth-first search algorithm is not difficult: the oroblem arises because shortest path map regions may be
algorithm of Guibas et al., which runs in a triangulated degenerate. A region may have arbitrarily many edges
simple polygon, can be modified to run using a shortest on its boundary, even though the edges lie on only three
path map in place of the triangulation. We build SPM(t) lines. Bowever, the exploration strategy outlined below
by running the modified algorithm in SPM(s). The algo- ensures that degeneracies do not hurt the algorithm’s per-
rithm changes only the regions overlapping P(qi); it runs formance.
in time proportional to the number of differences between
Our algorithm runs in time proportional to the num-
SPM(s) and SPM(t).
ber of differences between SPM(s) and SPM(t). To do
We begin by describing the shortest path map con- this, it explores only the regions of SPM(s) that overlap
struction of Guibas et al. In essence, the construction is P(q. It determines which regions to explore at run time.
a depth-first exploration of a triangulation, starting with This is feasible because the algorithm of Guibas et al. is
a triangle incident to the source. Each step processes an incremental: at each step the data structures contain the
unexplored triangle that shares a diagonal with one al- correct shortest path tree for the subpolygon explored so
ready explored. The algorithm maintains a shortest path far.
tree in the subpolygon explored so far. (It maintains a
The algorithm begins by exploring the region incident
funnel for each diagonal at the boundary of the explored
to 3. In the rest of the polygon, it crosses only diagonals
region.) When the algorithm crosses into a new triangle,
that lie inside P(a. Let ;;i; be a diagonal of SPM(s), and
it splits the funnel belonging to the crossed diagonal into
two funnels, one for each of the triangle’s other two sides. without loss of generality assume that l(s,b) = a. Then
The splitting edge is the tangent from the triangle’s third & lies inside P(q if and only if I(t, b) # a, that is, the
vertex to the interior of the funnel. See Figure 9 for an funnel associated with a in SPM(t) does not have a as its
example of funnel-splitting. When one of the new sides apex. Because b is the funnel apex only for 3 = 3, the
is a polygon edge rather than a diagonal, the algorithm algorithm crosses exactly those diagonals with nontrivial
has found a funnel of the shortest path tree. Extending funnels.
the edges on the funnel sides gives the shortest path map When the algorithm enters a region by crossing an
decomposition of the funnel. All the operations of the edge e, it can determine in constant time whether any
algorithm except funnel-splitting can easily be shown to particular edge of the region has a trivial funnel (equal
be linear. By using finger search trees [GMPR][HuM] to to the edge itself). An edge has a trivial funnel if and
store and split funnels, Guibas et al. reduce the the overall only if the tangents from its endpoints to the interior of
cost of funnel-splitting to O(n). e’s funnel lie on the same line, In such a case the tangents
17
both pass through the same endpoint of e. adjacent triangular regions that share the same apex and
The algorithm cannot afford to look at all the diago- whose bases lie on the same polygon edge, we merge the
nals that it does not cross. Fortunately, it can recognize two regions into one, resetting the region’s base pointer.
edges with trivial funnels without looking at them indi- This cleanup operation removes all the edges that do not
vidually. The algorithm enters each region by crossing an belong to SPM(t), both inside the changed subpolygon
edge e incident to the apex of the region. (This is be- and on its boundary. It leaves unchanged those edges that
cause s and t are neighbors on P.) If there are any other belong to both SPM(s) and SPM(t). It runs in time pro-
edges on the side of the region that contains e, their asso- portional to the number of regions of SPM(s) explored,
ciated funnels must be trivial. (See Figure 10.) As in the since it looks at at most two edges in each such region.
sweeping-path algorithm, we augment the subdivision so After the cleanup operation, the subpolygon that has
that each region has a pointer to its base. We can check been changed contains SPM(t); the unchanged part of the
in constant time whether the base’s funnel is trivial. If polygon contains SPM(s) (and hence SPM(t)). This con-
any edge on the side of the region opposite e has a trivial cludes the transformation. We have computed SPM(t),
funnel, all such edges do. We can classify them all at once and the new subdivision is ready to be transformed again.
by checking the edge incident to the apex of the region. Like the algorithm of Guibas et al., our algorithm
(In Figure 10, only the base has a non-trivial funnel.) runs in time proportional to the total number of funnel
edges it creates. Each funnel-splitting operation creates
one new funnel edge. The number of funnei-splittings per-
formed inside a region of SPM(s) is proportional to the
number of edges with non-trivial funnels on the boundary
of the region. Since P does not have consecutive colinear
edges, this quantity is in turn proportional to the num-
ber of regions adjacent to the current one that are ex-
plored after it. Thus the total number of funnel-splittings
is proportional to the number of regions of SPM(s) the
Figure 10. The algorithm enters the shaded re- algorithm explores.
gion by crossing edge e. The funnels on both
The depth-first exploration and the cleanup phase
sides of the shaded region are trivial.
both take time proportional to the number of regions of
SPM(s) the algorithm explores. Each region except the
The algorithm constructs ‘SPM(t) inside the region first is reached by deleting an edge of SPAI( Since the
without looking at the edges with trivial funnels. It splits number of edges deleted is just part of the total number
up the funnel that belongs to e among the other edges. of edges changed, we have the following theorem.
(This splitting is no more difficult if several of the edges
with non-trivial funnels lie on a single side of the region,) Theorem 2. The depth-first search algorithm computes
If any of the edges with non-trivial funnels lies on the SPM(t) from SPM(s) in time proportional to the number
boundary of P, the algorithm divides its funnel up into of differences between them.
regions of SPM(t) and sets the base pointers in each re-
gion. If multiple edges with trivial funnels lit on a single
4. Complexity bounds
side of a region of SI’M(s), then those edges also belong
to SPM(t). If only one such edge lies on a single side, it This section shows that each of the algorithms of the pre-
may not belong to SPM(t). The cleanup phase described ceding section takes 0(m) time overall. The proof asso-
below deletes it if necessary. ciates a constant number of shortest path map edges with
When the algorithm finishes its exploration, it has each visibility edge or polygon edge; every edge that ap-
constructed a refinement of SPM(t) in a subpolygon of pears in a shortest path map has an associated visibility
SPM(s). The subpolygon may have some vertices that edge or polygon edge. As the source of the shortest path
do not belong to P, and hence the new shortest path map map moves around the boundary of P, edges are added to
has some vertices and edges that do not belong to SPM(t). and deleted from the current shortest path map. We show
The additional vertices are vertices of SPM(s) that split that each edge is added and deleted a constant number of
polygon edges; they lie on the bases of regions of SPM(s). times, which gives the desired bound on the runuing time.
The additional edges are incident to the extraneous ver- It is helpful to think of shortest path edges as being
tices. We clean up the shortest path map by visiting both directed. The edge W has two versions, rq and @. When
endpoints of the base in each explored region of SPM[s). w appears in shortest path map SPM(u), we write it as
If the diagonal edge incident to such a vertex separates two p> if p lies on the path from v to p and @ otherwise.
18
We associate every edge that appears in a shortest 5. Conclusion and open problems
path map with a directed polygon edge or visibility edge.
This paper has presented an algorithm to find the visihil-
Shortest paths follow visibility cclgrs and polygon edges,
ity graph of a simple polygon irl time O(fn + n log log R),
so WC only need to account for the edges of the shortest
where m is the number of edges in the graph. The al-
path map that are not in the shortest path tree. These
gorithm works by computing the shortest path map from
edges are extensions of funnel edges. Each funnel edge
each vertex of the polygon, then reading off the visibility
is a polygon edge or a visibility edge; we associate each
edges from the source of the shortest path map. Rather
extension edge with the version of its funnel edge that is
than compute each shortest path map separately, the algo-
directed toward it. Each directed edge has at most one
rithm finds one shortest path map in O(nlog logn) time,
extension.
then builds the others as modifications of the first one. In
The following lemma characterizes the shortest path particular, the shortest path map with source t is built by
maps in which each directed edge appears. modifying the one whose source is the clockwise neighbor
Lemma 3. Let w be a polygon edge or a visibility edge. of t along the polygon boundary. This procedure is fast
The shortest path maps in which the directed edge j!ij because of the similarity between two shortest path maps
appears have sources that form a contiguous subsequence whose sourcea are neighbors on the polygon.
of the polygon vertices. Because it uses finger search trees to find the ini-
tial shortest path map, our algorithm may be difficult
Proof: We exhibit polygon vertices 1 and r
to implement. We can avoid the use of finger search
such that cq appears in SPM(u) for all u strictly
trees (at the cost of slightly increased asymptotic com-
counterclockwise of 1 and clockwise of 7 in the se-
plexity) by finding the initial shortest path map Sf’M(v,)
quence of polygon vertices, and Fq appears in no
in O(nlogn) time. We triangulate P with the algorithm
other shortest path maps. We first note that pq
of Garey et al. (GJPT]. By replacing the finger search
must appear in SPM(p). Let I be the first ver-
trees in the algorithm of Guibas et al. [GHLST] with
tex clockwise of p for which G is not in SPM(I).
linked lists, we find the shortest path map in O(nlogn)
Because shortest paths do not cross, fi cannot
additional time. We use the sweeping-path algorithm to
appear in any shortest path map whose source is
transform shortest path maps into each other. This yields
between 1 and q, inclusive. A similar argument
an O(m + n log n) algorithm that uses only simple data
shows the existence of r and proves the lemma.
structures.
I
Alternate definitions of visibility can simplify our al-
Now consider the shortest path map transformations gorithms. If we define two points to be mutually visible
of the previous section. If 3 is an edge of P, the short- when the segment connecting them does not intersect the
est path map SPM(t) can be constructed from SPM(s) exterior of P, the size of the visibility graph may increase.
in time proportional to the number of edges that must In a polygon with many colinear points, we may have
be changed to get from one to the other. The preceding m = fl(n”) under this definition and m = O(n) under
lemma lets us bound the time needed to produce shortest the standard definition. Under the broader definition of
path maps for all the polygon vertices. visibility, the sweeping-path algorithm will run in O(m)
time without using special cases to move p along extension
Theorem 3. Given SPM(u,) for any polygon vertex ~1,
repeated application of either of the algorithms of Section edges.
3 produces a shortest path map for every polygon vertex The presence of the O(n log log n) term in our algo-
in O(m) total time. rithm’s running time suggests an open question: Is it pos-
sible to triangulate a simple polygon in O(m) time? If
Proof: As the source of the shortest path map we could do so, we would have an optimal visibility graph
moves around the perimeter of the polygon, each algorithm for simple polygons. (There are polygons with
directed polygon or visibility edge is added to or m = O(n) for which the triangulation algorittm of Tar-
deleted from the current shortest path map at jan and Van Wyk takes n(n log log r~) time.) This ques-
most twice. (This follows from Lemma 3.) There tion fits into a framework of earlier work. Several authors
are 2n + 2m directed edges, and hence by either have proposed triangulation algorithms that run in time
Theorem 1 or Theorem 2 the n - 1 applications O(n log k) for some parameter k related to the complexity
of the transformation procedure take O(m) time of the polygon. For example, in the algorithm of Her-
altogether. 1 tel and Mehlhorn, k is the number of reflex angles in the
polygon (HeM]; in t.hat of Chazelle and Incerpi, k is the
“sinuosity” of the polygon ICI]. In some sense, we ask less
19
of our triangulation algorithm than previous authors. We Conference on Foundations of Computing The-
want it to run in O(m), but this can be much larger than ory, New York, Springer-Verlag, Berlin, 1983,
O(nloglogn). When m is smaller than O(rz log logn), pp. 207-218.
the polygon is narrow and few triangulations are possi-
IH4 S. Huddleston and K. Mehlhorn: “A new data
ble. This may make it easier to find one of them. structure for representing sorted lists.” Acta In-
formatica, Vol. 17 (1982), pp. 157-184.
Acknowledgements PI S. Suri: Private communication, 1986.
I would like to thank Joseph O’Rourke for mentioning this PI R. Tarjan and C. Van Wyk: “An O(n log log n)-
problem to me, Leo Guibas for several helpful discussions, time algorithm for triangulating simple poly-
and Jack Snoeyink for his careful reading of an earlier gons.” Manuscript, July 1986.
version of this paper. PI E. Welzl: ‘Constructing the visibility graph for
n line segments in O(ra2) time.” Information
Processing Letters, Vol. 20 (1985), pp. 167-171.
6. References
20