Вы находитесь на странице: 1из 7

AMS 345/CSE 355 Joe Mitchell

COMPUTATIONAL GEOMETRY
Practice Midterm – Solution Notes

(1). Triangulate P . This results in n − 2 triangles (in any triangulation). Place a guard at an interior
point (e.g., centroid) of each triangle. Every point of P is seen, since any point p must lie in some triangle,
and the guard for that triangle will see it (since triangles are convex).
(2).
/*---------------------------------------------------------------------
Returns TRUE iff the diagonal (a,b) is strictly internal to the
polygon in the neighborhood of the a endpoint.
---------------------------------------------------------------------*/
bool InCone( tVertex a, tVertex b )
{
tVertex a0,a1; /* a0,a,a1 are consecutive vertices. */

a1 = a->next;
a0 = a->prev;

/* If a is a convex vertex ... */


if( LeftOn( a->v, a1->v, a0->v ) )
return Left( a->v, b->v, a0->v )
&& Left( b->v, a->v, a1->v );

/* Else a is reflex: */
return !( LeftOn( a->v, b->v, a1->v )
&& LeftOn( b->v, a->v, a0->v ) );
}

(3). (a). Compute the number of reflex vertices of P . This can be done in time O(n), since we can spend
O(1) time per vertex to test if it is reflex or not (a single call to “Left” will do). (It is not possible to do
it in sublinear time, since an adversary could make it so that any vertex that we fail to examine is reflex,
thereby messing up the count.)
(b). Compute the convex hull of P (giving as output the vertices of the hull in clockwise order around the
hull). The convex hull of a simple polygon can be computed in O(n) time (e.g., by Melkman’s algorithm).
(It is not possible to do it in sublinear time, since every vertex must be examined.)
(c). Determine one ear of P (any ear is OK). This can be done in time O(n) by triangulating P , and
then stepping through the n − 3 diagonals, looking for one of the appropriate form (linking a vertex of index
i with a vertex of index i + 2 (mod n)). (It cannot be done faster than linear time, in the worst case.)
(Additional note: If we allow O(n) preprocessing of P , it turns out that we can test whether or not v i
is the tip of an ear in time O(log n), using “ray shooting queries”; however, applying this method to each
vertex in turn would take O(n log n) time, which is inferior to using triangulation. It would, though, tell us
all the valid ears. Using triangulation as a starting point, though, it is possible to identify all valid ears in
time O(n). Do you see how?)
(d). Triangulate P , giving a valid set of diagonals in any order. This takes time O(n); just use Chazelle’s
triangulation algorithm.
(e). Triangulate (all of ) the pockets of P , giving the set of diagonals in any order. This again takes time
O(n). Let ni be the number of P vertices in the ith pocket. Then, we traingulate P each pocket in linear (in
ni ) time, resulting in total time i O(ni ) = O(n). We have used the fact that i ni = O(n), which follows
from the fact that each vertex belongs to at most 2 pockets. (Vertices on the convex hull can belong to 2
pockets, while all other vertices are part of exactly one pocket.)
(4). (a). P is a simple polygon (not of any special class) Then, by the standard Art Gallery Theorem, we
know that bn/3c guards are sufficient and sometimes necessary. Thus, G(n) = bn/3c.
(b). P has exactly one reflex vertex Then, placing a single guard at the reflex vertex, v i , suffices to see all
of P . (There are many simple proofs of this claim. One is: Extend edge vi−1 vi across P , forming a chord e.
Also extend edge vi vi+1 across P , forming a chord f . These two chords decompose P into 3 convex polygons
(can you prove it?), each of which has vi as a vertex. Thus, vi guards all three subpolygons and therefore
guards all of P .)
At least one guard is necessary for any P . Thus, G(n) = 1 for this class.
(c). P is convex Then one guard is sufficient and sometimes necessary: G(n) = 1.
(d). P is y-monotone Chvatal’s comb can be drawn so that it is y-monotone (do it!). Thus, we know that
we may require bn/3c guards. Fisk’s proof shows that bn/3c guards suffice in any simple polygon (including
monotone polygons). Thus, G(n) = bn/3c.
(e). P has a single pocket Chvatal’s comb can be drawn to have a single pocket; see below. Thus, we
know that we may require bn/3c guards. Fisk’s proof shows that bn/3c guards suffice in any simple polygon.
Thus, G(n) = bn/3c.

(5). (a). Show the horizontal trapezoidalization of P . See the horizontal dashed chords in the figure below.
(b). Show the decomposition into monotone polygons given by the algorithm of Section 2.2. The diagonals
are drawn in red below: (14,19), (8, 22), (1,6).
(c). Show a triangulation of P that can be obtained from triangulating the monotone polygons. A valid
set of diagonals is shown in heavy blue dashed segments below.
(d). By inspection, obtain the point guard number for P , allowing guards to be placed at any point
(interior or boundary) of the polygon. Justify your answer! (Give an argument that fewer guards cannot
suffice.) The guard number is g(P ) = 4. We can place witness points at vertices 4, 7, 12, 21. Each of
these has a visibility polygon (shown in shaded blue below) that does not intersect any of the other witness
visibility polygons; thus, at least 4 guards are needed in order to see these 4 witness points. We can in fact
find a set of just 4 guards (shown as white disks below).
11 11
16 16
10 15 10 15
12 12
13 17 13 17
18 18
14 14

8 9 19 8 9 19

3 22 20 3 22 20
0 0
7 7

4 4
5 5
21 21
6 6

1 1

2 2

(e). Assume that we execute Melkman’s convex hull algorithm on the vertices of P in the order v 0 , v1 ,
v2 , v3 , etc. (In the figure, I label vi with “i”.) Show the deque, indicating the “top” dt and “bottom” db at
the instant just after having computed the hull of the first 8 vertices (v 0 –v7 ) and also just after the first 9
vertices (v0 –v8 ).
Using the convention of the handout on Melkman’s algorithm, I give the deque as < d b , . . . , dt >. The
evolution of the deque during the algorithm is: < 2, 1, 0, 2 >, < 3, 2, 1, 0, 3 >, < 3, 2, 1, 0, 3 >, < 3, 2, 1, 0, 3 >,
< 3, 2, 1, 0, 3 >, < 3, 2, 1, 0, 3 >, < 8, 2, 1, 0, 8 >, < 9, 8, 2, 1, 9 >. (A careful examination of the figure reveals
that point v9 lies to the right of the segment v1 v0 .) See the figure below.

AMS 345/CSE 355 (Spring, 2003) Joe Mitchell

COMPUTATIONAL GEOMETRY
Another Practice Midterm – Solution Notes

Statistics: n = 44, µ = 76.7, median 80.5, σ = 15.8; score range: 44-100


(1). By inspection, we obtain 4 guards that suffice to see P ; thus, g(P ) ≤ 4. In order to prove that at least
four guards are needed, we can place witness points at vertices 17, 3, 9, and 14; the 4 visibility polygons
from these points are pairwise-disjoint (no overlaps), so at least one guard must be placed in each of these 4
visibility polygons, proving that g(P ) ≥ 4. (Other choices of witness points also work; witness points need
not be at vertices, of course.) In the figure below, guard points are shown in small red circles, witness points
are shown in large blue circles. I show shaded in blue
12
14
11

18
17 13

7
16 15
0
8

3 9 10

4 1
19 2
6
5

(2). The predicate is shown below. The blanks could have been filled in correctly in various ways,
e.g., since Left(a,b,d) = Left(b,d,a) = Left(d,a,b), and Collinear(c,d,a) = Collinear(c,a,d)
= Collinear(a,c,d), etc.
/*---------------------------------------------------------------------
Returns true iff ab properly intersects cd: they share
a point interior to both segments. The properness of the
intersection is ensured by using strict leftness.
---------------------------------------------------------------------*/
bool IntersectProp( tPointi a, tPointi b, tPointi c, tPointi d )
{
/* Eliminate improper cases. */
if (
Collinear(a,b,c) ||
Collinear(a,b,d) ||
Collinear(c,d,a) ||
Collinear(c,d,b)
)
return FALSE;

return
Xor( Left(a,b,c), Left(a,b,d) )
&& Xor( Left(c,d,a), Left(c,d,b) );
}

(3). Let P be a simple polygon in the plane. The statement If a (stationary) guard is placed at every convex
vertex of P , this set of guards sees all of P . is FALSE. A counterexample is given by Godfried’s favorite
polygon (below, taken from the solution to HW1), which has 3 convex vertices: points in the center of the
polygon are not seen by any of the 3 convex vertices. There are also rectilinear counterexamples (e.g., an
“H”). There are many other counterexamples too, as several students discovered. It is also not even the case
that all of the boundary is seen if we place guards at all convex vertices (do you see an example?).

(4). There are at least two simple ways to use RayShoot(v,w) to perform triangulation efficiently (in
O(n log n) time):
(1). Just use RayShoot(v,w) to replace Diagonalie(a,b) in the ear-clipping algorithm, Triangulate:
In order to test if ab represents an interior or exterior diagonal (i.e., does not intersect any edge of P other
than those incident on a and on b), we just call RayShoot(a,b) and determine if the output point is b. This
means that we test ab in time O(log n) instead of O(n), as is done naively in Diagonalie(a,b). When we
argued that Triangulate takes only O(n2 ) time, this was based on making O(n) calls to Diagonal (and
hence to Diagonalie), at a cost of O(n) per call; now that these tests are only O(log n), the total time
is O(n log n). (There is one other place in Triangulate that we need to be slightly smarter: We should
keep the ear tips linked by a doubly link list in the order they appear around the boundary of P . This is
a separate ordering from the links for the vertices of P . We need them in order to move quickly from one
ear tip to the next, so that we avoid the quadratic behavior that may happen in the example of Figure 1.28.
With these extra pointers, we can “jump” to the next ear tip.)
(2). Just use RayShoot(v,w) to fire bullets left/right from each vertex of P and thereby construct the
trapezoidalization in time O(n log n) (at most 2 ray-shoots (one left, one right) per vertex v, where we use
w = (vx ± 1, vy ), a point to the left or right of v); after that, we convert to a set of monotone polygons (or
monotone mountains) in O(n) time and spend another O(n) time triangulating all of them.
(5). There are many possible classes of examples of polygons having unique triangulations; one simple class
of examples is illustrated below.
(6). The base is the left chain. (In this case, the base is unique.) We mark the top points and bottom
points as special: these are not used as ear tips. We walk down (top to bottom) the non-base (right) chain,
identifying ear tips as we go by a simple local test: is the vertex strictly convex? (O(1)) In principle, we can
pick any (non-top, non-bottom) vertex that is convex and clip its corresponding ear; however, the rule I used
in class specified that we always choose the highest (“highest” means with respect to “vertical”, the direction
of monotonicity we are using) convex vertex of the non-base chain. We then get a unique triangulation of
each, as shown below.
The diagonals are added in the order (9,11), (8,11), (6,8), (6,11), (0,6), (4,6), (3,6), (1,3), (1,6). (Thus,
the fifth one is (0,6).)
0

11
10

9
8

7
6

4
3

2
1

(7). Let S be a set of n points in the plane, given in arbitrary order. For each of the computations below
indicate how efficiently one can perform the calculation, in terms of O(...) notation (e.g., O(n), O(log n),
O(n2 ), O(n log n)). Try to give the best (lowest) upper bound possible in terms of n and h (the number of
convex hull vertices).
(a). It takes worst-case time O(n log h) to compute the convex hull, CH(S), of S, using the “ultimate
convex hull algorithm” (which we discussed existing but did not go into detail), which is the best possible
(there is an Ω(n log h) lower bound, even if the goal is simply to determine the number of vertices on
the convex hull). If we do not take into account the output size h, the most efficient algorithm possible
is O(n log n) (recall that we gave a lower bound of Ω(n log n), from sorting), as is achieved by Graham’s
algorithm, divide-and-conquer, incremental construction, etc.
NOTE: Several students answered “O(n)”, citing Melkman’s algorithm; however, Melkman’s algorithm
applies only to a set S of points that are given in a very special order: they form a simple chain (no crossings).
Order is very important! If the points S are given in some form of sorted order (e.g., sorted by x or by y or
by position along a simple chain), the problem becomes easier and O(n) time suffices.
(b). In order to determine if the convex hull, CH(S), is a hexagon (6-sided polygon), the simplest thing
to do is to apply the gift-wrapping algorithm (Jarvis march) for (up to) 6 iterations; if the algorithm “closes”
the hull within 6 steps, then we know the hull has at most 6 vertices. Each step of gift-wrapping takes time
O(n).
(A less efficient approach would be to compute the hull in time O(n log h) and then count the size (h)
of the output. This, however, is not only more complicated, but requires worst-case time O(n log n) (e.g., if
h = n).)
(c). One edge of CH(S) can be found in time O(n): just do the first iteration of gift-wrapping.
(d). Given as input the set S, the area of CH(S) can be computed in time O(n log h) by computing the
convex hull and then computing the area of the h-vertex polygon in time O(h). (The text shows you how to
compute the area of any simple polygon in linear time, even without having a triangulation of it. Here, we
could construct a trivial (“star”) triangulation of the polygon CH(S), in O(h) time, and then add up the
areas of the triangles (each of which can be computed in time O(1)).)
(8). The diagonals that are output when Triangulate is executed on P are given by: (2,4), (2,5), (2,6),
(8,10), (8,11), (8,12), (8,13), (13,15), (16,18), (16,19), (0,16), (1,6), (1,7), (7,13), (7,15), (0,15), (0,7). (You
were only asked to produce the first 6 of them.) Note that the algorithm starts at vertex 0, not at the
rightmost bottommost (as some students did); it really does not matter for this simple algorithm where it
starts, so it may as well save a bit of effort and start at the beginning of the input list (see the code in the
book). I draw the resulting triangulation below (you were not asked to draw it).
12
14
11

18
17 13

7
16 15
0
8

3 9 10

4 1
19 2
6
5

(9). When we execute Melkman’s convex hull algorithm on the vertices of P in the order v 0 , v1 , v2 , v3 , etc.,
we get a deque, < db , ..., dt >. At the beginning (after the first 3 points are considered), the deque is simply
< 2, 1, 0, 2 >. It then becomes < 2, 1, 0, 2 >, then < 4, 2, 1, 0, 4 >, then < 5, 1, 0, 4, 5 >, then < 5, 1, 0, 4, 5 >,
then < 7, 0, 4, 5, 7 >.
0 0 0

3 3
1 1 1
2 2 2

4 0 0

3 4 4
1
3 3
2
1 1
2 2

6 6
5 7

5 5