The Power of Triangulation: Applications to Problems of Visibility and Internal Distance.

It is well-known that the complexity of performing operations on a set depends heavily on the structure which we are allowed to put into its representation. For example, searching through a sequence of numbers can be performed more efficiently if the numbers appear in sorted order. In this paper, we take, as a case-study, the class of problems involving a simple N-gon P and, making the assumption that in addition to the usual description of the boundary of />, an arbitrary triangulation is also available, we investigate the computational power gained from having this additional information. Among other results, we give a very simple, optimal algorithm for computing the area visible from an arbitrary point in P. We also present several optimal algorithms for computing the internal distance between two points in P. Recall that the internal distance between A and B is defined as the length of the shortest path inside P between A and B.


Introduction
The complexity of problems that operate on fixed objects is highly dependent on the amount of preprocessing allowed in the objects* representation. As illustrated in the well known paradigm searching .vs. sorting, the mere availability of an order among keys cuts down the complexity of searching from linear to logarithmic. In numerical analysis, preconditioning a sparse matrix is standard procedure in order to facilitate the computation of its inverse. In general, the crucial issue is to balance costs and gains of preprocessing so as to optimize the overall performance. Few areas of computer science are free of this type of trade-offs and, in particular, this concern is recurrent in computational geometry, operations research, and in the study of data structures or data bases.
The first area mentioned, computational geometry, provides a good example of a structure, i.e., the Voronoi diagram, easy to construct efficiently, while one of the most powerful tools at our disposal for solving closestpoint problems [SH77]. Unrelated, .yet equally effective results have shown that convex figures lend themselves to speedier algorithms than arbitrarily-shaped objects [CH8G\CD80, DK81]. Consequently, an attractive approach to handle non-convex figures is to decompose them into their convex parts, then apply to these the efficient methods known for convex objects [CH80\FS81, GJ78,SC78,SV8G\TO80]. We pursue this endeavor in this paper, and investigate the existence of efficient algorithms for various problems, assuming that in addition to the usual boundary description of a polygon, an arbitrary triangulation is also available. It is standard to define a triangulation of a polygon as a convex decomposition which does not introduce new vertices 1 [GJ78]. For our purposes, however, we can relax this definition and allow the vertices of the triangulation to lie anywhere on the boundary of the polygon. The only provision to make is that the total number of points used in the triangulation is linear in the number of vertices of the polygon. Note that this is always true with the standard, more restrictive definition. We also observe that it is easy, given a convex decomposition of a polygon, to derive a triangulation in linear time. It is then apparent that it is only for simplicity that we choose to be supplied with a triangulation rather than a more general convex decomposition of the polygon.
With this additional information in hand, we are able to describe a very simple, yet optimal algorithm for computing the area visible from any point inside a polygon. We also present several optimal algorithms for computing the internal distance between two points inside a polygon. Recall that the internal distance is defined as the shortest distance a person might travel from one point to the other, while remaining within the boundary of the polygon.
i.e.. where ail the vertices in the decomposition arc vertices of the polygon. Next we introduce our notation, before proceeding with the description of the algorithms. Let P be a simple 1 polygon with vertices v x v N in clockwise order. We assume the existence of a triangulation Tof P t defined as a set of non-overlapping triangles whose union is exactly P, and whose summits arc taken in the set {v x v N }. The edges of the triangulation which are not edges of P are called interior edges. As mentioned above, we may choose to allow the summits to lie anywhere on the boundary of P, provided that the total number of vertices in the triangulation does not exceed the number of vertices of P, up to within a constant factor. In this case, we may, for simplicity, rename the vertices of P so that the list v x ,...,v N gives a clockwise description of all the vertices appearing on the boundary of the triangulation.
Observing that a triangulation forms the embedding of a planar graph, we choose a DC EL representation of this graph as our basic working structure [MP78]. Recall that a DCEL is simply a handy data structure, obtainable in linear time from any standard adjacency representation, which in particular, allows one to traverse the boundary of each face in clockwise order and list the faces encountered on the left-hand side during the traversal. Roughly, to each edge e of the graph is assigned a 6-field node containing the names of the two endpoints in some specified order, as well as the two adjacent faces and die names of each of the edges first encountered in traversing these faces in clockwise order, starting at the endpoints of e.
Note that several algorithms are available in the literature for computing an arbitrary triangulation of an N-gon. The best performance achieved so far is 0(Mog N) time [GJ78.CH82], but is yet unknown to be optimal or not

Visibility problems
A problem which arises frequently in graphics concerns the elimination of hidden lines from a two-or three-dimensional scene [NS79]. In two dimensions, the problem reduces to computing the sets of points that are visible from a given point inside a polygon P. Linear algorithms for this problem already exist [CH80.EA81], but they involve complicated stack manipulations which become unnecessary, once a triangulation is made available. The problem can be formulated as follows:

Given a simple polygon P and a point \t inside P, the locus of points V such that the segment MV lies entirely in P is a simple polygon V(M). Compute a clockwise description of the boundary of V(M)(M5).
We can regard the triangles of 7 as forming the nodes of a graph (7, whose edges join the pairs of triangles with a common edge (i.e., an interior edge) (fig.l). As shown in Lemma 1, the absence of interior faces ensures that the graph G is actually a tree.  Lemma 1: G is a tree.
Proof: It suffices to show that for any pair of triangles in the triangulation, there exists a unique path between / 1 and t^ in G. The triangle / x partitions P into 4 parts. One is the triangle ^ itself, the others being polygons adjacent to the edges of t l (note that some of these polygons may be reduced to a single edge). At any rate, exacdy one of the three polygons contains the triangle t 2 .
Call U this polygon, letting u denote its edge adjacent to ^ and / be the triangle of T adjacent to u and lying in U ( fig.2). Since the triangulation of P also provides a triangulation of £/, and its associated graph G u is a subgraph of G, we can see that if there is a unique path in G u from / to ^, there is also a unique path in G from / x to t r Therefore we can prove the lemma by induction on the number of vertices. • The main advantage of this algorithm is that it avoids the complicated stack manipulations of [CH80] and [HA81J. The reader may convince himself/hcrscif/itself that the algorithm could be rewritten without greater difficulty in order to deal directly with a more general convex decomposition (i.e.. without first converting it into a triangulation). This may be an interesting alternative if one is willing to exploit the fact that searching among the edges of a convex polygon can be done in logarithmic time, using a Fibonacci search-based stratcgy [CH80\CD80]. We would not recommend this approach in practice, however, unless the size of the problem was particularly gigantic. Once again, we leave substantiating these digressions to the attention of the reader. [

The car-racing problem
What is the shortest trajectory of a racing car on a given circuit? More precisely, the problem which we address in this section can be expressed as follows: A and B (fig.6).

Given a simple polygon P and two arbitrary points A and B in P, find the shortest path inside P between
[ from each other, in 0(A/ 2 ) time, so as to form the so-called viewability graph of P. We next add weights to the graph by associating to each edge the Euclidean distance between its endpoints. Computing an internal path ' is now equivalent to finding the shortest path between two vertices of a graph with .V vertices, which can be done in 0(iV 2 ) time. Of course, we assume in this case that both A and B arc vertices of P. We will next show how the use of a triangulation permits us to compute the internal path in 0(N) time, without even having to restrict the points to be on the boundary of P. Note that since we know how to compute a triangulation of an N-gon in 0( A/log AO time, this result constitutes a significant improvement.
For the time being, we will assume that both A and B arc vertices of P. We will sec later on how we can easily dispense with this requirement. If A and B arc vertices of the same triangle of T it is clear that IP( A.B) = AB, so wc may assume that this is not the case. In the following, wc will say that an interior edge of 7" is AB-crossing if its endpoints u.v arc such that A.u.B.v appear this order around the boundary of P. Let P* be the polygon resulting of the removal from 7of all the edges that arc not AB-crossing ( fig.7). Wc first prove a few technical lemmas. Proof: It suffices to show that IP (A,B) can only intersect AB-crossing edges. To see that, suppose that it intersects an interior edge e which is not AB-crossing. Since e partitions P into two polygons, one of them docs not contain therefore IP( A.B) crosses e at least twice (once in each direction). If A (resp. B*) is the first (resp. second) intersection, going from A to B, replacing the . pan of \P(A.B) from A* to B* by the segment A*B* will shorten the length of IP(which leads to a contradiction. • Lemma 4: The internal path between A and B intersects every interior edge of P* exactly once, and intersects no other edge in T. Proof: The proof of Lemma 3 shows that IP(/U?) cannot intersect any interior edge more than once. On the other hand, we can easily prove by induction thai since every interior edge of P partitions this polygon into two parts, neither of which contains both A and £, it must intersect IP(/1,£) at least once. Putting this result together with Lemma 3 completes the proof. • It is easy to compute P* in 0(N) time. To do so, consider every interior edge of T in turn, and if it is not AB-crossing, remove it from T along with the dangling sub-polygon, just created, that does not contain A or B. Let L = {j 1 6 1 ,...,j p 6 p } be the interior edges of as they appear from A to B ( fig.7), i.e., in the order in which they intersect IP(/1,2?) (Lemma 4). Note that it is straightforward to obtain L in 0(N) time, once P* has been computed. From now on, the term IP(JC,>'), with JC,;; vertices of refers to the internal path between x and y with respect to either P or P*. This is legitimate since the two paths are identical, as a simple generalization of Lemma 3 readily shows.
Proof: Let and C, be two oriented curves originating at the same point. To carry the analogy with internal paths. wc~may further assume that neither is self-intcrsccting; we say that C { and C 2 have a proper crossing if. as we follow C } from its starting point, we encounter a point where C 2 intersects C r and actually switches from one side to the other. Kig.9.1 (but not fig.9.2) shows an example of a proper crossing.
[ We next prove that for any three points A.B.C in the two paths 1PM./?) and IP(/1,C) never have any proper crossings. Suppose that they did: let a be die first point (starting at A) where \P(A.B) and IP(/I.O cease to coincide, and let b denote the next intersecting point. Since IP{A.B) and IP(.i.O take distinct paths from a to 6, we may re-route cither one to the other, since they must have exactly the same length. Iterating on this process will eventually cause all proper crossings to disappear, which proves the above fact We can now establish Lemma 5 by induction on L The initial case being trivial, we may directly assume that the lemma is true for all indices from 1 to L Since the a m b m 's are triangulation-cdgcs. we necessarily have a. = a. +1 or b { =b { + v say, J i = a i+r wlo S* "^u s -considering the path IP(^,6. +1 ), we observe that since it does not have any proper crossings with cither lP(/l,a.) or IPM,^), 1. It must pass through their common point v.

Its vertices between v and
1 are vertices of U and W.
From 1.. it results that we may concentrate on the path IP(v,6. +1 ) instead of IP(/f,6 i+1 ), since we obviously have IP(/i,6 i+1 ) = lPM,v) u IP(v,6 i+1 ). Next, we strengthen proposition 2. by proving that the vertices of IP(v,6 i+1 ) are vertices of U or but never of both at the same time. Indeed, suppose wlog that starting at v, the vertices of IP( v,6. + x ) are / r /->,.... with ^ through / lying on U and / i on W. It follows that the angle (tt^^.jt^ ,) is under 180 degrees, therefore there is m+i ^ m m+ L m m-l w an obvious shortcut for lP(v,6 i+] ), avoiding t ( fig. 10). which leads to a contradiction. Thus there are now two basic cases to consider, depending on whether IP( v,6. + ] ) takes its vertices in U or W.
In the former case, v will be relocated further ahead on £/, whereas it will stay unchanged in the latter. The details are straightforward, so we may consider the proof of the lemma as complete. • We are now ready to proceed with the algorithm for computing IP(/1,2?). The method involves computing \P(A,a { ) and IP(/4,&), for i=l,...,p, which we can do iteratively by using the results of Lemma 5. The procedure being trivial for i= 1, we turn to the general step directly. As already mentioned, we have either Q \ ~ a \ +1 0f *i = *i + r an( * WC Can 388111116 w l°8 * at a \~ a \ + r ^-Cl U l U a ^r cS P' w l w fi) ^C ^C vcrt i ces Of U (rcsp. W) from v to jj (resp. fc).
The half-plane delimited by a.b { on the side where b^l lies is partitioned into a +/? +1 regions, themselves delimited by the lines passing through With this order, the regions appear sorted along the segment a.6. from b to a., so that we can find the region which contains b. ^ by testing each of them in turn in this order, until we arc successful ( fig.ll). This corresponds to unfolding H 7 and possibly folding over U. If& + 1 lies in a pencil of die kind ( w k _ l w ]c .* v i c w k + 1 ). we must simply remove vv^ from ^and reset to k+1 and to b^{ ( fig.11.1). If b + l lies in the pencil (u. UMM. ,), however, wc must set W to u.b remove (\>,u. u, ,) from V and finally set v to u.
( fig. 11.2). All the other cases arc similar and call for no further explanation. Since none of the vcrtices removed in these operations will ever be examined again (Lemma 5), both IPM,a p ) and IP(/l,6 p ), hence IP(A.B\ will be computed in O(A0 time.
We generalize this result by allowing both A and B to lie anywhere inside P, and not only on the boundary.
Let R (resp. S) be the triangle where A (resp. B) lies. If R = S, the problem is solved since Otherwise, we can compute the chain of triangles P* in exacdy the same way as described above.
Next, let v. v. be the interior edge of R which U\A,B) crosses. We can replace R by the triangle v.v.A without altering the path IP( A,B). Applying the same treatment to S will make A and B become vertices of P* 9 which allows us to call on the procedure described earlier to compute IP(/i,2?). In conclusion, we can state our main result: Theorem 6: Let P be a simple iV-gon, and assume that any triangulation of P is available. For any pair of points A.B in P % it is possible to compute \P(A,B\ the internal path between A and B, in O(iV) time, which is optimal in the worst case.

The all-internal-paths problem
The problem is to preprocess the polygon P so that a batch of queries of the kind:

What is the internal path between A and B?
can be answered optimally. The method described in the previous section grants an attractive balance between execution and preprocessing time, when only a few queries have to be handled at any given time. It is worst-case optimal, but not optimal in the strictest sense of the term, since all the vertices of P must always be examined for every query. As a result, the precomputation of all possible internal paths between vertices entails a prohibitive 0(JV 3 ) cost The goal which we set forth here is to preprocess P so that the computation of

The internal-length problem
Imagine that an island with only inland communications is to be serviced by some utility (water tank, power station, fire house, police station, hospital, etc...). An interesting piece of information which may be needed is an upper bound on the internal path length between any pair of points.
Let A*,B* be the two vertices of P which form the longest path IP(/f, 5*). We call |IP(/4*,£*)| the internal length of P. It is easy to determine A* and B* by trying out all possible pairs of vertices and using the matrix F of the previous section, given that the longest path can always be assumed to be found between two vertices of the polygon. This leads to an 0(N 3 ) running time, which we can cut down to 0(N 2 ) by proceeding as follows: Let DM,20 = |IP(/I.2?)|. We will compute D(A,B) itcrativcly by summing up partial distances obtained from F. In order to avoid duplicating computations, as soon as TXA.B) is available, we backtrack along the path just followed in F to record the partial results. This ensures that, on average, one value D(/i,2?) will be computed at every other step, which leads to an 0(JV 2 ) algorithm.

INTDIST
- Initially, each D(A,B) is set to -1 for A+B. and to 0 for A= B.        Figure 10