an optimal algorithm for realizing a delaunay triangulation

6
ELSEVIER Information Processing Letters 62 ( 1997) 245-250 An optimal algorithm for realizing a Delaunay triangulation Timothy Lambert School of Computer Science and Engineering, University of New South Wales, PO. Box I, Kensington NSW 2033, Australia Received 1 July 1994; revised 1 March 1997 Communicated by R.G. Dromey Abstract Dillencourt ( 1990) gives a constructive proof for the realizability as a Delaunay triangulation of any triangulation of the interior of a simple polygon. A naive implementation of the construction will take 0( n*) time. I give a simple O(n) algorithm for this problem. An application of this algorithm is generating test data for algorithms that process convex polygons. ($ 1997 Elsevier Science B.V. Keywords: Delaunay triangulation; Realizability; Algorithms; Computational geometry; Convex polygons 1. Introduction Testing geometric algorithms requires sources of random geometric objects. In particular, algorithms that deal with convex polygons require “random” con- vex polygons for testing. Unfortunately, there is no accepted definition of what a random convex poly- gon is. For example, Sylvester’s problem [ 121 is to find the probability that the convex hull of four ran- dom points is a quadrilateral. Even for points drawn from the uniform distribution, this turns out to de- pend on the shape of the region from which they are drawn. Random convex polygons have been generated on the computer by Crain [ 31, who used Voronoi poly- gons defined by a Poisson point process, by Crain and Miles [ 41 who examined polygons defined by a Pois- son line process, by Devroye [ 61, DePano et al. [ 51 and Abrahamson [ 1] who took the convex hull of ran- dom points, and by May and Smith [9] who took the Email: [email protected]. intersection of random half-spaces. However, none of these methods iet you specify the number of sides of the polygon. Roussille and Dufour [ 111 present an algorithm that allows the number of sides of the polygon to be spec- ified. The algorithm works its way around the bound- ary of the polygon, randomly choosing an angle for each corner and a length for each edge. Unfortunately, once the first few angles are chosen, the rest are forced to be very close to straight angles. XYZ Geobench [ 13,101 contains an algorithm for generating a random convex polygon with a specified number of sides. It can best be described if we use polar coordinates pi = (Ti, ei), where 1 < i < n, for the corners of the convex polygon. The angles Bi are chosen by taking n values from the uniform distribution on [ 0,277-) and sorting them so that the corners are given in anti-clockwise order. An initial cyclic convex polygon is created by setting all the Tis to 1. Then, a randomly chosen li is given a new randomly chosen value ri, subject to the constraint that the resulting polygon remain convex. This is repeated 0020-0190/97/$17.00 @ 1997 Elsevier Science B.V. All rights reserved. PII SOO20-0190(97)00071-9

Upload: timothy-lambert

Post on 02-Jul-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

ELSEVIER Information Processing Letters 62 ( 1997) 245-250

An optimal algorithm for realizing a Delaunay triangulation Timothy Lambert ’

School of Computer Science and Engineering, University of New South Wales, PO. Box I, Kensington NSW 2033, Australia

Received 1 July 1994; revised 1 March 1997

Communicated by R.G. Dromey

Abstract

Dillencourt ( 1990) gives a constructive proof for the realizability as a Delaunay triangulation of any triangulation of the interior of a simple polygon. A naive implementation of the construction will take 0( n*) time. I give a simple O(n) algorithm for this problem. An application of this algorithm is generating test data for algorithms that process convex polygons. ($ 1997 Elsevier Science B.V.

Keywords: Delaunay triangulation; Realizability; Algorithms; Computational geometry; Convex polygons

1. Introduction

Testing geometric algorithms requires sources of random geometric objects. In particular, algorithms that deal with convex polygons require “random” con- vex polygons for testing. Unfortunately, there is no accepted definition of what a random convex poly- gon is. For example, Sylvester’s problem [ 121 is to find the probability that the convex hull of four ran- dom points is a quadrilateral. Even for points drawn

from the uniform distribution, this turns out to de- pend on the shape of the region from which they are drawn.

Random convex polygons have been generated on the computer by Crain [ 31, who used Voronoi poly- gons defined by a Poisson point process, by Crain and Miles [ 41 who examined polygons defined by a Pois- son line process, by Devroye [ 61, DePano et al. [ 51 and Abrahamson [ 1 ] who took the convex hull of ran- dom points, and by May and Smith [9] who took the

’ Email: [email protected].

intersection of random half-spaces. However, none of

these methods iet you specify the number of sides of the polygon.

Roussille and Dufour [ 111 present an algorithm that

allows the number of sides of the polygon to be spec- ified. The algorithm works its way around the bound- ary of the polygon, randomly choosing an angle for each corner and a length for each edge. Unfortunately, once the first few angles are chosen, the rest are forced to be very close to straight angles.

XYZ Geobench [ 13,101 contains an algorithm for generating a random convex polygon with a specified number of sides. It can best be described if we use

polar coordinates pi = (Ti, ei), where 1 < i < n, for the corners of the convex polygon. The angles Bi are chosen by taking n values from the uniform distribution on [ 0,277-) and sorting them so that the corners are given in anti-clockwise order. An initial cyclic convex polygon is created by setting all the Tis to 1. Then, a randomly chosen li is given a new randomly chosen value ri, subject to the constraint that the resulting polygon remain convex. This is repeated

0020-0190/97/$17.00 @ 1997 Elsevier Science B.V. All rights reserved.

PII SOO20-0190(97)00071-9

246 7: Lmnbert/lnformtion Processing Letters 62 (1997) 245-250

n times. However, for large n, all the vertices lie very close to the unit circle [ 81.

An alternative to these methods is to choose a ran-

dom topological triangulation of a polygon and con- struct a convex polygon with Delaunay triangulation homeomorphic to this.

Atkinson and Sack [2] give a O(n) algorithm for

choosing a random triangulation of a convex polygon. Dillencourt [7] gives a constructive proof for the

realizability as a Delaunay triangulation of any trian- gulation of the interior of a simple polygon. A naive implementation of the construction will take O(n*) time. I show below how the construction can be per- formed in O(n) time.

The total time to generate a convex n-gon by this

method is O(n). Sugihara [ 141 gives a simpler proof of Dillencourt’s

result. His construction can also be implemented in O(n) time. However, the basic operation it uses is to select a point in a region bounded by a circular arc and two lines. If finite precision arithmetic is used,

the region may not contain any points of the precision

used.

2. Realizing a Delaunay triangulation in O(n*) time

Dillencourt’s construction shows how to compute each angle of each triangle in the triangulation. If the values of the angles (measured in some arbitrary units such that s units form a straight angle) are ai, then the ais must satisfy the following properties: ( 1) For each vertex, ai, + . . . + ai, < s where

ai,, . . . 1 ui, are the angles at that vertex. This says that the polygon is convex.

(2) For each edge AB between triangles ACB and ABD, LBDA + LACB < s (see Fig. 1). This says that the triangulation is Delaunay.

(3) For each i, ai > 0.

(4) For each triangle, Ui + Uj + Uk = s where Ui, Uj

and ak are the angles of the triangle. The construction proceeds incrementally, comput-

ing values satisfying the above properties for progres- sively larger subtriangulations of the triangulation to be realized.

The dual graph of the triangulation of a polygon is a tree (see Fig. 5). This means that between any

Fig. 1. Adding triangle ACE.

pair of triangles there is a unique path, with each step of the path crossing an interior edge of the triangula-

tion. Hence, for each triangle T in a triangulation of a

polygon we can define the opposite comer to another triangle S to be the corner of T opposite the last edge crossed in the path from S to T. For example, in Fig. 8

the opposite corner of 234 to 678 is 3. The construction starts by selecting any triangle of

the triangulation, setting the value of each of its an- gles to 1 and s to 3, clearly satisfying the four proper- ties above. Each step adds a triangle (which we call the adjacent triangle) sharing a common edge (AB

in Fig. 1) with one of the triangles in the subtriangu- lation.

Let z be the value of the opposite corner of the adjacent triangle to the new triangle (see Fig. 1) . The new triangle is given values z + 1, z + 1 and s - z - 1 at vertices A, B and C respectively. The value of s is replaced by s’ = s + z + 1. In all the other triangles the value of the opposite corner to the new triangle is

increased by z + 1. Property ( 1) remains true for vertices other than A,

B and C: since exactly one of the angles adjacent to each of these vertices is an opposite corner, both sides of the inequality ai, + . . . + ui, 6 s are increased by z + 1. The totals at A and B are also increased by z + 1, while there is only one angle at C, and it is clearly less than s’.

Property (2) remains true because for edges other than AB only one of the angles facing the edge is an opposite corner, while for AB we have LBDA + LACB=z+z+l+s-z-l=s+z<s’.

Property (3) is obviously still true.

T L.ambert/lnformation Processing Letters 62 (1997) 245-250 247

Fig. 2. Realizing a Delaunay triangulation.

Property (4) is true for OABC. For the other trian- gles it is still true since there is exactly one opposite corner per triangle.

Fig. 2 shows an example of the steps in the con- struction.

Once all the angles of all the triangles have been

computed we just need to pick positions for the end- points of one edge and then use a little trigonometry to determine the positions of all the other vertices. Fig. 3 shows the polygon determined by the angles in Fig. 2.

Since an angle in each triangle must be updated at each step in the computation of the angles the total time required is 0 (n*) .

3. Realizing a Delaunay triangulation in O(n) time

The key to improving the execution time to O(n) is the following observation: Since the angles of a triangle add to s, it does not matter if the value of one

of the angles is incorrect, as long as we know which one it is. This observation allows us to do the updating of the angles described in the previous section in a lazy fashion - at each step we will only update the angles of one triangle.

Any given triangle ABC divides the triangulation into three pieces: those triangles for which the op-

posite corner of ABC to the triangle is A, those for which the opposite corner is B and those for which the opposite corner is C (see Fig. 4). If we add all the triangles for which the opposite corner of ABC is A without updating the angles of ABC only the value of A will be incorrect. Its value can then be com- puted from the value of s and the other angles. Then the triangles for which the opposite comer is B can be added and the value of B corrected and similarly for C.

We wish to do this for all triangles, so the ap- propriate order is given by traversing the outer face of the dual graph of the polygon triangulation (see Fig. 5).

248 T. L_ambert/lnformation Processing Letters 62 (1997) 245-250

Fig. 3. A realized Delaunay triangulation (angles in degrees).

Fig. 4. ABC divides the triangulation into three components.

To describe the invariant for this algorithm we need one more piece of state - the current triangle of the traversal. By the opposite comer of a triangle we just mean the opposite corner with respect to the current triangle. (The current triangle does not have an oppo-

site corner.) For each angle i we store a value a:. The relationship

between the af and the ai of the previous section is quite simple: If i is not an opposite comer then ai = a;. If i is an opposite corner, the value of ai is irrelevant andai= s - a$ - ai, where j and k are the two other corners of the triangle.

The traversal order ensures that we only ever cross a single edge when moving from one current triangle to

4 “\\ 3 ,,A

;\‘I

,:$L I’

Fig. 5. Dual of triangulation and traversal order.

2

_~ 9

Fig. 6. New current triangle is previously unvisited.

a new one. If the new current triangle is one we have not visited before then we can compute the values for its angles and update s just as in Section 2 (see Fig. 6). This will be correct since we know that the values for the current triangle are correct. The difference from Section 2 is that we do not add z + 1 to all the opposite

corners with respect to ABC. Since ABC is now the current triangle, these are all opposite corners and their values will be ignored.

If the new current triangle has been visited before, the comer opposite the edge crossed to enter this tri- angle is no longer an opposite comer, so we compute its value from s and the values of the two other cor- ners.

One traversal of the outer face ensures that all the triangles are visited. A second one ensures that all the angles are correct. Fig. 7 shows the steps for our exam- ple triangulation. The current triangle is highlighted in bold. The steps where no values change have not been shown.

Each step takes 0( 1) time. The traversal crosses each edge exactly twice, so there are O(n) steps and a total run time of O(n) .

?: Lumbert/lnformtion Processing Letters 62 (1997) 245-250 249

15 I

1

2 1 s \

\

I 15 I

2 2

2 2 3 B 3

5

3, \ 9

3 53

1 2 2 11

11

2 2 3 P 35

5 3

> 9

3 53

L!_Ll

2 i, 2 3 x3 3

5 3

35 9

3 53

1

2 2 3

3 Ia 5 5 3

9

9 3 53

/5) 2 1

2 1 s _A

17) 2 2

3

\

2 \’ B \

m 2 9 11

2 2 3 s 3

35 5 3

; 53 9

Fig. 7. Realizing a Delaunay triangulation - O(n) algorithm.

4. Implementation

The following fragment of C/Java implements the

algorithm described above. The topology of the triangulation is represented by

three functions on the angles. prev and next give

the next angle in the same triangle in the anticlock- wise and clockwise directions respectively. ad j is the successor in the clockwise ordering of angles which share a common vertex. The last angle in this order- ing has adj(i>=-I In Fig. 8 we have next(l)=5, prev(l)=9, adj (1)=2, and adj (2)=-l.

250 1: Lambert/lnformation Processing Letters 62 (1997) 245-250

Fig. 8. Traversal order for angles.

We traverse the angles in the order in which they occur on the outer face (see Fig. 8). Let i is the cur- rent angle. If adj (i) =0 then the successor to i in the ordering is next(i) in the same triangle. Otherwise,

we cross a triangle edge to adj (i) and must update the angles of the new triangle. We store the values of

the angles in array a, which is initially zero (so that we can test to see if we have entered a triangle for the first time by looking at a Cil ) . We assume that the tri- angles are numbered from 0 to 3*n-1, where n is the

number of triangles.

for (i = 0; i < 3*n; ++i)

a[il = 0;

i = 0;

a[il = a[next(i)l = aCprev(i)l = 1;

s = 3;

for (j = 0; j < 2; ++j) (

do C if (adj(i) == -1) I

i = next(i);

) else I i = adj(i);

if (aCi1 == 0) C

z = a[next(adj(prev(i)))l ; a[prev(i)l = aCi1 = 2 + 1;

a[next(i)l = a - z -1;

s=s+z+l;

1 else C

a[next(i)l = a - a[il - aCprev(i)l;

)

) while (i != 0);

An interactive Java applet implementing this algo- rithm is available at the URL http://www.cse.unsw. edu.au/lambert/java/realize.

References

[ 11 K. Abrahamson, On the modality of convex polygons,

Discrete Comput. Geom. 5 (1990) 409-419. [2] M.D. Atkinson and J.-R. Sack, Generating binary trees at

random, Inform. Process. L&t. 41 (1992) 21-23.

[3] I.K. Cram, Monte-Carlo simulation of the random Voronoi

polygons: Preliminaty results, Senrch 3 ( 1972) 220-221.

[4] LK. Cram and R.E. Miles, Monte-Carlo estimates of the

distributions of the random polygons determined by random

lines in a plane, J. Statist. Comput. and Simulation 4 ( 1976) 293-325.

[5] N.A.A. DePano, ED. Boudreau, P Katner and B.

161

[71

181

191

1101

111

112

1

1131

[141

Li, Algorithmic paradigms. Examples in computational

geometry II, in: Proc. 21st SIGCSE Technical Symp. on Computer Science Education, Fort Collins Computer Center,

Fort Collins, CO (ACM, New York, 1990) 186-191.

L.P. Devroye, On the computer generation of random convex

hulls, Comput. Math. Appl. 8 (1982) l-13. M.B. Dillencourt, Realizability of Delaunay triangulations,

Inform. Process. Lett. 33 (6) (1990) 283-287. T. Lambert, Empty-shape triangulation algorithms, Ph.D.

Thesis, Dept. of Computer Science, University of Manitoba,

Winnipeg, Manitoba, 1994.

J.H. May and R.L. Smith, Random polytopes: Their

definition, generation and aggregate properties, Math. Programming 24 (1982) 39-54. J. Nievergelt, P Schom, C. Amman, A. Brllngger

and M.D. Lorezi, XYZ: A project in experimental

geometric computation, in: Computational Geometry: Methods, Algorithms and Applications, Proc. CG’91. Internat. Workshop on Comp. Geometry, Bern, Switzerland,

Lecture Notes in Computer Science, Vol. 553 (Springer, Berlin, 1991) 171-186.

M. Roussille and P Dufour, Generation of convex polygons

with individual angular constraints, btform. Process. Len. 24 (3) (1987) 159-164. L.A. Santalo, Integral Geometry and Geometric Probability (Addison-Wesley, Reading, MA, 1976).

E? Schom et al., XYZ Geobench ~4.4.5, 1994; available by

FTP from neptune.inf.ethz.ch:/XYZ

K. Sugihara, Simpler proof of a realizability theorem on

Delaunay triangulations, Inform. Process. Len. 50 (4)

(1994) 173-176.