Class of 2008 Senior Conference on Computational Geometry

70
Computer Science Department CPSC 097 Class of 2008 Senior Conference on Computational Geometry Proceedings of the Conference

Transcript of Class of 2008 Senior Conference on Computational Geometry

Page 1: Class of 2008 Senior Conference on Computational Geometry

Computer Science DepartmentCPSC 097

Class of 2008Senior Conference on

Computational Geometry

Proceedings of the Conference

Page 2: Class of 2008 Senior Conference on Computational Geometry

Order copies of this proceedings from:

Computer Science DepartmentSwarthmore College500 College AvenueSwarthmore, PA 19081USATel: +1-610-328-8272Fax: [email protected]

ii

Page 3: Class of 2008 Senior Conference on Computational Geometry

Introduction

About CPSC 097: Senior Conference

This course provides honors and course majors an opportunity to delve more deeply into a particulartopic in computer science, synthesizing material from previous courses. Topics have included advancedalgorithms, networking, evolutionary computation, complexity, encryption and compression, andparallel processing. CPSC 097 is the usual method used to satisfy the comprehensive requirement for acomputer science major.

During the 2007-2008 academic year, the Senior Conference was led by Andrew Danner in the area ofComputational Geometry.

Computer Science Department

Charles Kelemen, Edward Hicks Magill Professor and ChairLisa Meeden, Associate ProfessorTia Newhall, Associate ProfessorRichard Wicentowski, Assistant ProfessorAndrew Danner, Visiting Assistant Professor

Program Committee Members

Allison BarlowAlex BennGeorge DahlScott DalaneKit La ToucheAndrew FramptonDavid GermanMichael GorbachChris HarmanMike JohnsJeff KaufmanDrew PerkinsDavid RosenLucas SandersMegan SchusterBryce WiedenbeckMary Wootters

Conference Website

http://www.cs.swarthmore.edu/˜adanner/cs97/s08/

iii

Page 4: Class of 2008 Senior Conference on Computational Geometry

Conference Program

Thursday 24 April 2008

9:55–10:10 Seamless Intersection Between Triangle MeshesDavid Rosen

10:14–10:29 Approximate K Nearest Neighbors in High DimensionsGeorge Dahl and Mary Wooters

10:33–10:48 The Road Not Taken: Creating a Path-Finding Tool Using Consumer-Grade GPSEquipmentAllison Barlow and Lucas Sanders

10:52–11:07 Drawing Isoglosses AlgorithmicallyKit La Touche and Bryce Wiedenbeck

Tuesday 29 April 2008

9:55–10:10 The Largest Empty Circle ProblemMegan Schuster

10:14–10:29 Unbiased Congressional DistrictsAlex Benn and David German

Thursday 1 May 2008

9:55–10:10 Optimal Double Coverage in the Art GalleryScott Dalane and Andrew Frampton

10:14–10:29 Voronoi Natural Neighbors InterpolationChris Harman and Mike Johns

10:33–10:48 Bridge Detection by Road DetectionJeff Kaufman

10:52–11:07 Image Stained Glass using Voronoi DiagramsMichael Gorbach

iv

Page 5: Class of 2008 Senior Conference on Computational Geometry

Table of Contents

Seamless Intersection Between Triangle MeshesDavid Rosen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Approximate K Nearest Neighbors in High DimensionsGeorge Dahl and Mary Wooters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

The Road Not Taken: Creating a Path-Finding Tool Using Consumer-Grade GPS EquipmentAllison Barlow and Lucas Sanders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Drawing Isoglosses AlgorithmicallyKit La Touche and Bryce Wiedenbeck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

The Largest Empty Circle ProblemMegan Schuster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Unbiased Congressional DistrictsAlex Benn and David German . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Optimal Double Coverage in the Art GalleryScott Dalane and Andrew Frampton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Voronoi Natural Neighbors InterpolationChris Harman and Mike Johns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Bridge Detection by Road DetectionJeff Kaufman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Image Stained Glass using Voronoi DiagramsMichael Gorbach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

v

Page 6: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 1–8,Computer Science Department, Swarthmore College

Seamless Intersection Between Triangle Meshes

David [email protected]

Abstract

We present an algorithm that providesartistic control of the rendering of in-tersections between two triangle meshes.We detect the intersection edges usingan octree, and then seamlessly subdivideboth meshes at and around the intersectionedges to allow local geometry morphingand creation of transition texture bands.

1 Introduction

In computer graphics there has been a lot of progresson rendering techniques that use diffuse, height, andnormal maps to make rendered surfaces look muchmore detailed than their underlying geometry. How-ever, these techniques do nothing to break up thelinear silhouette of each polygon (Figure 1). Thisis a very difficult problem to solve in general, be-cause the silhouette of an object can change signif-icantly every frame, so any algorithm that appropri-ately changes the silhouette would have to be ex-tremely fast for real-time applications. There hasbeen some progress in this area, but nothing that isreally practical yet (Oliveira and Policarpo, 2005).However, this problem can be solved more easilywhere two static objects intersect because the inter-section line is independent of camera position.

There are two obvious problems with the naiveintersection. First, there is an immediate discon-tinuity in the lighting and texturing that is unlikewhat you see in such intersections in real-life (Fig-ure 2). Second, this discontinuity occurs along per-fectly straight lines, destroying the illusion of depththat the texture mapping is supposed to create.

2 Seamless Intersection Algorithm

To make intersections more realistic, we must ad-dress both of these problems. First, we need to find

Figure 1: Rocks on the beach in Crysis, with shad-ows disabled for clarity. Despite the detailed tex-tures, there is an unrealistically sharp line betweenthe big rocks and the terrain.

Figure 2: A photograph of a post intersecting theground.

1

Page 7: Class of 2008 Senior Conference on Computational Geometry

the intersection between the objects and create ver-tices at each point of intersection. We can then findauxiliary intersections which we will discuss auxil-iary intersections in more detail in section 2.2, andexplain more clearly why they are important. Usingour new intersection and auxiliary intersection ver-tices, we can apply geometric deformations aroundthe intersections, and create texture bands to makethem look more natural. None of these steps are triv-ial, so we will explore them one at a time.

2.1 Data Structures

First, we should look at the data structures we areusing to represent the mesh. The mesh object con-tains an array of vertices and an array of triangles.Each vertex object contains several vectors: a 3-partvector storing its local coordinates, a 3-part vectorstoring its surface normal, and a 2-part vector storingits texture coordinates. Each triangle object containsthree pointers, one to each of its vertices.

2.2 Finding Intersection Segments

To find the intersection of two meshes, we couldcheck every triangle against every other triangle tosee if there is an intersection. However, this wouldrequireO(n2) comparisons, which is not acceptablewhen working with detailed meshes. Fortunately,we can do much better using what I call an inter-section octree (Figure 3), which indexes pairs of tri-angles that might intersect. Each node in the octreecontains the coordinates of its bounding box and twolists of triangles (one for each mesh). We create theroot of the octree by taking the intersection of thebounding boxes of each mesh, and adding all of thetriangles from each mesh that at least partially liewithin this shared bounding box. We then recur-sively subdivide each node until it reaches a maxi-mum depth or no longer contains at least one trian-gle from each mesh. Finally, we walk through all ofthe child nodes and report each pair of triangles, andcheck each pair for intersection using well-knowntechniques (Moller, 1997), returning the intersectionas a line segment. We have now efficiently found theintersection between two meshes as a set of line seg-ments (Figure 4), which will form a closed loop ifboth meshes are closed.

Figure 3: The intersection octree generated by apower transformer and a detailed sidewalk. The oc-tree returned 70 pairs of triangles that might inter-sect, out of 846,000 possible pairs.

2

Page 8: Class of 2008 Senior Conference on Computational Geometry

Figure 4: The intersection segments between apower transformer and a sidewalk.

Figure 5: Without an auxiliary intersection (left),the deformation propagates in an uncontrolled way.With the auxiliary intersection (right), we have pre-cise control over the shape of the deformation.

Figure 6: Scaling a model by moving vertices alongtheir normals, resulting in discontinuities at sharpedges.

2.3 Finding Auxiliary Intersections

If we would like to change the geometry aroundthe intersecting object, we will need to find auxil-iary intersections to protect the environment geom-etry from these changes(Figure 5). For example, ifa tree is intersecting the ground on a large, flat fieldrepresented by a single triangle, then altering the in-tersection points will alter the geometry of the en-tire field. If we want to create a small slope in theground around the tree of some controlled size, saytwo inches, then we can find the auxiliary pointsby translating each vertex in the object out by twoinches in the direction of the surface normal. How-ever, for meshes with sharp edges, the surface nor-mals of overlapping vertices can point in differentdirections, and moving each vertex along its surfacenormal could result in a discontinuous mesh (Fig-ure 6). We can solve this by temporarily averagingtogether all normals belonging to overlapping ver-tices (Figure 7).

3

Page 9: Class of 2008 Senior Conference on Computational Geometry

Figure 7: Scaling a model by moving vertices alongtheir corrected normals. This results in some distor-tion, but no discontinuities

This can be done inO(n log n) time using a kd-tree (Bentley, 1975). We loop through each vertexin the model, and check if the tree is storing a ver-tex that has the same coordinates. If not, we addthe vertex to the tree. If so, we store a pointer tothe vertex that is already in the tree. Now for eachgroup of overlapping vertices, we have a represen-tative vertex in the tree, and every other overlappingvertex has a pointer to its representative. We findthe average normal for each representative vertex bylooping through the vertices again, adding each ver-tex’s normal to its representative’s normal, and thennormalizing it by dividing it by its length. Finally,we can translate each vertex by some multiple of thenormal of its representative vertex.

Figure 8 is an example of typical auxiliary inter-sections that we can use to isolate the effects of ma-nipulation of intersection points. These will also beuseful later to isolate texture transition effects, so wedo not have to apply them to any unnecessarily largetriangles (so we can avoid drawing too many unnec-essary pixels). It is essential to find and store allof the lines of intersection, including auxiliary inter-section, before the final retriangulation. Otherwisewe will have to find intersections with the trianglesthat are already subdivided, and the algorithm willtake longer and end up with many unnecessary sub-divisions.

2.4 Dividing Polygons Along Intersection Lines

Now that we have our intersection segments, whatdo we do with them? We have to retriangulate ourmesh to include these segments as edges, and wehave to do it without any cosmetic changes. Thatis, the retriangulation itself should have no visibleeffect on the scene, but we can use our new ver-tices later to change the intersection however welike. This problem can be divided further into twosubproblems: creating the new vertices, and retrian-gulating the mesh to include the new edges.

2.4.1 Seamlessly Adding Vertices

Suppose we have an intersection point on the edgeof a triangle. How do we incorporate it into themesh? We know the position component already,but our mesh vertices contain other auxiliary infor-mation, such as texture coordinates and surface nor-mals. Since our vertex is on an edge, we can just

4

Page 10: Class of 2008 Senior Conference on Computational Geometry

Figure 8: Some examples of auxiliary intersections

interpolate between the auxiliary information storedin the two endpoint vertices based on their relativedistance from the new point. But what if our inter-section point is not on an edge? Suddenly the prob-lem is much more complicated. We still have to in-terpolate between the three vertices, but it is not asobvious what weights to assign to each vertex in theinterpolation.

The solution here is to find the position of the in-tersection point in barycentric coordinates. That is,find its position as a weighted sum of the positions ofthe three triangle vertices. So far this sounds some-what circular: how do we find the barycentric co-ordinates? We know that the weighted sum of thetriangle vertices in each axis adds up to our new ver-tex, and we know that the weights have to add up to1. We have a system of four independent equationsand three unknowns, so we can just solve it usinglinear algebra. Once we have the weights of eachtriangle vertex, we can use them to interpolate all ofthe auxiliary values of our new vertex.

Figure 9: The Delaunay triangulation (right) doesnot necessarily preserve the lines of intersection(left).

Figure 10: The constrained Delaunay triangulation(right) is guaranteed to preserve the lines of inter-section (left).

2.4.2 Retriangulation

Now that we have our seamless vertices, how dowe incorporate them into the triangulation? At firstwe expected that we could just use Delaunay trian-gulation on the set of intersection points and trian-gle vertices, but that failed because it did not pre-serve our lines of intersection (Figure 9). To achievethe desired results, we had to use the constrainedDelaunay triangulation, which takes as input a setof points as well as a set of line segments to pre-serve(Figure 10). Implementing the constrainedDelaunay triangulation efficiently could easily be afinal project in itself, so we used the free “Triangle”library (Shewchuk, 2002).

2.5 Geometry Morphing

To deform the geometry, we can now safely translateany of intersection vertices that do not lie on the out-ermost auxiliary intersection ring. After moving anyof the vertices, we have to recalculate the normals ofall of the adjacent triangles so that the lighting willbe correct for their new orientation. With one in-tersection ring and two auxiliary intersection rings,

5

Page 11: Class of 2008 Senior Conference on Computational Geometry

Figure 11: Translating upwards the intersection ringand inner auxiliary intersection ring.

Figure 12: Translating upwards only the inner aux-iliary intersection ring.

we can create a number of interesting effects. Wecan raise the intersection ring and the inner auxil-iary ring to slope the ground around the object (Fig-ure 11), or we can only raise the inner auxiliary ringto create a crater effect (Figure 12).

2.6 Texture Band

Our final step is to create a texture band around theintersection. First we will have to create a new meshthat contains a copy of all the triangles and verticesthat we will need, and then we will have to assigntexture coordinates to each vertex in the mesh. Tocreate the new mesh, we can make a copy of eachtriangle that contains at least one of the intersectionpoints, and make a copy of each of its vertices. If itfits the effect we are going for, we can now recalcu-

late the normals to smooth the lighting transition atthe intersection. Alternately, we can leave them howthey are to keep the sharp edge.

Finally we have to calculate the texture coordi-nates. We would like to map the texture in Figure 13to achieve the effect shown in Figure 14 and Figure15. The vertical texture coordinate can be assignedquite simply. Vertices on the intersection ring re-ceive the vertical texture coordinate of 0.5, so thatit is lined up exactly with the center of the texture.Vertices on the innermost auxiliary intersection ringof one mesh receive the vertical texture coordinateof 1.0, and of the other mesh, 0.0. This stretches thetexture over the intersection such that the middle ofthe texture corresponds to the intersection ring, andthe top and bottom stretch out to the innermost aux-iliary ring of each mesh.

The horizontal texture coordinates are a bit moretricky. We have two priorities here: we would likethe texture to be mapped with uniform density, andwe would like it to wrap around seamlessly. Map-ping it with uniform density means that it is neverstretched or compressed. That is, the difference intexture coordinate between two connected vertices isproportional to the physical distance between them.To satisfy this constraint, we can start at any inter-section point and assign it a horizontal texture coor-dinate of 0.0, and walk around the intersection, andassign to each point a texture coordinate equal to thetotal distance walked so far.

To satisfy the second constraint (seamless texturewrapping), we have to round up to the nearest in-teger the total distance. That is, if the total distancewalked is 1.58 units, we have to round it to 2.0 units,and scale all of the other texture coordinates simi-larly. We do this because the right edge of the textureimage lines up seamlessly with the left edge of thetexture image, and the only way that these can lineup on the texture band is if the image is repeated anintegral number of times. If the texture is repeated1.58 times, then there will be a visible seam wherethe texture coordinate wraps from 1.58 back to 0.0.

Now that we have the horizontal texture coordi-nates for the intersection points, we need horizontaltexture coordinates for the remaining points. To findthese we simply loop through all of the remainingpoints and find the nearest intersection point, andcopy its horizontal texture coordinate. We can do

6

Page 12: Class of 2008 Senior Conference on Computational Geometry

Figure 13: A simple dirt texture that can be used fortexture bands.

this in O(n) time instead ofO(n2) by only lookingat points that are connected by a triangle edge.

3 Results

This algorithm allows for artistic control of meshintersections, from subtle weathering effects (Fig-ure 14) to dramatic impact deformations (Figure12). It accomplishes this inO(n log n) time. Inthis prototype implementation it takes about 0.2 sec-onds to create the intersections for the simple powertransformers ( 400 triangles), and about 1.6 secondsto create the intersections for the detailed boulder( 2500 triangles).

The intersection rings and retriangulation are ro-bust to degenerate cases, but the deformation andtexture band creation can give unexpected results insome cases. For example, the current deformationalgorithm will only affect vertices that are on one ofthe intersection rings, so if there are other verticeswithin the deformed area, there can be unexpectedindentations. Similarly, the texture bands stretch outto the nearest vertices connected to the intersectionrings, which may not be the auxiliary intersectionrings if there are already vertices nearby.

Figure 14: A subtle dirt texture (right) around thebase of an object.

Figure 15: A large dirt texture around the base of anobject.

7

Page 13: Class of 2008 Senior Conference on Computational Geometry

4 Discussion and Future Work

There are many applications for this kind of technol-ogy. Two of the most significant applications are ag-ing effects (e.g. rust accumulation around the baseof nails) or ambient occlusion (obstruction of am-bient light when two surfaces are close together).The algorithm takes a fraction of a second to run,so with some optimization it will be useful for dy-namic heightmaps, such as water surfaces, and dy-namic environmental damage from explosions andheavy impacts.

In the future we would like to make the deforma-tion and texture bands more predictable in degener-ate cases, and optimize the algorithm to run faster.We would also like to create a user-friendly inter-face that allows artists to easily create and test newkinds of intersection effects.

5 Conclusion

Intersections between detailed meshes have been aserious problem in modern 3D graphics. We havecreated an algorithm that can automatically createdeformations or texture bands that can greatly im-prove the appearance of these intersections. As faras we know, there has been no other work addressingthis issue, so this is an important new step towardsefficiently creating realistic 3D environments.

References

Jon Louis Bentley. 1975. Multidimensional binarysearch trees used for associative searching.Commun.ACM, 18(9):509–517.

Tomas Moller. 1997. A fast triangle-triangle intersectiontest.Journal of Graphics Tools, 2(2):25–30.

Manuel M. Oliveira and Fabio Policarpo. 2005. An effi-cient representation for surface details.UFRGS Tech-nical Report, RP-351.

Jonathan Richard Shewchuk. 2002. Delaunay refine-ment algorithms for triangular mesh generation.Com-putational Geometry: Theory and Applications, 22(1-3):21–74.

8

Page 14: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 9–17,Computer Science Department, Swarthmore College

Approximate K Nearest Neighbors in High Dimensions

George Dahl

[email protected]

Mary Wootters

[email protected]

Abstract

Given a set P of N points in a d-dimensional space, along with a query pointq, it is often desirable to find k pointsof P that are with high probability closeto q. This is the Approximate k-Nearest-Neighbors problem. We present two al-gorithms for AkNN. Both require O(N2d)preprocessing time. The first algorithm hasa query time cost that is O(d+log N), whilethe second has a query time cost that isO(d). Both algorithms create an undirectedgraph on the points of P by adding edgesto a linked list storing P in Hilbert order.To find approximate nearest neighbors of aquery point, both algorithms perform best-first search on this graph. The first algo-rithm uses standard one dimensional index-ing structures to find starting points on thegraph for this search, whereas the second al-gorithm using random starting points. De-spite the quadratic preprocessing time, ouralgorithms have the potential to be use-ful in machine learning applications wherethe number of query points that need tobe processed is large compared to the num-ber of points in P . The linear dependencein d of the preprocessing and query timecosts of our algorithms allows them to re-main effective even when dealing with high-dimensional data.

1 The Problem

The K-Nearest Neighbors problem is the follow-ing: given a set P of N points in a d−dimensionalspace and a query point q, return the k points in Pthat are closest to q.

However, solving K-Nearest-Neighbors in highdimensions (say, more than 10) has proved compu-

tationally infeasible - most solutions are not muchbetter than the naıve method. Thus, we considerthe Approximate K-Nearest Neighbors prob-lem: given a set P of N points in a d−dimensionalspace, a query point q, and parameters ǫ and δ be-tween 0 and 1, return, with probability greater than1−δ, k points of P such that the ith point is at most(1+ ǫ) times farther from q than the true ith nearestneighbor of q (Arya et al., 1994).

Approximate K-Nearest Neighbors is widelyapplicable, but we are motivated by its applicationto supervised machine learning. Machine learningapplications are often characterized by a data set ofrelatively high dimensionality, so we are interestedin solutions that scale well with d. In a typical su-pervised learning scenario, a training set is processedoffline, and later the system must be able to quicklyanswer a stream of previously unknown queries. Ourassumption is that the number of queries will belarge compared to N , which is why we are moreconcerned with query time than preprocessing time.Many supervised machine learning techniques thatcould be alternatives to K-Nearest Neighbors

have quadratic or cubic (in N) training time. To thisend, our goal is to make query time as fast as possi-ble, and accept almost any reasonable preprocessingcost (quadratic in N or better). Since the naıve al-gorithm has a query time complexity of O(Nd), wedemand a solution that provides query times sublin-ear in N and linear in d.

2 Related Work

Recent solutions to K-Nearest Neighbors that wehave found tend to fall into two categories: ones thatemploy locality sensitive hashing (LSH) (Andoni andIndyk, 2008; Gionis et al., 1999) or ones that usesophisticated tree-like structures to do spatial par-titioning (Liu et al., 2004; Arya and Mount, 1993;Arya et al., 1994; Beckmann et al., 1990; Berchtold etal., 1996). LSH defines a hash function on the query

9

Page 15: Class of 2008 Senior Conference on Computational Geometry

space which has a collision probability that increasesas the distance between two points decreases. In gen-eral, LSH approaches scale reasonably well with d,while the tree-based algorithms tend not to scale aswell. Most notably, Arya et al. (1994) present an al-gorithm which, for fixed d, has a preprocessing costof O(N log N) and a query time of O(log N), butis exponential in d. There are results which scalewell with d and have fast query time. In partic-ular, Kleinberg (1997) presents an algorithm withquery time O(N + d log3 N), and preprocessing costquadratic in d, linear in N , and is O(1/ log(δ)) in δ.Andoni and Indyk (2008) use LSH to achieve a query

time of O(N1/c2+o(1)d), and pre-processing cost of

O(N1+1/c2+o(1)d), where c = (1 + ǫ).

3 Algorithm 1

Our two algorithms are similar. We will describe thefirst in its entirety, and then describe the changes wemake to produce the second one.

3.1 Overview

Algorithm 1 creates several auxiliary data struc-tures to speed up query processing. The most im-portant of these index structures is a graph, G, thatholds all the N points in P . To create G, we first cre-ate a linked list containing all the points in P that issorted in the Hilbert order. Then we add edges to thegraph by linking points that are close together. Thegoal is to create a connected graph (starting witha linked list ensures connectedness) in which twopoints that are close in space will be very likely to beclose on the graph. We also construct a small, con-stant number of one-dimensional search structures,specifically red-black trees, that order points basedon their projections onto one-dimensional subspacesof our space. Given a query point q, the one dimen-sional search structures are used to obtain a smallset of initial guess nodes in G. These are the nodescorresponding to points whose projections are closeto the projection of q in the one-dimensional sub-spaces. Starting at these guess points, our algorithmsearches G until k + m nodes have been touched, forsome constant m (assuming k + m is greater thanthe number of guess points, otherwise we touch eachguess point once). The nodes are sorted by theirdistance to q, and the first k are returned.

Figure 1: The first six curves in the sequence limitingto the Hilbert curve. Picture courtesy of Wikimedia.

3.2 Preprocessing and Auxiliary Data

Structures

Algorithm 1 requires several auxialiary data struc-tures, as mentioned above. It uses a graph G onnodes corresponding to points in P , and several red-black trees. In order to create G, we first computethe Hilbert order of the points in P .

3.2.1 Snapping Points to an Integer Lattice

and Sorting by Hilbert Order

The Hilbert curve is a space-filling curve defined asthe limit of self-similar curves in a d-dimensionalspace. The first few curves in the 2-dimensionalsequence are shown in Figure 1. One of the morecelebrated properties of the Hilbert curve (Jagadish,1990) is that it preserves locality well. That is, if twopoints are close in the d-dimensional space, their pre-images on the unit interval will likely be close. Eachcurve in the sequence touches every point of a d-dimensional lattice with 2n points on each side forsome n. The Hilbert order of a set of points P onsuch a lattice is the order of the preimages of thepoints in the unit interval. We impose a Hilbert or-der on our set of points P by snapping them to sucha lattice first. We compute the location in the latticefor a point by applying the following function to it:

f(~x) = ⌈a~x⌉ +~b,

where1

a= min

~p,~q∈P

(

mini≤d

|pi − qi|

)

andbi = −min

~p∈P⌈pi⌉,

where xi denotes the ith component of ~x. That is,the smallest distance along any axis between any two

10

Page 16: Class of 2008 Senior Conference on Computational Geometry

points becomes the lattice spacing. Such a poten-tially small lattice spacing could be undesirable be-cause computing the Hilbert order might take toolong. In practice, we have not found this to be aproblem, but if it were, a coarser lattice could beused. Once the points are on a lattice, we computethe Hilbert order using an algorithm developed byButz (1971), and explained to us by Jaffer (2008b).Our implementation is based on the implementationof hilbert->int in the SLIB library (Jaffer, 2008a).

3.2.2 Additional Graph Edges

The graph G begins as a linked list of the pointsof P in the Hilbert order as described above. Forclarity, we will refer to nodes in G by the pointthey correspond to in P . Edges are strategicallyadded as follows: each node p in G is linked to theb nodes closest to p in space, for some constant b.If p’s b nearest neighbors are already adjacent toit (perhaps they were in the original linked list orthey themselves have already been processed), theseedges are not added again. This guarantees that eachnode of G will be adjacent to its b nearest neigh-bors. These nearest neighbors are computed usingthe naıve method, i.e., simply scanning all the pointsin P .

3.2.3 One-Dimensional Search Structures

In order to keep preprocessing costs low, we choosea subset P ′ of P consisting of N2/3 points randomlyselected from P . For some constant c, suppose thefirst c principal components of P ′ are {a1, . . . , ac}.For each principal component ai, we create a red-black tree Ti holding the elements of P ordered bywhere they fall along ai.

3.3 Handling Queries

Given a query point q, we search each one-dimensional search structure Ti for the point pi

whose projection onto ai is the closest to the pro-jection of q onto ai. These pi are the c initial nodesfor the search of G.

The search proceeds in a best-first manner by prefer-entially expanding nodes closer to q. If n is a node inG, let d(n) denote the distance from n to q. Two pri-ority queues are maintained during the search, ToEx-pand and BestK. We initialize ToExpand to containthe nodes pi. ToExpand is a minheap with the prior-ity of node n being d(n). We initialize BestK to beempty. BestK is a maxheap, such that the highestpriority node l maximizes d(l). For m + k steps, anode n is removed from ToExpand. If d(n) > d(l) for

the node l with the highest priority in BestK, thenn is added onto BestK and l is removed (assumingBestK contains k items). Then all of the nodes adja-cent to n are added to ToExpand. After m+k steps,the k nodes in BestK are returned.

3.4 Cost Analysis

In order to compute the Hilbert order, we map eachpoint in P to its distance from the origin alongthe appropriate Hilbert curve. This computation isO(d + log s), where s is a times the maximum co-ordinate of p, where a is the factor from our latticesnapping. Although we cannot control the maximumcoordinate or a, we find that in practice, at least, wecan compute the Hilbert order very quickly in hun-dreds of dimensions. We could theoretically controlthese variables by creating a coarser lattice, whichmight result in an approximation of the Hilbert or-der. We are convinced that this is not a problem.We assume that either s is reasonable or we force itto be so by adjusting the lattice, so this step shouldtake time approximately linear in Nd.

We can complete the preprocessing phase of our al-gorithm in O(N2d) time. Once points are in a linkedlist, for each point in P we add at most b additionaledges. The new edges can be computed for a givenpoint with a single scan of the points in P whichwill require O(N) distance computations which eachtake time linear in d. Therefore we can constructthe graph in O(N2d) time. Computing the principalcomponents of a subset of P of cardinality N2/3 canbe done in time quadratic in N since Principal Com-ponent Analysis can be performed in time cubic inthe size of the dataset. The search trees can easily beconstructed in O(N log N) time, so our preprocess-ing phase can be completed in O(N2d) time. Thespace requirements of our auxiliary data structuresare clearly linear in N .

To evaluate a query, we need to do a constant num-ber of searches of red-black trees on N nodes whichwill have a cost logarithmic in N . We also have toproject the query point into one dimension whichadds a term proportional to d to our cost. In thebest-first search of the graph we search a constantnumber of nodes and do a constant number of dis-tance computations in d dimensions. Thus our querytime is O(d + log N).

4 Algorithm 2

Algorithm 2 is a simplification of Algorithm

1. Initial experiments suggested that the one-

11

Page 17: Class of 2008 Senior Conference on Computational Geometry

dimensional search structures used in Algorithm 1

were not that important to performance. Since the1D search structures added a term proportional tolog N to our query time, we designed a new algorithmthat does not use them. In Algorithm 1, the red-black trees were used to get starting points for thebest-first search. In Algorithm 2, we simply pick crandom start points for this search. However, thesestart points will almost certainly be worse guessesthan those produced by the red-black trees. Sincewe only expand a small constant number of nodesin our best-first search and since all of the edges inG connect points that are close in space, the searchwill expand many nodes that are far from the querypoint. Our solution is to add some longer edges toG. In the preprocessing phase of Algorithm 2, foreach node in G, we add an edge from that node toone other random node (if the edge does not alreadyexist). On average, these edges will be much longerthan the nearest-neighbor edges.

4.1 Cost Analysis

The preprocessing phase of Algorithm 2 is identicalto the preprocessing phase of Algorithm 1, except

1. PCA is not performed.

2. Red-black trees are not constructed.

3. We add up to N random edges.

Adding the N random edges requires a single scanof the nodes in G, therefore our preprocessing timeis still O(N2d).

The term proportional to log N in the query time ofAlgorithm 1 resulted from querying the red-blacktrees. Algorithm 2 does not do this, so the querytime for Algorithm 2 is O(d).

5 Experiments

Because we do not have proofs about the relation-ships between b, c,m, ǫ, and δ, we ran extensive em-pirical tests of our algorithms.

5.1 Datasets

We tested our algorithms on several large high di-mensional data sets, both synthetic and real. Oursynthetic data consists of mixtures of multivariateGaussian distributions. Covariance matrices andmeans were generated randomly to produce thesedistributions. In particular, we considered unimodal,bimodal, pentamodal, and dodecamodal synthetic

distributions. Gaussian distributions were chosenboth because they often approximate distributionsfound in the wild, and because given a finite variance,the Gaussian distribution achieves the maximum en-tropy. We predicted that our algorithms would per-form best on data with fewer modes, so the highermodal1 distributions were selected to challenge ouralgorithms. In the case of the synthetic data, querypoints were drawn from the same distribution usedto create the data. All of the synthetic data sets were50-dimensional and contained 3000 points.

Real-world data was obtained from the UCI MachineLearning Repository (Asuncion and Newman, 2007).We used the ISOLET data set, which is audio dataof spoken letters of the alphebet, and the WaveformDatabase Generator dataset. The ISOLET data sethas 617 dimensions and more than 5000 points. Thewaveform data set has 22 dimensions and also morethan 5000 points. In the case of the real data, thedata sets were split into two parts, one for the initialset of points, and one from which to draw queries.

5.2 Parameters and Measurements

For each data set tested, the independent variableswere:

· b: The number of nearest neighbors each pointin P is connected to in G.

· c: The number of one-dimensional search struc-tures created in the case of Algorithm 1, or thenumber of guess points in the case of Algorithm2.

· m: The number of nodes (beyond k) in thegraph that are expanded.

· k: The number of nearest neighbors requested.

The variables measured were:

· Percent Correct: The percent of the points re-turned which are actually among the k nearestneighbors.

· Excess Rank: The actual rank (that is, the jof “jth-nearest neighbor”) of the worst point re-turned, minus k.

· Maximum Epsilon: If the actual ith nearestneighbor of a query point q has distance di

from q, and the ith approximate nearest neigh-bor has distance d′i from q, then Max Epsilon=

1With more extreme modality/modacitude, as it were.

12

Page 18: Class of 2008 Senior Conference on Computational Geometry

maxi (d′i/di − 1). Note that this is an upperbound on the ǫ from the definition of AkNN,if δ = 1.2

Based on preliminary experiments, the parameters b,c, m, and k were allowed to vary in the ranges below.

· b ∈ {0, 1, . . . , 10}

· c ∈ {1, 4, 16}

· m ∈ {0, 1, 10, 30, 60, 100, 150, 200, 250} inAlgorithm 2. For Algorithm 1, we ommitted200 and 250 because m had less of an impact.

· k ∈ {100}

We ran preliminary experiments using a variety ofvalues for k, but settled on k = 100. The relation-ships between parameters are easier to determine forlarger k, since the algorithms are identifying moreneighbors, and so setting k = 100 is more enlight-ening than looking at smaller values of k. For eachcombination of parameters, 50 queries were made,and the average value for each dependent variablewas recorded. An implementation of the naıve ex-act kNN algorithm determined the accuracy of theapproximate nearest neighbors. We ran experimentsusing the above parameters on all of our syntheticdata sets.

We tested how each parameter affected our perfor-mance metrics (Percent Correct, Maximum Epsilon,Excess Rank) when the other parameters were smalland fixed. We fixed two of c = 4, m = 10, b = 4,varying the third.

On the real-world data, we picked reasonable valuesfor all parameters and did not vary them. The chosenparameter values were c = 4, b = 4, m = 100, k =100.

In the results presented below, the graphs for Ex-cess Rank exactly followed the graphs for MaximumEpsilon, so we omit them.

6 Results

Unsurprisingly, b is an important parameter for bothalgorithms. Figure 2 shows that for Algorithm 1, ifc and m are small, b can easily pick up the slack.For b > 4, nearly all of the nearest neighbors areguessed correctly. As shown in Figure 3, for distribu-tions with few modes, using a large enough b ensures

2Further note that this is not generally how the ex-perimental ǫ is computed for AkNN.

Figure 2: Algorithm 1 on synthetic data sets with3000 points in 50 dimensions. For b > 4, nearly 100%of the nearest neighbors are correctly identified.

that Maximum Epsilon is close to zero. Unfortu-nately, when we run Algorithm 1 on distributionswith more modes, Maximum Epsilon is not as closeto zero.

As can be seen in Figure 4, Algorithm 2 scales withb in the same way as Algorithm 1 does. A highb guarantees a good maxEpsilon for the unimodaland bimodal cases, but the situation is worse for the5 and 12−modal cases. This is because incorrectneighbors were sometimes drawn from a Gaussian inthe mixture that was far away.

However, there is a difference in the Percent Correctachieved by our two algorithms as a function of b. Ascan be seen in Figure 5, while the general relationshipbetween Percent Correct and b on a single distribu-tion is the same for both algorithms, the distribu-tions that are easier for Algorithm 1 to handle arenot the distributions that are easier for Algorithm 2

to handle. While Algorithm 1 had a lower PercentCorrect on the 12-modal distribution, even for largerb, Algorithm 2 appears to behave in the oppositeway. For Algorithm 2, Percent Correct is highestfor the 12-modal distribution for pretty much all b.In all cases, a choice of b > 4 still guaranteed a highPercent Correct.

Increasing m improves Percent Correct and Max Ep-silon. However, over the ranges we tested, b hasmore of an impact than m on the performance ofAlgorithm 1. Figures 6 and 7 demonstrate this ef-fect nicely. As we have come to expect for Algorithm1, the 12-modal distribution produces the worst per-formance. Algorithm 2 benefits even more thanAlgorithm 1 from increased m. Figures 8 and 9

13

Page 19: Class of 2008 Senior Conference on Computational Geometry

Figure 3: Algorithm 1 on synthetic data sets with3000 points in 50 dimensions. For b > 4 and fordata sets with few modes, the points which are notcorrect are not far from the points which are correct.For data sets with many modes, this is less true.

Figure 4: Algorithm 2 on synthetic data sets with3000 points in 50 dimensions. For b > 4 and for datasets with few modes, the points that are not correctare not far from the correct points. For data setswith more modes, this is less ture.

Figure 5: Algorithm 2 on synthetic data sets with3000 points in 50 dimensions. For b > 4, nearly100% of the nearest neighbors are correctly identi-fied. Surprisingly, Algorithm 2 does better on morecomplicated distributions.

demonstrate that when we run Algorithm 2 withincreasing m on any of our synthetic data sets, Per-cent Correct rapidly approaches 1 and Max Epsilonrapidly approaches 0. The increased impact of mof Algorithm 2 makes sense because Algorithm 2

partly depends on a more extensive search to makeup for its random starting points.

For both algorithms, over the ranges that we tested,c had less of an impact on performance than m or b.In particular, the Percent Correct for Algorithm 2

was almost independent of c. It should be noted thatwhile c represents the number of initial points for thesearch in both algorithms, these points are obtainedin completely different ways. Thus, we do not gainmuch insight by comparing the effects on Algorithm

1 and Algorithm 2 of varying c. At some point,changing c would impact performance, but we arecontent to find a single reasonable value for c andfocus on the other more important parameters.

Due to time constraints, we did not test Algorithm2 on our real world data sets. However, Algorithm1 performed admirably, especially considering thelarge number of dimensions (617) in the ISOLETdata set. We have no reason to believe thatAlgorithm 2 would not be as good or better thanAlgorithm 1 on the real world data. Our experi-ments on synthetic data sets suggested that m = 100,b = 4 and c = 4 would be reasonable parameter set-tings that should work on any task. The results ofrunning Algorithm 1 with these parameters on allof our data sets are shown in Table 1. Algorithm

1 returned more than 90% of the correct k nearest

14

Page 20: Class of 2008 Senior Conference on Computational Geometry

Figure 6: Algorithm 1 on synthetic data sets with3000 points in 50 dimensions. As we would hope,Percent Correct increases with m.

Figure 7: Algorithm 1 on synthetic data sets with3000 points in 50 dimensions. m seems relativelyeffective for data sets with few modes. For data setswith many modes, this is less true.

PC ME ER1-Modal 0.919 0.009 9.832-Modal 0.970 0.005 3.225-Modal 0.992 0.002 0.8212-Modal 0.929 0.154 58.86ISOLET 0.922 0.042 33.93

Wave 0.952 0.009 5.55

Table 1: Average Percent Correct (PC), Max Epsilon(ME), and Excess Rank (ER) over 100 queries on realworld data (ISOLET and Wave) and over 50 querieson the synthetic data

Figure 8: Algorithm 2 on synthetic data sets with3000 points in 50 dimensions. As we would hope,Percent Correct increases with m, and more so thanin Figure 6.

Figure 9: Algorithm 2 on synthetic data sets with3000 points in 50 dimensions. m seems relativelyeffective for data sets with any number of modes.

15

Page 21: Class of 2008 Senior Conference on Computational Geometry

Figure 10: Both algorithms on the 12-modal syn-thetic data sets with 3000 points in 50 dimensions,along with a new algorithm Hobbled Algorithm 2.This algorithm is the same as Algorithm 2, exceptno random edges are added.

neighbors of the query points on each data set. As wehave come to expect, Algorithm 1 performed worseon the 12-modal data set. The ISOLET data set wasalso difficult, as presumably its intrinsic dimension-ality was much larger that the dimensionality of thesynthetic data.

6.1 Comparison of Algorithms

While Algorithm 2 may sacrifice quality in its ini-tial guesses when compared to Algorithm 1, it alsohas a more complete graph to search. Comparingthe performance of both algorithms on our syntheticdata sets, we found that Algorithm 2 tended to out-perform Algorithm 1 on the 12-modal set, and thatthere was no discernable pattern on the other sets.One might wonder whether or not using the one di-mensional search structures helped Algorithm 1 atall, or whether the additional random edges helpedAlgorithm 2. Figure 10 demonstrates that the an-swer to both questions is yes. While Algorithm

2 does slightly better than Algorithm 1, both domuch better than Hobbled Algorithm 2, which isthe same as Algorithm 2, except no random edgesare added.

7 Conclusions and Future Work

The adjustments we made to Algorithm 1 to obtainAlgorithm 2 suggest a third algorithm with O(Nd)preprocessing time and O(d) query time that mightbe interesting to try in future work. This algorithm,tentatively called Algorithm 3, would start with the

same linked list as Algorithms 1 and 2, add b ran-dom edges to each node, and process queries as inAlgorithm 2. Dispensing with the nearest neighboredges would give us the faster preprocessing time. Itwould be interesting to see how accurate Algorithm

3 would be.

We have presented two algorithms which, thoughO(N2d) in preprocessing cost, handle queries inO(d + logN) and O(d) time, respectively, with ex-perimentally good accuracy. As they are only lin-ear in d, our algorithms scale well to the high-dimensional problems common in machine learning.Furthermore, our algorithms do not appear to beoverly sensitive to parameter settings - choices of,say, m = 100, b = 4, and c = 4, seem to be suffi-cient to get good accuracy on all the data sets wetried. Our second, faster algorithm seems to do aswell or better than our first algorithm, and its per-formance seems depend even less on the data distri-bution. Since Algorithm 2 is faster and seems to bemore robust, it should be preferred in general. Ulti-mately, our second algorithm is an attractive choicefor solving Approximate K Nearest Neighbors

in high dimensions.

References

Alexandr Andoni and Piotr Indyk. 2008. Near-optimal hashing algorithms for approximate near-est neighbor in high dimensions. Commun. ACM,51(1):117–122.

Arya and Mount. 1993. Approximate nearest neigh-bor queries in fixed dimensions. In SODA: ACM-SIAM Symposium on Discrete Algorithms (A Con-ference on Theoretical and Experimental Analysis ofDiscrete Algorithms).

Sunil Arya, David M. Mount, Nathan S. Netanyahu,Ruth Silverman, and Angela Wu. 1994. An op-timal algorithm for approximate nearest neighborsearching. In SODA ’94: Proceedings of the fifth an-nual ACM-SIAM symposium on Discrete algorithms,pages 573–582, Philadelphia, PA, USA.

A. Asuncion and D.J. Newman. 2007. UCI machinelearning repository.

Norbert Beckmann, Hans-Peter Kriegel, Ralf Schnei-der, and Bernhard Seeger. 1990. The r*-tree: an ef-ficient and robust access method for points and rect-angles. SIGMOD Rec., 19(2):322–331.

Stefan Berchtold, Daniel A. Keim, and Hans-PeterKriegel. 1996. The X-tree: An index structurefor high-dimensional data. In T. M. Vijayaraman,

16

Page 22: Class of 2008 Senior Conference on Computational Geometry

Alejandro P. Buchmann, C. Mohan, and Nandlal L.Sarda, editors, Proceedings of the 22nd InternationalConference on Very Large Databases, pages 28–39,San Francisco, U.S.A. Morgan Kaufmann Publish-ers.

A. R. Butz. 1971. Alternative algorithm for hilbert’sspace-filling curve. IEEE Trans. Computers, C-20:424–426.

Aristides Gionis, Piotr Indyk, and Rajeev Motwani.1999. Similarity search in high dimensions via hash-ing. In VLDB ’99: Proceedings of the 25th Interna-tional Conference on Very Large Data Bases, pages518–529, San Francisco, CA, USA. Morgan Kauf-mann Publishers Inc.

Jaffer. 2008a. The SLIB Portable SCHEME Li-brary, available at http://swissnet.ai.mit.edu/ jaf-fer/SLIB.html.

Aubrey Jaffer. 2008b. Personal Communication.

H. V. Jagadish. 1990. Linear clustering of objectswith multiple attributes. SIGMOD Rec., 19(2):332–342.

Jon M. Kleinberg. 1997. Two algorithms for nearest-neighbor search in high dimensions. In Proceedingsof the Fifth Annual ACM-SIAM Symposium on Dis-crete Algorithms, pages 599–608.

T. Liu, A. Moore, A. Gray, and K. Yang. 2004. Aninvestigation of practical approximate nearest neigh-bor algorithms.

17

Page 23: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 18–21,Computer Science Department, Swarthmore College

The Road Not Taken: Creating a Path-Finding Tool Using Consumer-GradeGPS Equipment

Allison [email protected]

Lucas [email protected]

Abstract

We automate the organization of GPS datato create a visibility map with correctlyconnected intersections. For our exam-ple case study, we use GPS data collectedon the Swarthmore College campus. Af-ter the data is automatically organized andcleaned, a user is able to select points ona visual map to search for an optimal pathbetween those points.

1 The Problem of Navigation

Swarthmore College, set in the beautiful Scott Ar-boretum, has many scenic routes and winding pathsbetween the lovely stone buildings. This serene set-ting is wonderful for long walks, but can be trou-blesome in trying to navigate from one’s dorm to aclassroom when one is half-awake and running be-hind schedule. In order to assist the poor, sleep-deprived students of Swarthmore College, we cre-ate an interactive map of the campus to help usersdiscover the appropriate paths between the variousbuildings on campus. In doing so, we develop aset of tools that can easily create similar systems fordata collected in other locations.

1.1 Previous Work

Another group worked on a GPS path-planningproject for last year’s Senior Conference (Singletonand Woods, 2007). Because their data required quitea bit of manual editing, their system would not eas-ily scale to larger data sets. We also noticed that

their interface was difficult to understand immedi-ately. Taking these challenges into account, we cre-ate a scalable, user-friendly path planning tool.

We used a large amount of previous researchto build our tools. Most notably, Dijkstra’s algo-rithm (Dijkstra, 1959; de Berg et al., 1997) andthe more general A* search algorithm (Hart et al.,1968) have been developed to find appropriate pathsthrough our spatial graph. We also implement animproved version of the Douglas-Peucker line sim-plification algorithm (Hart et al., 1968).

1.2 Approaches to Path Planning

Path planning is essentially a least-cost graphsearching problem, a task for which several algorith-mic variations have been developed. In the past, Di-jkstra’s algorithm has been widely used for this task,but we implement the A* search algorithm, which isa generalization of Dijkstra’s approach that is bothcomplete and optimally efficient. In typical situa-tions, A* performs slightly faster than Dijkstra’s al-gorithm because it uses a heuristic to help decidewhich search paths are most promising. This processminimizes the size of the subgraph to be explored.

2 Implementation

This project consists of three main parts: data collec-tion and processing, path planning, and UI develop-ment. The first two parts center on problem solvingusing computational geometry while the third pro-vides easy access to the results.

18

Page 24: Class of 2008 Senior Conference on Computational Geometry

2.1 Data Collection and Processing

We use self-collected GPS data for our finished map-ping system. Swarthmore College kindly providedtheir survey plans for use with this project, but dueto a lack of time, we were not able to complete anintegration of this data into our user interface. Weprioritized our work with the GPS data, even thoughthat data is not as precise, because we wanted oursystem to be useful in creating mapping systems inother situations where no such detailed survey planshave been prepared.

2.1.1 GPS Data Collection

Our main dataset is GPS tracking data recordedby walking the paths of Swarthmore’s campuswith a consumer-grade GPS receiver, the GarminGPSmap 60CSx. For consistency, we carried theGPS receiver at about waist-height and walked onthe center of each footpath, recording tracks ofwhere we had walked and marking a waypoint eachtime we encountered a path intersection. We usedGPSBabel to transfer data from the Garmin unit tothe GPX format, an XML-based file format that in-cludes latitude, longitude, elevation, and timestampdata. We collected GPS data for virtually all exteriorpaved footpaths on the Swarthmore campus; in con-trast to last year’s project, we did not record indoorfootpaths because of the inability to collect GPS dataindoors with inexpensive equipment and our desireto avoid manual editing of the collected data (Sin-gleton and Woods, 2007).

2.1.2 GPS Data Processing

Our pre-processing algorithms find clusters ofpaths with geographically nearby endpoints. We as-sume that these paths intersect at a common point, sowe reassign the endpoint coordinates of all paths in acluster to the arithmetic mean of the endpoint coor-dinates in that cluster. While this approach is fairlynaive, we found that it works quite well in prac-tice with the relatively coarse resolution captured byconsumer-grade GPS equipment.

We experimented with simplifying the data as afinal processing step, hoping to reduce the computa-tional power needed for both the user interface dis-play and our path-finding algorithms. We use theDouglas-Peucker line simplification algorithm to doso. This, however, was not particularly helpful for

this particular application in part because of the rela-tively infrequent position sampling provided by ourequipment. Also, we constructed our search graphon adjacent path intersections, ignoring the com-plexity of the path segment between those intersec-tions, which is an even more efficient simplificationfor searching purposes. It is important, however, toexplore the practicability of such simplification tech-niques for use with larger, higher-precision datasets.

At the end of these pre-processing steps, the re-sulting data is saved as latitude, longitude, and ele-vation tuples for each meaningful point of each pathsegment. Figure 1 shows a clear difference betweenour raw data and the same data after being processedwith our programs.

Figure 1: Before and after data processing cleanupon a subset of our GPS data

Figure 2: GIS overlay of our GPS data and the sur-vey drawings

2.1.3 CAD Survey Drawings

Thanks to the maintenance staff at SwarthmoreCollege, we also acquired survey-grade mappingdata for the Swarthmore campus in AutoCAD for-mat. We convert the several layers of data from these

19

Page 25: Class of 2008 Senior Conference on Computational Geometry

drawings to the Shapefile format and simplify thedata using the Douglas-Peucker algorithm. The fi-nal output data uses the same simplified data formatdescribed at the end of our GPS data pre-processingalgorithms. We had hoped to use information fromthese drawings as a base layer to help orient usersto the paths as displayed in our user interface, butran out of time before we could complete that ef-fort. Figure 2, however, shows an overlay of thesedatasets that has been prepared with a GIS package.

2.2 Path Planning

Path planning using the A* search algorithm is fairlystraightforward. We create a graph of the connec-tions between path intersections; each edge in thesearch graph is weighted with the path distance be-tween its endpoint vertices. Then, we apply thesearch algorithm to this graph, finding the shortestpath between the two selected nodes.

A* uses a heuristic function: the sum of distanceto get to the current node plus the cost to get to thenext node. Using this function, A* chooses whichnodes to visit based on the routes that appear to beshortest. The partial paths it has explored are storedin a priority queue, and when its cheapest path be-comes relatively expensive, other potentially shorterpaths are explored. When a path is found to reachthe goal with a lower heuristic value than any other(partial) path in the queue, A* has found the shortestpath. A* is both complete and optimal, making it anobvious choice for path finding.

We choose to implement the A* search algo-rithm because its implementation is not significantlymore difficult than implementing Dijkstra’s algo-rithm. Given this, the heuristic in A* provides aslight performance improvement in typical situa-tions.

2.3 UI Development

We provide a python program for visualizing thepaths in our search space and the optimized paths be-tween selected points. Search endpoints are selectedsimply by clicking on intersections in our searchgraph, and the optimal path between those points isthen highlighted on the map. A screenshot of this in-terface is provided in Figure 3, where the first pointselected is green, the second point selected is red,and the shortest path between them is shown in blue.

Figure 3: Screenshot of our UI with a path selected

20

Page 26: Class of 2008 Senior Conference on Computational Geometry

We did not have time to complete further UI de-velopment work, although this was not the largestfocus of our project. The UI would be even more in-tuitive, however, if the paths were overlaid on a mapthat shows other landmarks, such as buildings.

3 Results & Conclusions

Our system appears to be robust and to provide ac-curate results for a user’s queries. The interface canbe quickly and simply explained, but is not yet intu-itive enough to be used by most individuals withouta brief explanation.

We are quite happy with the way that our systemmeets the goals set out at the beginning, especiallywith regards to scalability. For example, we devel-oped our processing routines with a subset of ourcollected GPS data, then were able to add the re-mainder of our data with less than five minutes ofadditional work. We are confident that our systemwould scale well even to much larger datasets thanthe ones used in this project, and that this representsa good approach to developing such path-findingsystems much more quickly and cheaply than hasbeen previously possible.

References

M. de Berg, M. van Kreveld, M. Overmars, andO. Schwarzkopf. 1997.Computational Geometry: Al-gorithms and Applications. Springer.

E. W. Dijkstra. 1959. A Note on Two Problems in Con-nexion with Graphs.

P. E. Hart, N. J. Nilsson, and B. Raphael. 1968. A For-mal Basis for the Heuristic Determination of MinimumCost Paths.

Matt Singleton and Bronwyn Woods. 2007. FindingYour Inner Blaha: GPS Mapping of the SwarthmoreCampus.

21

Page 27: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 22–27,Computer Science Department, Swarthmore College

Drawing Isoglosses Algorithmically

Bryce [email protected]

Kit La [email protected]

Abstract

In this paper, we apply algorithms fordefining regions from sets of points to theproblem of drawing isoglosses, the bound-aries between dialect regions. We discussthe justifications for our method, and al-ternative models that could be constructedfrom this data. We evaluate the resultantmodel by comparison to the traditionalmethod of drawing isoglosses, by hand.

1 Introduction

In the linguistic subfield of dialectology, an impor-tant activity is the drawing of isoglosses, or bound-aries between dialect areas. It is often difficult to pindown the meaning of these terms, as within a regionpeople come and go, and bring their speech withthem, but broadly speaking, an isogloss is a bound-ary between where people speak like this and wherepeople speak like that. Typically, an isogloss willnot be a sharp line, but will be an area of overlapbetween speakers of one type and the other.

Unfortunately, isoglosses are typically drawn byhand, as an approximate dividing line. This leads totwo problems: one, they should not be thought of orrepresented as lines, but rather as approximate tran-sition zones, and two, they could be better drawn,we think, by algorithm than by eyeballing. As thenoted sociolinguist William Labov writes,

Every dialect geographer yearns for anautomatic method for drawing dialectboundaries which would insulate this pro-cedure from the preconceived notions ofthe analyst. No satisfactory program hasyet been written. (Labov et al., 2005)

We have therefore attempted, as something like aproof-of-concept, to redraw the isoglosses for cer-tain dialect differences in American English. We

have taken as our data the results of the telephonesurvey of speakers across the contiguous USA donefor the Atlas of North American English (Labov etal., 2005). To this data, we have applied a numberof algorithms from the field of computational geom-etry, and hope that the result will better represent theboundaries between dialect regions.

One way we expect that our method will improveon a hand-drawn line is by clearly showing areasthat are thoroughly mixed. It can be tempting, whendrawing by hand, to mark an area as primarily speak-ing one way, and drawing your line as though thatis the case. It may well be the case, however, thatin such situations, the region is much more evenlymixed than it appears to the eye, and should proba-bly not be marked decidedly in either direction. Wesuspect that an algorithmic approach will see thesecases more clearly.

The clearest way to test whether our method im-proves on a hand-drawn line would be to see if thismodel has greater predictive power, such that if wewere to randomly make telephone calls to people,their proximity to our lines would be a better indica-tor of the features of their dialect. However, doingso is outside the scope of the project. Other changesto our method that would make it more explicitlya predictive model, such as predicting the value fora point based on the inverse-distance weighted av-erage of the n-nearest neighbors,1 while interest-ing, would also be outside the scope of this project.Such an approach would really be a machine learn-ing task, and not a cartographic task.

As such, our evaluation is limited to observingin a qualitative way the differences between ourmethod and the hand-drawn method. We expectthat if there is no significant difference, this will atleast provide a way of automating the creation ofa machine-readable form, assuming data points areavailable. If there is a significant difference, then

1As suggested by George Dahl.

22

Page 28: Class of 2008 Senior Conference on Computational Geometry

perhaps more investigation into the predictive pow-ers of the two models is warranted.

2 The data

The data from the Atlas of North American En-glish (Labov et al., 2005) is in the form of approxi-mately 600 points, identified geographically by ZIPcode, which we then converted to latitude and lon-gitude coordinates. At each point, there was an in-dication of whether the speaker at that point makesor does not make each of a set of possible linguisticdistinctions. The data is generally denser around thenorth east and Great Lakes regions, but this is in partdue to greater population density in these areas. Ofcourse, more datapoints would always be desirable,but these data are still useful.

A dialect area can be considered an area of over-lap between polygons from different feature sets,where the area of overlap consists of most of the areaof the parent polygons. Thus, it is an area where,at least with respect to the features under consid-eration, people speak the same way, and that wayis distinct from the surrounding area. The scale ofthis can vary, of course: a city may form a distinctdialect area within a state, if it has sufficiently dif-ferent speech, but there may also be dialect areaswithin that city, which are each more like each otherthan they are like the speech outside the city, but stilldiffer from each other.

The specific features which we mapped were thefollowing: whether the speaker distinguishes A andO, whether the speaker distinguishes û and w, andwhether the speaker distinguishes I and E before anasal, such as n or m.2 These are a set of easily ex-plicable features, with the first and third being gen-erally considered to be characteristic of large USdialects. For each feature, following the format inthe Atlas, a speaker could make the distinction, notmake the distinction, or be unclear — that is, theinterviewer was unable to tell whether they reliablymade or did not make the distinction. In all cases,we used the interviewer’s judgment, rather than thespeaker’s self-reporting.

The scale of our project is across the contigu-ous USA, so many smaller-scale regional variationsdon’t show up. This is dependent on a number of

2These symbols are explained in Section 7.

parameters in the algorithm, and the size and gran-ularity of the dataset. For example the data set andour techniques might allow us to note the speech ofwestern Pennsylvania and West Virginia as distinctfrom the area around it, but would not create a dis-tinct region for the dialect of San Francisco and itscountryside.

3 Methods

Our goal of identifying dialect regions based on in-dividual phoneme information required us to first lo-cate areas where speakers pronounced a phonemesimilarly. For most phonemic variables in the Atlasof North American English, the speakers with sim-ilar pronounciation are not located all in one area.This meant that for each feature setting, we had tofirst break the data points up into several regionalgroupings, which we did using k-means clustering.Once we had clustered the data for a particular fea-ture setting we found boundaries for the resultingregions by computing the convex hulls of the datapoints in each cluster. This gave us several polygonsdescribing regions in which a particular feature hadthe same setting, so to find dialect regions we over-laid these polygon sets and found regions of inter-section. Each of these three steps is described indetail below.

3.1 Clustering

To break the data points from a data set for a par-ticular feature setting down into smaller groups, weused k-means, a clustering algorithm proposed byMacQueen (1967). The algorithm starts with k cen-troids that can be specified as input or randomly se-lected from the data points. Each data point is thenassigned to the nearest centroid, and each centroid isadjusted to minimize the distance to all of its points.Then the data points are again assigned to the clos-est centroid, and the centroids are recomputed, andso on. The algorithm terminates when an iterationoccurs in which no data points switched centroids.The theoretical worst-case time complexity of thek-means algorithm is superpolynomial (Arthur andVassilvitskii, 2006), but in practice it runs quitequickly.

We considered a number of alternative cluster-ing algorithms including faster heuristic-based or

23

Page 29: Class of 2008 Senior Conference on Computational Geometry

approximate k-means implementations. We alsoconsidered other more adaptive clustering algo-rithms, like growing k-means or growing neuralgas (Daszykowski et al., 2002). The main advantageto such techniques is that they would not require thenumber of clusters to be specified in advance, butinstead start with very few centroids and add moreas needed. We decided against such methods afterconsidering the potential applications of our work.First, if a user of our algorithm, say a linguist creat-ing dialect maps, is unfamiliar with the details of theimplementation, it might be easier for him to spec-ify starting-point centroids than to tune the param-eters that control the termination point of growingk-means or growing neural gas. Additionally, be-cause our data come from an atlas with hand-drawnisoglosses, we have available to us reasonably goodstarting-point centroids to use in our testing.

3.2 Convex Hulls

After forming clusters, we computed the convex hullof each set of clustered points, using a simple convexhull algorithm, the Jarvis March. The algorithm usesa “gift-wrapping” technique, starting from the left-most point in the data set, and at each subusequentstep, scanning through all the remaining points tofind the one that makes the widest angle with the pre-vious hull boundary-segment. This runs in in O(nh)time, because each of h loops scans all of the inputpoints (de Berg et al., 1997). Non output-sensitive,O(n log n), convex hull algorithms also exist and areuseful when h is close to n, resulting in n2 complex-ity for Jarvis, but in our application, h tends to bequite small relative to h, so the Jarvis March per-forms marginally better.

When inspecting the first applications of ourconvex-hull implementation to real data, we noticedthat the hulls were often significantly affected by afew outlier points that weren’t particularly close toany of the cluster centroids but our implementationof k-means required that they be assigned to somecluster. For example one data set had three clearclusters in the northeast, the midwest, and the deepsouth, plus a few extraneous data points in Califor-nia. These California points caused the midwest-hull to stretch halfway across the country (see figure1).

To fix this, we tried two different methods. The

Figure 1: Convex hulls of point clusters for regionswhere A and O are distinguished, without oulier re-moval.

first was onion-peeling of the convex hulls, 3 whichwould involve throwing out the points on the con-vex hull and recomputing the convex hull of the re-maining points (perhaps more than once). We foundthis method ineffective because removing all out-liers would sometimes require more than one onion-peeling step, in which case some more-compactclusters would be whittled away and no longer ac-curately represent the data. We then tried, and weresatisfied with, calculating the outliers more explic-itly. For each cluster, we computed the standard de-viation of the distance from each point to the cen-troid and removed all points more than some num-ber of standard deviations4 away before computingthe convex hull.

3.3 Overlay

Finally, given the hulls for each cluster in a particu-lar map, we overlaid them to find the common areabetween, for example, the speakers who both makethe A/O distinction, and drop syllable-final r. Byoverlaying hulls from different features, we couldidentify regions of significant overlap, indicating di-alect regions, and by overlaying hulls from differentsettings of the same feature, we can determine bor-der areas where common sets of linguistic featurescannot be readily described.

3Suggested by Andrew Danner.4We found that 3 standard deviations produced good results.

24

Page 30: Class of 2008 Senior Conference on Computational Geometry

Overlaying these regions requires first detectingwhether two polygons intersect. A method to dothis in O(log n) time was proposed by Chazelle andDobkin (1980), but is exceedingly difficult to imple-ment, so we opted instead for an O(n2) algorithmbased on the leftTurn and rightTurn primitives wehad already implemented for computing the inter-section. The idea is that if two polygons don’t inter-sect, then there exists a dividing line between them,and one such line must be a side of one of the poly-gons. Therefore we can walk around the outside ofone polygon and determine for each side, whetherall points in the other polygon lie on the oppositeside of that line from the rest of its polygon. If so,the polyogns don’t intersect; if no such line is foundafter walking around both polygons, then the poly-gons intersect.

Once we know that two polygons intersect, weuse a rotating calipers implementation provided byMary Wooters and George Dahl to compute bridgepoints between them (Toussaint, 1983). Each ofthese bridge points corresponds to a point of inter-section between the two hulls at the other end of the“sail polygon” (see figure 2), which we locate us-ing the stepDown procedure outlined in Toussaint(1985). Once we have located these intersectionpoints, finding the convex intersection of the twopolygons is simply a matter of walking around onepolygon and then the other, switching at each inter-section point. Both rotating calipers and stepDownrun in time linear in the size of the polygons, as doesthe final output step, so the whole overlay step runsin worst-case O(k2 ∗ h) time, where k is the num-ber of k-means centroids (and therefore the numberof polygons), and h is the number of points on thepolyogns being combined. In practice, k and h arewell under n

13 , so this works out to be no worse than

linear in the size of the overall data set.To visualize the data, we used GRASS,5 mapping

our datapoints to latitude and longitude coordinates.

4 Results

The regions drawn by this method seem plausiblegiven our knowledge of the data sets we used. How-ever, a rigorous test of the predictive power of this

5GRASS is an Open Source geographic information system,available at http://grass.osgeo.org/.

Figure 2: The stepDown function iterates over a“sail polygon” to find the intersection between twopolygons given a bridge-line between them.

model is not particularly feasible without more data.One major difference is that this method produces

only convex polygons as dialect regions, and alsodoes not cover all the inhabited territory on the map.Both of these facts imply something about how ourregions are to be interpreted: for a given feature, theregions of no overlap with other settings for that fea-ture are areas of high-confidence that there is onedialect, areas of overlap are areas of confidence thatthe speech is mixed there, and areas outside of poly-gons are areas of insufficient data.

There were some moments when it was clear howto hand-evaluate the algorithm. For example, be-fore switching to standard-deviation hulls, we at-tempted onion-skin hulls. This resulted in a hull thatstretched across the US from Wisconsin to south-ern California, even after peeling off the first layer.This was clearly an artifact of the processing, andnot reflective of a here-to-fore unobserved swath ofspeakers who distinguish A and O; the greater part ofthe polygon, as it stretched across the country, wasdevoid of datapoints, having them all clustered at theWisconsin end.

5 Future Work

The clearest route for future work would be to de-velop a metric with which to test the quality of adialect map. The purpose of such a map is presum-ably as a predictive tool; as such, gathering largeramounts of data, for distinct training and testing,

25

Page 31: Class of 2008 Senior Conference on Computational Geometry

Figure 3: Overlaid convex hulls of clustered data. The red are areas where A and O are merged. The blue areareas where I and E are merged before nasals.

would be ideal. However, collecting such data re-mains time-consuming and difficult.

It has been suggested that an alternative approachto this problem would be to treat it as a machinelearning task. One could imagine easily a learn-ing system that would, given training data of geo-graphic points classed by setting of linguistic fea-tures, would produce the likeliest settings for lin-guistic features, given testing data of just geographicpoints. While such a system would be interesting,and possibly very informative, it would not lend it-self immediately to map-making, and was outsidethe scope of this project.

6 Conclusions

It is difficult to evaluate the success of our algorithmboth because the Atlas is not conducive to a quanti-

tative comparison, and because testing our algorithmagainst real-world data is impractical. The algorithmseems to produce reasonable results, but a large partof our ability to evaluate this is based, circularly, onthe maps available in the Atlas. Clearly, both moredata and a better means of evaluation would be de-sirable.

7 Linguistic Appendix

A number of phonetic symbols have been used inthis paper. As familiarity with them is not assumed,we will explain them here.

• A: for those that distinguish this from the fol-lowing vowel, it is the vowel in tot.

• O: for those that distinguish this from the pre-ceding vowel, it is the vowel in taught.

26

Page 32: Class of 2008 Senior Conference on Computational Geometry

• w: this is the first consonant of witch.

• û: this is the first consonant of which, thoughmany speakers do not use this, instead mergingwith w, above.

• I: as in pin.

• E: as in pen. Some US dialects do not distin-guish I and E before nasal consonants, such asn or m.

These features were selected because they wereavailable in the Atlas, and easily explicable. A thor-ough effort to algorithmically create dialect mapswould use many more features.

ReferencesDavid Arthur and Sergei Vassilvitskii. 2006. How slow

is the k-means method? In SCG ’06: Proceedingsof the twenty-second annual symposium on Computa-tional geometry, pages 144–153, New York, NY, USA.ACM.

Bernard Chazelle and David P. Dobkin. 1980. Detec-tion is easier than computation (extended abstract). InSTOC ’80: Proceedings of the twelfth annual ACMsymposium on Theory of computing, pages 146–153,New York, NY, USA. ACM.

M. Daszykowski, B. Walczak, and D. L. Massart. 2002.On the optimal partioning of data with k-means,growing k-means, neural gas and growing neuralgas. Journal of Chemical Information and Modelling,42(6):1378–1389.

Mark de Berg, Marc van Kreveld, Mark Overmas, andOtfried Schwartzkopf. 1997. Computational Geome-try. Springer.

William Labov, Sharon Ash, and Charles Boberg. 2005.The Atlas of North American English. Mouton deGruyter.

J. B. MacQueen. 1967. Some methods for classificationand analysis of multivariate observations. In L. M. LeCam and J. Neyman, editors, Proc. of the fifth BerkeleySymposium on Mathematical Statistics and Probabil-ity, volume 1, pages 281–297. University of CaliforniaPress.

Godfried Toussaint. 1983. Solving geometric problemswith the rotating calipers.

Godfried T. Toussaint. 1985. A simple linear algorithmfor intersecting convex polygons. The Visual Com-puter, 1(2):118–123.

27

Page 33: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 28–37,Computer Science Department, Swarthmore College

The Largest Empty Circle Problem

Megan [email protected]

Abstract

The largest empty circle (LEC) problem isdefined on a set P and consists of findingthe largest circle that contains no points inP and is also centered inside the convexhull of P . The LEC is always centered ateither a vertex on the Voronoi diagram forP or on an intersection between a Voronoiedge and the convex hull of P . Thus,finding the LEC consists of constructinga Voronoi diagram and convex hull for P ,then searching the Voronoi vertices andintersections between Voronoi edges andconvex hull edges to see where the LEClies. This paper presents a simple O(n[h+log n]) solution to the largest empty circleproblem. Though previous work on thisproblem has found O(n log n) solutions,we find that for data sets which are some-what normally distributed, h is small andour simple algorithm performs well.

1 Introduction

The Largest Empty Circle (LEC) problem is definedon a set of points P and consists of locating thelargest circle that contains no points of P and is cen-tered inside the convex hull of P . Less formally, thisproblem finds the point q bounded by the convex hullwhich maximizes the distance to its nearest neighborp ∈ P ; this point is the center of the largest emptycircle. We constrain q to lie within the convex hullof P because otherwise we would simply choose thepoint at infinity as the center of the LEC.

This problem is sometimes referred to as theToxic Waste Dump problem, because given the co-ordinates for a set of cities, the LEC problem wouldallow you to find the best site for a toxic wastedump by finding the location which is maximally far

from every city. This might also be useful for plan-ning locations for new stores. For example, imag-ine you would like to build a new McDonald’s ina metropolitan ares that already has several dozenMcDonald’s stores. By computing the LEC on theset of existing McDonald’s restaurants, you couldselect a site for a new store which is maximallyfar from all existing stores to minimize competitionwith other McDonald’s restaurants and situate your-self near people who previously did not have a Mc-Donald’s nearby.

The Voronoi diagram for the set P is a useful toolfor solving the LEC problem. The Voronoi diagramis a partition of the plane into convex faces suchthat given a set of points P , each face (hereafter,Voronoi cell) contains exactly one point p ∈ P andall points in the plane which are closer to p than toany other point in P . Points lying on the edges be-tween Voronoi cells are equidistant between the twopoints contained in the cells lying to either side ofthe edge. Given these properties, it seems intuitivethat the largest empty circle should be centered on aVoronoi vertex. Since the edges represent all pointswhich are equidistant to the two points they divide,it follows that a vertex, which is simply an intersec-tion between multiple Voronoi edges, would max-imizes the minimum distance to all nearby points.Any point that is not on a Voronoi vertex must becloser to one point than any other and as such anyempty circle we can draw around it will not be ofmaximal size.

Based on the above principles, it seems that wemight simply be able to draw empty circles aroundall Voronoi vertices and see which is the largest.However, since we constrain our circle to be cen-tered inside the convex hull of P , we must beslightly more careful in our search for the LEC.First, we must consider only Voronoi vertices whichlie inside the convex hull of P . Second, we mustconsider what happens on the edges of the convex

28

Page 34: Class of 2008 Senior Conference on Computational Geometry

hull itself. At points where a Voronoi edge inter-sects a convex hull edge, the distances between eachof the two nearest points is maximized, since we areon a Voronoi edge. Such points must also be consid-ered as candidates for the center of the LEC.

2 Related Work

The earliest solution to the LEC problem waspresented by Shamos in his Ph.D. thesis (1978).Shamos presented an algorithm that, given theVoronoi diagram and the convex hull, could find thelargest empty circle in O(n) time. Unfortunately,this algorithm was based on the assumption that ev-ery convex hull edge is intersected by at most twoVoronoi edges, which is not always true, as latershown by Toussaint (1983). Because the originalShamos algorithm incorrectly assumes a maximumof two Voronoi edge intersections at each convexhull edge, it can miss intersections at edges withmore than two intersections with Voronoi edges and,as such, can fail to recognize the true LEC.

Toussaint (1983) went on to present an algorithmwhich correctly finds the LEC in all cases. However,the Toussaint algorithm requires O(n log n) runningtime when given the convex hull and Voronoi di-agram. The algorithm first computes the largestempty circle about each Voronoi vertex which liesin the interior of the convex hull. This step requiresO(n log h) operations; there are O(n) Voronoi ver-tices for which we must do an O(log h) point loca-tion step to check for interiority to the convex hull(where h is the number of convex hull edges), andcomputing the largest empty circle about a point canbe done in constant time. Once all interior pointshave been considered, the algorithm computes all in-tersections between Voronoi edges and convex hulledges. Toussaint uses an O(log n) algorithm takenfrom Chazelle (1980) to find the intersections be-tween a line segment and a convex n-gon. Sincethere are O(n) Voronoi edges (de Berg et al., 2000),this step requires O(n log h) time overall. By check-ing all points interior to the convex hull and all in-tersection points between the Voronoi diagram andthe convex hull, all possible sites for the center ofthe LEC have been considered. All that remains isto report the point about which the largest circle wasdrawn. Toussaint thus finds the LEC in O(n log n)

time.Later, Preparata and Shamos (1985) offer an im-

proved version of Shamos’s original methods (1978)which no longer relies on the assumption that eachconvex hull edge is intersected by at most twoVoronoi edges. Preparata and Shamos describe anO(n) marching method for finding all intersectionsbetween the Voronoi edges and the convex hull,which is an improvement on Toussaint’s O(n log h)method. Preparata and Shamos do not go into detailabout how to check Voronoi vertices on the interiorof the convex hull to see if they might be the cen-ter of the largest empty circle. We can only assumethat they, like Toussaint, also require an O(n log h)technique for checking interior points. This solutionis then slightly faster than Toussaint’s, thanks to theO(n) intersection location step.

Still, all of the LEC-finding algorithms discussedabove require use of the Voronoi diagram andthe convex hull. Both of these structures requireO(n log n) steps to compute. Construction of thesestructures dominates the computation time whenfinding the LEC, so while there may be some quib-bling about the fastest methods for finding intersec-tions between Voronoi diagrams and convex hulls,overall the solution to the LEC problem is at bestO(n log n) regardless of the steps required to actu-ally find the largest empty circle.

In this paper, we present a complete method forfinding the LEC, borrowing our approach to theproblem from the previous work of Toussaint. Thealgorithm presented includes a computation of theVoronoi diagram and the convex hull and requiresO(n[h + log n]) running time.

3 Methods

3.1 Computing the Voronoi Diagram andConvex Hull

Before we can find the largest empty circle for aset of points P , we must first construct the Voronoidiagram (V or(P )) and convex hull (CH(P )) forthe set of points. Here, V or(P ) is computed byfirst finding the Delaunay triangulation, DT (P ),which is the dual of V or(P ). Common algorithmsfor computing V or(P ) involve an O(n log n) planesweep and are not dynamically updateable. How-ever, de Berg et al. (2000) describe an incremen-

29

Page 35: Class of 2008 Senior Conference on Computational Geometry

Figure 1: A simple example of the Delaunay triangulationcomputed on a small set of points.

tal algorithm for computing DT (P ). Because wewould like to support dynamic updates to V or(P ),we choose to compute V or(P ) by dualization of adynamically updateable implementation of DT (P ).

3.1.1 The Delaunay Triangulation

de Berg et. al (2000) describe an incrementalalgorithm for computing Delaunay triangulations,which we employ here to compute DT (P ). The De-launay triangulation is a special type of triangulationwhich maximizes the minimum angle found in anytriangle in the triangulation. An example is shownin Figure 1.

We begin with a very large bounding triangle andadd points from P to it one at a time. When addinga point p, we check the current triangulation and lo-cate the triangle T which contains p. We then drawedges between p and each of the vertices of T tore-triangulate the set P . In doing so, however, wemay have introduced new triangles with small an-gles such that we no longer have a Delaunay triangu-lation. Thus, as we re-triangulate with every addedpoint, we must check the edges of new triangles in-troduced to see whether they form any small angles.We flip such edges as needed to the opposite cornersof the quadrilateral which contains them, recursingon triangles in the neighborhood of newly flippededges until we have ensured again that the smallestangle in the triangulation is as large as possible.

We represent triangles as nodes in a directedacyclic graph. Whenever a triangle is divided byinsertion of a new point or changed due to edge-

Figure 2: The circumcircle for a triangle T , whose center v isfound by perpendicular bisector construction. If T is a trianglein a Delaunay triangulation, the v is the Voronoi vertex obtainedwhen dualizing the Delaunay triangulation to the Voronoi dia-gram.

flipping, it sets pointers to the new triangles whichresult from these changes. Each triangle node alsomaintains a pointer for each of its three edges indi-cating which other triangle neighbors it along thatedge, with care being taken to update these neighborpointers as new triangles are introduced and edgeflips are performed. These neighbor pointers are cru-cial to our ability to dualize DT (P ) to V or(P ).

For full details on the computation of Delaunaytriangulations, see see de Berg et al. (2000). Oncewe have a Delaunay triangulation in place, we candualize it to give the desired Voronoi diagram.

3.1.2 The Voronoi DiagramOnce DT (P ) has been computed, it is fairly

straightforward to dualize it to V or(P ). The dualitybetween the Voronoi diagram and the Delaunay tri-angulation is such that every triangle in DT (P ) cor-responds to a vertex in V or(P ). Triangles which areneighbors in DT (P ) have their vertices connectedby an edge in the V or(P ) dual space (de Berg et al.,2000).

The coordinates of the Voronoi vertex which cor-respond to a triangle T ∈ DT (P ) can be found bylocating the center of the circle which circumscribesT (Okabe et al., 2000). To compute the circumcir-cle, we use the perpendicular bisector constructionas in Figure 2; the circumcircle for a triangle is cen-tered at the point at which the perpendicular bisec-tors for the triangle’s edges all intersect. To computeV or(P ) from DT (P ), then, we first iterate over alltriangles in DT (P ), computing the circumcircle tofind the dual vertex in V or(P ).

Once all Voronoi vertices have been found, we

30

Page 36: Class of 2008 Senior Conference on Computational Geometry

Figure 3: A simple example of the Voronoi diagram and con-vex hull computed on the set of points shown in Figure 1.

connect them to one another by again iterating overthe triangles of DT (P ). Here, we make use of theneighbor pointers stored in our Delaunay structure.For each triangle T ∈ DT (P ) and its correspond-ing point p ∈ V or(P ), we retrieve all of T ’s neigh-bors, T ′. For each t ∈ T ′, we take its correspondingpoint p′ ∈ V or(P ) and draw an edge between p andp′. The resulting set of edges describes exactly theVoronoi planar partition.

The dualization from DT (P ) to V or(P ) de-scribed here can be computed in O(n) time. Wemust iterate over all triangles in DT (P ), of whichthere are O(n) (de Berg et al., 2000). For each tri-angle, we must compute the circumcircle to locatethe corresponding Voronoi vertex and check threeneighbor pointers to draw the appropriate Voronoiedges. These two operations can be done in con-stant time, giving an overall O(n) runtime for thedualization step.

3.1.3 The Convex Hull

Finally, we must compute CH(P ) before we cango on to find the LEC. Here, we use the simpleO(nh) Jarvis march algorithm to compute the con-vex hull. The interested reader should refer to deBerg et al. (2000) for further details on this algo-rithm.

At this point, we have found the Voronoi diagramand convex hull for our data set (Figure 3). With allnecessary data structures in place, we now proceedto find the largest empty circle.

3.2 Finding the Largest Empty Circle

To find the largest empty circle, we first locateall potential centers for that circle, which involvesidentifying all Voronoi vertices which are interiorto CH(P ) and finding all intersections betweenVoronoi edges and convex hull edges. Once all can-didate centers have been located, we draw the largestpossible empty circle around each and report whichwas the largest of all.

3.2.1 Checking Interior Voronoi VerticesWe use a naive approach for finding all Voronoi

vertices which are interior to CH(P ). For eachVoronoi vertex, we march counter-clockwise aroundCH(P ), checking whether the vertex lies to the leftof the edge. If the vertex lies to the left of all edges inCH(P ), we know that it is interior and add it to thelist of candidate LEC centers. This requires O(nh)steps, since we must check all h convex hull edgesfor all O(n) Voronoi vertices.

3.2.2 Finding Convex Hull and Voronoi EdgeIntersections

We employ another naive approach for findingall intersections between Voronoi edges and convexhull edges. For every Voronoi edge, we check bothendpoints for interiority to CH(P ). If one is interiorand one is exterior, we know that this edge must in-tersect CH(P ) at some point. We then iterate overall convex hull edges and check for intersection withthe Voronoi edge in question. By repeating this pro-cess for every Voronoi edge, we are guaranteed tofind all intersections between V or(P ) and CH(P ).

This step requires O(nh) runtime. We must checkall O(n) Voronoi edges, and for any which intersectthe convex hull, we must iterate over all h convexhull edges to find the intersection point.

3.2.3 Locating the Largest Empty CircleNow that we have found all possible points at

which the LEC can be centered (as in Figure 4),we have to decide which of these candidates is theactual center of the LEC. To find the largest emptycircle that can be drawn around any given candi-date center, we exploit the duality between DT (P )and V or(P ). Candidate centers are vertices in V orspace; however, when drawing a circle around a can-didate point we want to ensure that this circle does

31

Page 37: Class of 2008 Senior Conference on Computational Geometry

Figure 4: Candidate centers for the largest empty circle for theset of points shown in Figures 3 are outlined here. All candi-date centers lie on Voronoi vertices or on intersections betweenVoronoi and convex hull edges.

Figure 5: Solid, black lines indicate edges in DT (P ).Dashed, grey lines indicate edges in V or(P ). The point p isa Voronoi vertex and is thus a candidate LEC center. Here,p’s three nearest neighbors are the three points contained in theVoronoi cells adjacent to p, which are the vertices of p’s dualtriangle in DT space, v1, v2, and v3.

Figure 6: The LEC for our simple set of points.

not contain any points in P , which are vertices inDT space.

Any Voronoi vertex is the intersection of at mostthree Voronoi edges. This follows directly fromthe dual relationship between V or(P ) and CH(P );each Voronoi vertex corresponds to one Delaunaytriangle and is connected to the vertices which cor-respond to that triangle’s neighbors, of which thereare exactly three (except near the edges of the space,where there may be only two neighbors). Since eachVoronoi vertex p is incident to at most three Voronoicells, the three points in P closest to p are those threepoints which lie in the Voronoi cells to which p isadjacent. Those three points are the vertices of p’sdual triangle in DT (P ) (see Figure 5). Thus, bydualizing p ∈ V or(P ) back to T ∈ DT (P ), we canfind p’s three nearest neighbors. We then choose theclosest neighbor and draw a circle about p whose ra-dius equals the distance between that neighbor andp.

We accomplish the dualization of a Voronoi ver-tex to a Delaunay triangle very simply by building adictionary of Voronoi vertex-Delaunay triangle pairsas we are doing our initial construction of V or(P )from DT (P ). We then look up candidate verticesin this dictionary to find their nearest neighbors anddraw empty circles about them. By drawing emptycircles around each candidate vertex, we can locateand report the LEC.

This final step of the algorithm requires O(n)time. Finding the closest point P to any candidatecenter can be done in constant time by simple dic-tionary lookup, and we must repeat this process for

32

Page 38: Class of 2008 Senior Conference on Computational Geometry

Figure 7: A summary of the steps involved in computing theLEC.

all O(n) candidate centers.At this point, we need only to report the largest

empty circle we have found, as in Figure 6. Figure7 provides a summary of all steps taken to computethe LEC and their associated runtimes. The overallruntime of our algorithm is thus O(n[h + log n]).

4 Results

We ran the algorithm described above on a set ofpoints corresponding to the latitude and longitudecoordinates of all U.S. cities in the 48 contiguousstates of population 100,000 or greater (there are 251such cities). We found the LEC to be centered at-108.2659◦ latitude, 46.7316◦ longitude, near Win-nette, MT. V or(P ) and CH(P ) for this data setare displayed in Figure 8; the resulting LEC is dis-played in Figure 9.

The algorithm runs on this dataset of U.S. citiesin less than four seconds. In order to analyze the al-gorithm’s overall performance and the performanceof intermediate steps within the algorithm, we ran iton a number of data sets ranging in size from 100points to 10,000 points and recorded the amount ofprocessor time required to compute each step of thealgorithm. For these timed tests, we used randomlygenerated, normally distributed sets of points. Theresults of these tests are shown in Figure 10.

5 Discussion

Our algorithm was tested on and successfully com-puted the LEC for the U.S. cities data set as well asrandomly generated, normally distributed data setsof up to 10,000 points. It is clear from Figure 10that the time required to compute the LEC is domi-nated by the computation of DT (P ); all other stepsof our algorithm proceed quickly in comparison. Forthe 10,000 point data set, for example, it took about33 minutes to compute DT (P ). The next slowest

step of the algorithm was locating the intersectionsbetween V or(P ) and CH(P ), which took only 26seconds.

As mentioned earlier, we used naive approachesto several of the intermediate steps of this algo-rithm, including the simple Jarvis march for con-vex hull computation, the point location step forfinding all Voronoi vertices interior to the convexhull, and the step for identifying intersections be-tween Voronoi and convex hull edges. Each ofthese naive steps was O(nh), and for each of thesesteps we might have used a more sophisticated algo-rithm in hopes of achieving better runtime for theoverall LEC algorithm. For the convex hull, wemight have chosen from a variety of O(n log n) al-gorithms (see Preparata and Hong (1985), de Berget al. (2000), for examples). This only improvesthe speed of computing the convex hull if the num-ber of convex hull edges is somewhat large. For theidentification of interior Voronoi vertices, Toussaint(1983) describes an O(n log h) technique, which is aguaranteed improvement over the O(nh) techniquewe use, regardless of the distribution of our set ofpoints. For the Voronoi/convex hull intersection lo-cation step, Chazelle (1980) describes an O(n log h)technique for computing the intersections betweena set of segments and a convex polygon, and betterstill, Preparata and Shamos (1985) describe an O(n)march around all Voronoi cells that discovers all in-tersections with the convex hull.

While the naive approaches to these intermediatesteps used in our algorithm could be improved byimplementing any of the known faster algorithmsmentioned above, the results of Figure 10 sug-gest that this would provide very little improve-ment to the running time of our overall LEC algo-rithm. It is clear that the O(n log n) computation ofDT (P ) dominates the computation time for findingthe LEC, and thus minor speed-ups to intermediatesteps would be of limited value.

It should be noted that the data sets on which wetested our algorithm’s running time were all approxi-mately normally distributed. As such, h, the numberof convex hull edges, was quite small compared to n,the number of data points (see, for example, Figure8). Considering the possible applications of the LECproblem, such as toxic waste dump site selection orbusiness location planning, we expect that the data

33

Page 39: Class of 2008 Senior Conference on Computational Geometry

Figure 8: The Voronoi diagram and convex hull for the data set of all US cities of population 100,000 or greater.

Figure 9: The largest circle which contains no U.S. cities of population 100,000 or greater and is centered within the convex hullof these cities. The center lies at -108.2659◦ latitude, 46.7316◦ longitude, near Winnette, MT.

34

Page 40: Class of 2008 Senior Conference on Computational Geometry

Figure 10: At top, a plot of processor time versus number ofdata points. The time required for the DT (P ) computation isbarely distinguishable from the total running time of the entirealgorithm. All other algorithmic steps have running times clus-tered very near to zero for data sets of all sizes and are not distin-guishable on this plot. For this reason, a plot of log(processortime) versus number of data points is shown at bottom. Thetime for the DT (P ) computation is again quite similar to thetime for the overall algorithm. The next most time consumingstep is the identification of V or(P )/CH(P ) edge intersections,but this step is far faster than the computation of DT (P ).

Figure 11: Processor time used by our algorithm on 1000data points lying on a circle as compared to 1000 normally dis-tributed, randomly generated data points.

sets our algorithm will most commonly encounterwill be similar to the data sets on which we have al-ready tested it–somewhat normally distributed, withh small compared to n. However, should we need tocompute the LEC on some set of points which is dis-tributed differently (say, in a ring-like shape, whereh and n would be similar), we expect our O(nh)intermediate steps to begin to contribute to signifi-cantly slower runtimes for our algorithm overall.

To test this idea, we ran our algorithm on a setof 1000 points distributed on a circle so that h = nand compared the resulting performance to the per-formance on a normally distributed set of the samesize. The resulting running times are displayed inFigure 11. Note that the O(nh) check for interiorVoronoi vertices is still relatively quick. However,we see that our convex hull algorithm and our tech-nique for locating Voronoi/convex hull intersectionstake much longer on the circular data than on thenormally distributed data, leading to about a seven-fold increase in the overall running time of our al-gorithm. Thus, if we intend to run our algorithmon non-normally distributed data where h may be-come large, we would almost certainly benefit fromswitching to an O(n log n) convex hull algorithmand an O(n) technique for finding Voronoi/convex

35

Page 41: Class of 2008 Senior Conference on Computational Geometry

hull intersections. Still, because our algorithm is pri-marily applicable in domains where data is likely tobe normally distributed, such as sets of cities or busi-ness locations, we continue to use the naive O(nh)intermediate steps, since they seem to work well forthis type of data.

6 Conclusion and Future Work

In this paper, we have describe an algorithm whichcomputes the largest empty circle on a set of pointsP . The algorithm is O(n[h + log n]) and sup-ports dynamic updates to the set P without heavyre-computation of underlying structures. The algo-rithm requires the use of the Voronoi diagram, whichwe compute by dualizing the Delaunay triangulationof P . The convex hull of P must also be computed.We then check all Voronoi vertices and intersectionsbetween Voronoi and convex hull edges to see whichis the center of the largest empty circle.

Our algorithm is O(n[h + log n]), which isasymptotically worse than the O(n log n) solutionspublished by Toussaint (1983) and Preparata andShamos (1985). This extra h term results from tak-ing naive O(nh) approaches to a few intermedi-ate steps in computing the LEC. However, we haveshown that our algorithm’s overall running timeis not much affected by these O(nh) intermediatesteps when our data is more or less normally dis-tributed. Thus, we find that our use of simple, naivetechniques at some steps of our algorithm is justi-fied; while asymptotically faster techniques do existfor these steps, these faster techniques are consider-ably more complicated than the simple approach wetake. Because our O(nh) methods contribute verylittle to the total runtime of our algorithm (Figure10), we find that we can use simple, straightforwardtechniques at a negligible cost to the running time ofour algorithm.

For future work, it may be useful to implementsupport for further location constraints on the centerof the LEC, such as described in Chew and Drysdale(1986) or Toussaint (1983). For example, we mightlike to restrict the LEC to be centered in some sim-ple, though not necessarily convex, polygon or setof polygons other than the convex hull. This wouldhave been useful when working with the data setcomprised of US cities. Suppose we are using our

algorithm to find a toxic waste dump site. Ratherthan using the convex hull of this data set, whichcontains parts of Mexico, the Gulf of Mexico, andthe Atlantic and Pacific oceans, and does not includeall of the land comprising the 48 contiguous states(Figure 8), we might have preferred to constrain theLEC to be centered anywhere on US mainland terri-tory. This would both ensure that the selected sitewere actually a United States holding, and wouldalso provide a wider selection of possible LEC cen-ters by including more area in the northern UnitedStates. Thus, using some sort of simple, polygonalapproximation of the 48 contiguous states would bean improvement.

To do this, we would have to change our pointlocation strategy for testing whether a Voronoi ver-tex is interior to the bounding region, since that re-gion would no longer be convex. The current naiveO(nh) technique for finding intersections betweenthe Voronoi diagram and the bounding region wouldstill be effective, but if we were to update to theO(n) marching technique described by Preparataand Shamos (1985), we would have to modify itslightly to deal with non-convex bounding regions.

Our current algorithm avoids complicated inter-mediate steps and successfully computes the LECon data sets of varying sizes and distributions. It isquite fast on normally distributed sets. While wecould improve its performance on non-normal datasets and support further location constraints on thecenter of the LEC by using more complicated in-termediate steps in our algorithm, for now we stickwith the simple solution to the LEC problem andassume it will most often be used on normally dis-tributed data sets.

7 Acknowledgements

I am grateful to Professor Andy Danner for advisingthis project and for providing a script for graphingthe 48 contiguous states. I also thank my Swarth-more College Computer Science Senior Conferenceclassmates for reviewing this paper and providingsuggestions for its improvement.

ReferencesB.M. Chazelle, 1980. Computational Geometry and Con-

vexity, Ph.D. thesis, Carnegie-Mellon University.

36

Page 42: Class of 2008 Senior Conference on Computational Geometry

L.P. Chew and R.L. Drysdale, 1986. Finding LargestEmpty Circles with Location Constraints DartmouthComputer Science Technical Report PCS-TR86-130

M. de Berg et al. Computational Geometry: Algorithmsand Applications (2ed). Berlin: Springer, 2000. pp185-197.

A. Okabe et al. Spatial Tessellations: Concepts andApplications of Voronoi Diagrams (2ed). Chichester:John Wiley and Sons, Ltd, 2000. pp 43-57.

F.P. Preparata and S.J. Hong. 1977. Convex Hulls of Fi-nite Sets of Points in Two and Three Dimensions.Communications of the ACM, v.20, n.2, pp 87-93.

F.P. Preparata and M.I. Shamos. Computational Geome-try: An Introduction. New York, NY: Springer-Verlag,1985. pp 251-253.

M.I. Shamos, 1978. Computational Geometry, Ph.D. the-sis, Yale University.

G.T. Toussaint, 1983. Computing Largest Empty Circleswith Location Constraints. International Journal ofParallel Programming, v12.5, pp 347-358.

37

Page 43: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 38–44,Computer Science Department, Swarthmore College

Unbiased Congressional Districts

Alex [email protected]

David [email protected]

Abstract

This paper presents a strategy for dividinga state into congressional districts using amodified version of Smith and Ryan’s re-cursive shortest splitline algorithm (2007).Our strategy reduces the cost of the com-putation by approximating the populationof a ZIP Code Tabulation Area (ZCTA) asa point mass at its population centroid. Ifthere areN ZCTAs in the state withE to-tal edges, andk districts to be created, ouralgorithm runs in expectedO((N2 + E) ·logk) time.

1 Introduction

The determination of congressional district bound-aries within a state is often a controversial pro-cess. Typically, any solution that gives contiguous,equipopulous districts is legal. Therefore, the ma-jority party in the state legislature has wide latitudeto draw districts that bolster its chances in congres-sional elections. Such gerrymandered districts willtypically disperse regions of strong support for theopposition party among the districts so that the ma-jority will control most or all seats.

We adopt the following definitions. Anunbiaseddistricting is a division of a region into equipopu-lous districts that is developed without any informa-tion about the residents’ voting preferences. Ager-rymandered districtingis a division of a region intoequipopulous districts such that the region’s major-ity party is the majority party in every district.

2 Related Work

The literature contains several proposals for gener-ating or maintaining unbiased districts that optimizesome geometric criterion.

Given an initial districting, Helbig et. al. heuris-tically maximize district compactness using an iter-ative linear programming technique (1972). In theirmethod, the region is discretized intom existing po-litical zones, such as counties or census tracts, thatare small compared to the whole state and approxi-mately equipopulous. They then proceed as summa-rized in Algorithm 1. Constraint A is the one-voteconstraint: each zone belongs to exactly one district.Constraint B is the equipopulation constraint. It re-lies on the assumption that zones are equipopulous,but this restriction could easily be lifted by rewrit-ing the constraint as an inequality on the popula-tion sum, with some deviation tolerance. The valuefunction to be minimized is simply the summedpopulation-weighted distance of zones from the cen-troids of their districts. Since finding a minimum bybrute force takesO(2m) time, the transportation al-gorithm is used; the details are out of the scope ofthis paper. Note that this method does not guaranteethat districts will be contiguous.

Macmillan presents an innovative solution to thecontiguity problem (Macmillan, 2001). Macmillanfirst presents the connectivity method of checkingcontiguity of a region, which is a streamlined, butstill O(m3), version of connectivity matrix multipli-cation. Macmillan improves on this algorithm byinitially assuming that the regions in the districtingare already connected, and what is being examinedis the decision to either add a single zone to or re-move a single zone from the current region. Sincethe only way the region can become disconnectedis if adding or removing the zone breaks contiguity,we need only examine the single zone and the zonesit borders. Using Macmillan’s switching point tech-nique, it can be determined quickly whether the op-eration breaks contiguity. An initial districting canthen be updated in response to population movement

38

Page 44: Class of 2008 Senior Conference on Computational Geometry

Algorithm 1 Helbig et. al. linear transportLet ǫ be an arbitrary stagnation threshold.Let m be the total number of zones.Let n be the number of districts.g = m/nLet (ui, vi) be the centroid of zonei.Let pi be the population of zonei.repeat

for All districts j doCompute(aj , bj), the centroid of districtj.for All zonesi do

dij =√

(aj − ui)2 + (bj − vi)2

if zonei is in districtj thenxij = 1

elsexij = 0

end ifend for

end forconstraint A:

j

xij = 1 for all i.

constraint B:∑

i

xijpi = g.

Using the transportation algorithm, minimize∑

i

j

(xij · dij · pi) subject to constraints

A,B.for All districts do

Let (aj , bj) be the centroid of the new districtj.

end foruntil |aj − aj | < ǫ and|bj − bj | < ǫ for all j.

by simulated annealing. In this process, donor dis-tricts with excess population and recipient districtswith a population deficit are selected at weighted-random by the size of the deviation. A zone totransfer is selected at weighted-random by the sizeof the resulting deviation. So long as the transferwould not break contiguity, it is accepted if it strictlyimproves deviation, and probabilistically acceptedbased on the current annealing temperature other-wise. Macmillan’s algorithm does not optimize forcompactness or any other geometric property, andtherefore may yield results as unattractive as a ger-rymander.

The shortest splitline algorithm of Smith andRyan recursively divides the region to be districtedinto two regions (Smith and Ryan, 2007). If the re-gion being divided has an even number of congres-sional seats, the two child regions are equipopulous.If it has an odd number, then one region will be largeenough to have one more seat than the other. Smithand Ryan compute splitlines on a grid sampling ofpopulation. The details of their implementation areonly given as uncommented C source code, and aretherefore not summarized here.

Our literature search did not discover any exist-ing work explicitly concerned with optimal gerry-mandering. However, the generalized equitable hamsandwich algorithm of Bespamyatnikh et. al. isapplicable (1999). This algorithm splits a set ofr · p red points andr · q blue points intor regionswith p red points andq blue points using a divide-and-conquer strategy. Using voter registration rolls,registered Democrats (blue points) and Republicans(red points) can be identified with geographic loca-tions. Lettingr equal the size of the state’s con-gressional delegation, the majority party will controlevery district in the equitable ham sandwich subdi-vision.

3 Implementation

We have implemented a shortest splitline algorithmusing the basic concepts developed by Smith andRyan (2007), but with the adapted implementationsummarized in Algorithm 2. The algorithm pro-duces districts that are contiguous, and equipopulousto a variable tolerance parameterǫ. Degeneracy han-dling is not included in the pseudocode, but has been

39

Page 45: Class of 2008 Senior Conference on Computational Geometry

implemented and is discussed further in Section 3.3.Smith and Ryan use a raster model for the re-

gion: boundary points are represented by pixels, anda splitline starts and ends at the centers of pixels.This model has the problem of fixed and arbitrarygranularity: edges cannot shift by less than one pixelat either end, and the granularity is set by the reso-lution of the original raster image of the region. Ifthe original image is too small, the resulting splitlinemay be unsatisfactory in population distribution, butif the original image is too large, the algorithm takesmuch longer.

Instead of working within the limitations of araster image, we chose to use the ZIP code as ourfundamental element. Populations are stored by ZIPcode rather than by pixel. Splitlines start and endon ZIP code population centroids, and the determi-nation of the population of each district is calculatedby summing the populations of the ZIP codes whosecentroids fall within that region. The outer bound-aries of the ZIP code zones comprise the border ofeach district.

3.1 Data Set

ZIP codes have a number of virtues as fundamentalelements for the software. They are generally sizedto contain roughly even populations, so areas of highpopulation density are broken down into smaller ZIPcodes. However, ZIP code regions are determinedarbitrarily by the post office and tend to follow postalroutes rather than being shaped according to anymetric of geographical cohesiveness.

The US Census has found it useful to map out theregions containing all addresses in each ZIP code,called Zip Code Tabulation Areas (ZCTAs). Mapoverlays in standard formats are available onlinefrom the US Census’s website for all fifty states.1

Our implementation extracts data from the ArcViewShapefile format.

Grubesic and Matisziw’s use of census ZCTAmaps for epidemiological studies (2006) helpfullyclarified that ZCTAs in which three numbers are fol-lowed by anHH represent water surface, and thosewith anXX represent unpopulated land. For exam-ple, any water feature mostly within the303 ZIP3ZCTA would be labeled303HH.

1http://www.census.gov/geo/www/cob/z52000.html

Algorithm 2 ZCTASplitLet ǫ be an arbitrary population deviation toler-ance.Let k be the number of districts.Let t be the population.Let R be the set of ZIP codes in the region.if k = 1 then

return Rend iffor Each edgee of a ZIP inR do

If e adjoins only one ZIP, it is in the set of pos-sible boundary edgesB.

end forFind the northwesternmost edgep in B. {p mustbe on the outer boundary.}Z ← ∅Let c be the edge followingp on the ZIPz thatpadjoins.while c 6= p do

Z ← Z ∪ {z}while c ∈ B do

cn ← the edge followingc on z.c← cn

end whilez ← the ZIP thatc adjoins that is notz.cn ← the edge onz in B that shares a vertexwith c.c← cn

end whileg ← ⌊k/2⌋ · t {g is the goal population.}l←∞for All z1 ∈ Z do

for All z2 ∈ Z doDraw a splitline connecting the centroids ofz1 andz2.a← the population above the line.d← the distance between the centroids.if (1− ǫ)g ≤ a ≤ (1 + ǫ)g andd < l then

l← d.sb ← (z1, z2)

end ifend for

end forif sb is not definedthen

error no acceptable splitline foundelse

U ← ZCTASplit(ǫ, k = ⌊k/2⌋, t = g, R =ZIP codes above the splitline)O ← ZCTASplit(ǫ, k = ⌈k/2⌉, t = t− g, R =ZIP codes below the splitline)

end ifreturn U ∪O

40

Page 46: Class of 2008 Senior Conference on Computational Geometry

Since the ZCTA maps simply delineate eachZCTA by one or more labeled polygons, no neigh-borhood information can be directly determinedfrom the ZCTA shapefile. This complicates findingthe boundary of a region to split, an issue that is dealtwith in Section 3.2.

We have been testing our implementation withpublicly available voter rolls from the state of Geor-gia.2 These voter rolls contain ZIP code, latitude,longitude, and party registration. All voter entriesfor a single ZIP code are placed within that ZIPcode, and the centroid of the population of that ZIPcode is found. This population centroid is used todetermine the side of a splitline on which each ZIPcode falls.

3.2 Strategy

Algorithm 2 can be divided into two phases. First,ZIP codes on the boundary of the region are identi-fied. A ZIP is a candidate to be on the boundary if ithas at least one edge that no other ZIP code in the re-gion shares. Since the census ZCTA polygons maynot perfectly tessellate the state, a walk is performedto identify the actual edge. This walk begins at thenorthwesternmost edge in the entire set of candidateboundary edges, which bounds some boundary ZIPz0. The edges ofz0 are traversed in the cyclical or-der extracted from the shapefile until an edgee thatalso bounds some other ZIPz1 is reached. The walkthen moves ontoz1. One edge adjacent toe bound-ing z1 is in the set of candidate boundary edges. Thewalk returns to the boundary by proceeding in thedirection of that edge. When the walk revisits thefirst edge, all visited ZIPszn are returned.

Then, for every pair of boundary ZIPs (za, zb), asplitline is drawn between the population centroids.Each ZIP population centroid in the region is classi-fied as above or below the splitline, and the popula-tions in each half are summed. If the ratio of pop-ulation above the splitline to below the splitline iswithin some arbitrary tolerance of the equipopulousratio, the splitline is a legal candidate. The shortestlegal candidate splitline is accepted, and the algo-rithm recurses on the two ZIP sets returned.

2http://grso.uga.edu/voter/

3.3 Degeneracies

3.3.1 Rivers and Lakes

HH regions representing rivers can wander fromthe border across large swaths of a state, makingit difficult to identify ZIP codes on the boundary.Simply removing the water from the dataset directlyplaces a large number of interior ZIP codes on theapparent boundary, which is no improvement. Whena split is made with water preserved, allocating wa-ter that crosses the boundary to one side or the otherproduces similar problems upon recursion.

The solution is to allocate the entire body of waterto both regions. The boundary walk then proceedsalong the edge of the water until it eventually returnsto the proper boundary on the other side. The result-ing boundary will thus include protrusions that arenot actually part of the intended district. While po-tentially bizarre in appearance, these protrusions arenot disruptive to the algorithm because they containno population. Since regions will eventually containwater that is entirely disconnected from their actualland area, the boundary edge traversal must begin onthe northwesternmost edge inB that adjoins a pop-ulated ZIP in the region.

3.3.2 Eccentric Splitlines

Consider the line containing the segment that con-nects the centroids of two boundary ZIP codesz1

andz2. If this line crosses the region boundary atany other ZIP code, the subsets of ZIPs produced bysplitting on the line may be misidentified. We callsuch lines eccentric splitlines.

As a simple example, considerz1 andz2 on theboundary of a circular region, with populations dis-tributed such that the line connecting the centroidsis perpendicular to the local boundary. A splitlinefrom z1 to z2 appears to divide the region in half,when it actually should separatez1 andz2 from allother ZIPs.

To work around this degeneracy, we simply rejectany eccentric splitline. The check for eccentricityis fast. Recall that the boundary walk produces theboundary ZIP codes in order. After classifying allZIP codes as above or below the line, we start atan arbitrary ZIP code on the boundary and look upits classification. We then consider each subsequentboundary ZIP in order. If the classifications of ad-

41

Page 47: Class of 2008 Senior Conference on Computational Geometry

jacent ZIPs differ, but neither is a boundary ZIP, thesplitline is eccentric.

3.3.3 Discontiguity

ZIP code boundaries are stored in the shapefileas ordered lists of edges. Since the boundary-walkalgorithm must be able to wrap around the edge listfrom the last edge to the first, each ZIP code cannotstore more than one polygon. However, the datasetmay include more than one polygon with the sameZIP code label. Examples of situations where thismay occur include groups of islands with the sameZIP code, and ZIP codes that have a river cuttingthrough the middle.

The solution to this problem is to symbolicallyperturb the dataset by re-labeling multiple polygonsthat have the same ZIP code. Data is read in a lin-ear fashion, so the first polygon with the ZIP code30304 will keep that label, but subsequent polygonswill be re-labelled 30304I, 30304II, etc. Populationdata is only inserted into the polygon that happens tohave been inserted first, and therefore happens to belabeled 30304. Since the population centroid is usedto determine splitline information, this has no nega-tive effect on the accuracy of the resulting splitline.

3.3.4 High-Degree Vertices

There are two other degeneracies that result frompeculiarities of the ZCTA dataset. These must bedealt with on a case-by-case basis.

The first situation that may arise is a polygonmaking contact with the boundary at a single vertex.This is a special case of a situation called a high-degree vertex. The implementation is designed todeal with vertices that are incident to at most threeedges: we walk the boundary of the current polygonuntil we run into another polygon on the boundary,then we jump to that polygon and keep walking. Ifthe abutting polygon only touches the boundary at asingle point, however, then the boundary continueson some other polygon that also touches that vertex.Since the algorithm does not know how to get to thatnext polygon, it must search through all edges in thecandidate boundary edge list to find the one that con-tinues from this vertex. It is important to look for anincident edge that has not yet been traversed.

Another degeneracy occurs when a polygon hasonly one edge on the boundary. The implementation

determines the direction to walk along each polygonby looking one edge ahead and one edge behind.If the first boundary edge is also the last boundaryedge, then the implementation cannot determine thisdirection. It must then examine the vertices; the di-rection selected is that which carries the walk awayfrom the last vertex seen.

3.4 Asymptotic Analysis

Say the dataset hasN ZCTAs andE edges, and wewish to form k districts. Let us first consider thetopmost level of recursion. The algorithm first ex-amines each edge to determine whether it appearsin more than one polygon in order to build a list ofcandidate boundary edges. This takesO(E) time.Next, we traverse the polygons that are incident tothe boundary edges to cull for internal water fea-tures and polygon edge misalignments. Our al-gorithm only walks those polygons that sit on theboundary of the region. For the next step, we maketwo assumptions. First, we assume that approxi-mately

√N ZCTAs lie on the boundary, and thus√

N polygons. Second, we assume that all poly-gons in the dataset contain an approximately con-stant number of edges. walking the boundary is thenanO

(

E +√

N)

operation at each level.The final portion of the algorithm examines all

candidate splitlines, that is, the set of lines connect-ing any pair of boundary ZIP code population cen-troids. Assuming there are

√N centroids, there will

beO(√

N2)

= O(N) splitlines. For each splitline,we must calculate the population above and belowthat splitline, takingO(N) time. Thus the runtimefor this portion of the algorithm takesO

(

N2)

time.Each level of recursion must execute both of the

above operations. There arelog(k) levels of recur-sion, so the expected runtime for the overall algo-rithm is O

(

(N2 + E)logk)

. The worst-case run-time occurs when all ZCTAs lie on the boundaryof the region to be split, resulting in a runtime ofO

(

(N3 + E)logk)

.

4 Results

We have tested our software on the state of Geor-gia. Since our implementation is proof-of-concept,we let the registered voters of Georgia approximatethe population. Our software produces lists of ZIP

42

Page 48: Class of 2008 Senior Conference on Computational Geometry

codes by district, and generates KML output for vi-sualization with Google Earth.

Georgia has 13 congressional districts. Our soft-ware successfully computes a shortest splitline dis-tricting for population variation tolerances of 3%and higher. Since there are only about 1000 ZIPcodes in Georgia, the regions at low levels of recur-sion can have very few non-eccentric splitline candi-dates, resulting in failure to find an acceptable split-line at tighter tolerances. If better population eq-uity is required, smaller tabulation regions should beused.

Figure 1 shows the results with a 3% tolerance,and Figure 2 shows the results with a 5% tolerance.As expected, the splitlines are noticeably longer inFigure 1, particularly in the north of the state.

Figure 1: 13 districts attempted, 3% tolerance.

Of the approximately 3.5 million registered votersin the Georgia data, only 102,227 have a declaredparty affiliation. 63% of those with a declared affil-iation are Democrats; consequently, Democrats ap-pear to carry 10 of the 13 districts at 5% populationtolerance. Since so few voters have formal affilia-tion, this result has no value as a prediction of actualoutcomes.

5 Conclusion

The software we have developed successfully dis-tricts Georgia. Since there are relatively few ZIP

Figure 2: 13 districts, 5% tolerance.

codes per state, it runs quickly in practice: Georgia,with about 1200 ZIPs, is districted in 210 secondson a modern workstation. Qualitatively, the resultsare reasonable. The Atlanta area is partitioned intosmall, compact districts, with larger but still simplepolygons outstate.

The districts produced by using ZCTAs as the fun-damental zone are certainly preferable to gerryman-dering, but have some quality issues. As seen inGeorgia, high equipopulation precision is not attain-able with such large quanta. Moreover, the degen-eracy handling required to cope with idiosyncrasiesof the ZCTA data set can distort results. In particu-lar, the eccentric splitline handling will reject mostlines that closely parallel a region boundary, even ifthat line would be a desirable solution. Finally, ZIPboundaries themselves are arbitrary, irregular, andpotentially open to political manipulation.

The natural solution is to replace ZCTAs withsome other, finer tessellation of convex polygons.In the extreme, this tessellation could be theVoronoi diagram on the set of all voters. However,the expected quadratic and possible cubic runningtimes will penalize performance severely for higher-frequency sampling. It may be possible to remove afactor ofN from the runtime by building a quadtreeindex of voters, with each node storing the entirepopulation descended from it.

43

Page 49: Class of 2008 Senior Conference on Computational Geometry

6 Acknowledgments

We thank Andy Danner for advising our project.

References

Micah Altman. 1997. Is automation the answer: Thecomputational complexity of automated redistricting.Rutgers Computer and Law Technology Journal.

Sergei Bespamyatnikh, David Kirkpatrick, and JackSnoeyink. 1999. Generalizing ham sandwich cuts toequitable subdivisions. InSCG ’99: Proceedings ofthe fifteenth annual symposium on Computational ge-ometry, pages 49–58, New York, NY, USA. ACM.

Tony H. Grubesic and Timothy C Matisziw. 2006. Onthe use of zip codes and zip code tabulation areas (zc-tas) for the spatial analysis of epidemiological data.IntJ Health Geogr., 5(58).

Robert E. Helbig, Patrick K. Orr, and Robert R. Roediger.1972. Political redistricting by computer.Commun.ACM, 15(8):735–741.

Jorg Kalcsics, Stefan Nickel, and Michael Schroder.2005. Towards a unified territorial design approach -applications, algorithms, and gis integration.Journalof Geographical Systems, 13(1):1–56.

W. Macmillan. 2001. Redistricting in a gis environ-ment: An optimisation algorithm using switching-points. Journal of Geographical Systems, 3(2):167–180.

Warren D. Smith and Ivan Ryan. 2007. Ger-rymandering and a cure - shortest splitline al-gorithm. http://www.rangevoting.org/GerryExamples.html.

44

Page 50: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 45–48,Computer Science Department, Swarthmore College

Optimal Double Coverage In The Art Gallery

Scott [email protected]

Andrew [email protected]

Abstract

We plan to examine a well known visibil-ity problem termed the art gallery prob-lem. The general idea behind the prob-lem is that a museum wants to mini-mizethe number of cameras present inan art gallery while still recording every-thingthat happens in the room. We takethe problem a step further and investigatethe optimal arrangement of cameras sothat every spot in the room is covered bynot just one, but two cameras. This willallow constant surveilance even if any onecamera were to fail. We do this by us-ing a bottom-up approach where we usea three coloring algorithm to find the op-timal placement for single coverage and abasic dobuble coverage of a polygon rep-resenting a floorplan. We then use a opti-mization algorithm with a line of sight al-gorithm to check each camera of the dou-ble coverage and remove any unnecessarycameras, leaving the optimal double cov-erage of the polygon.

1 Introduction

The problem is named after art galleries because theart needs to be under surveilance at all times andthey tend to be shaped in irregular ways which canmake this security difficult. The problem was firstproposed by Viktor Klee in 1973 (Klee, 1979). Ithas since been proven that a maximum of⌊n/3⌋cameras will be needed,n being number of verticesin the polygon that is the room, to cover the entireroom. This is known as the Art Gallery Theoremand was stated by Vaclav Chvatal (Chvatal, 1973).

For us to tackle this problem we designed a programthat takes a set of points that make up the polygonthat will be guarded, and then returns an image of thefloorplan with the cameras placed upon it. By usinga three coloring algorithm on each of the points inthe triangulation determine the ideal single cameraplacement and the basic double coverage placementof cameras, which can then be optimized.

2 Triangulation

In order to perform the 3-coloring on the points ofthe polygon, it is first necessary to break the polygondown into its constituent triangles, so that we canaccurately determine whether the 3-coloring is ac-curate. We do this by finding any splitpoints withinthe polygon so that it can be seperated into mono-tone polygons. These monotone polygons are thenindividually triangulated, then put back together tocreate an ideal triangulation ofn − 2 triangles fornpoints.

2.1 Finding Split Points

The first step in our triangulation algorithm was tolocate any split points in the polygon that we can useto break the polygon down into smaller, monotonepolygons to triangulate. The split point is a point thatis determined to be interior to its neighboring pointson they-axis, in other words, when the point causesthe polygon to be convex on the top or bottom. Thisis done by going through each point and shooting arays up and down the point’sx-axis (Seidel, 1991).We then use helper functions to determine whetheror not the rays intersect any other segments of thepolygon. If both rays hit a segment of the polygon,they are then tested on the basis of how many timesthey intersect the polygon to determine whether theyare interior to the polygon. If the point and its rays

45

Page 51: Class of 2008 Senior Conference on Computational Geometry

Figure 1: The top two polygons are monotone be-cause every line only intersect the polygon twice.1

meet these criteria they are then flagged as a splitpoint and the polygon is then split into three poly-gons, one to the upper right of the point, one to theupper left, and one beneath the point, with the basesof the upper two polygons and the top of the lowerpolygon formed by the rays along the x-axis of thepoint. This continues until the original polygon hasbeen completely broken down into monotone poly-gons (de Berg et al., 2000).

2.2 Monotone Triangulation

Since monotone polygons have no interior points onthe y-axis, they get rid of several possible degen-eracies when being triangulate as opposed to try-ing to triangulate the entire poylgon at once. Oncethe monotone polygons have obtained, each pointwithin them is checked as the start point for the tri-angulation using a method similar to the one usedfor finding split points, but this time we check to seeif they are interior to their neighboring points in re-gard to thex-axis. If such a point is found, then itis chosen as a start point, otherwise the split pointis chosen. The triangulation algorithm then walksaround the polygon’s points using a list of connec-tions stored in each point to determine the points itis connected to, and if there is no connection to thestart point, then one is added and a line is formed.The shared point between the two previous pointsis added and then the three are saved as a triangle,and this continues until the entire polygon has beentraversed. After each monotone triangle has been tri-

1image from http://en.wikipedia.org/wiki/Monotonepolygon

Figure 2: An example of triangulation around startpoints.2

angulated, they are all put back together in the poly-gon, and the horizontal rays from the split points areremoved, creating an optimally triangulated polygon(de Berg et al., 2000).

2.3 Handling Degeneracies

It is worth noting that the algorithm that we havecome up with in this is capable of handling just aboutany degeneracy that we encountered. If the polygonis concave, our algorithm can deal with the problemsof possible outside segments as well as any problemsthat may arise from having a vertex in the middle ofthe polygon. the outside segment problem is done byour suprisingly simple intersection test which takesthe modulus of the number of interstections that theray encounters with both edges and vertices. If thenumber of intersections is even then the resultingmodulus is zero, and the ray is considered outsideand discarded, as was previously explained in sec-tion 2.1.

3 Optimizing Camera Placement

3.1 3-coloring and Camera Placement

With the triangulation in place it is now possibleto perform an easy 3-coloring of the polygon, sothat cameras can be placed. Using the triangula-tion within the polygon, we can now proceed to use

2from http://www.cs.ucsb.edu/suri/cs235/Triangulation.pdf

46

Page 52: Class of 2008 Senior Conference on Computational Geometry

three coloring to determine where to place the cam-eras. Using the list of triangles that was created dur-ing the monotone triangulation, our algorithm takesthe first triangle from the list and colors each pointa different color. The algorithm then looks for tri-angles that share sides with the previously coloredtriangle and color the remaining point is then col-ored based on what coloring of the other two pointsare. This continures until all of the triangles in thelist have been colored, with the number of the pointswith each coloring stored as an integer. The integersare then compared with one another, cameras beingplaced at the color with the lowest integer value, cre-ating optimal single coverage for the polygon (Urru-tia, 1991) . But in order to achieve double coverageanother set of cameras have to be placed at the nextsmallest coloring to provide a basic double coveragewhich can be optimized.

3.2 Visibility Graph

Now that the cameras have been placed it is time todetermine what points they see and and what howmany cameras see each point, assuming that if acamera could see a point then it generally sees thearea surrounding the point, barring degenerate caseswhich are taken care of when the cameras are opti-malized later on. Using a line of sight function,wecreated a visibility graph by traversing every pointfrom each camera, drawing a line between the twopoints, making sure that the line did not intersect asegment of the polygon and remained inside of it.By doing this we then built up a list of each pointseen by each camera, with thenumber of camerasseeing each point, allowing our heuristic to optimal-ize the camera placement (O’Rourke, 1987).

3.3 Camera Optimalization

Now we have our optimalize the camera placementby going through each camera and seeing if it canbe removed from the polygon, updating the eachpoint it sees and decrements the number of camerasthat can see them accordingly. If one any point’scount of cameras that can view it drops below 2, thenthe camera has to be replaced, otherwise, it remainstaken off and the next camera is then checked. Afterthe optimization algorithm is complete, the camerasleft are the optimal.

Figure 3: Simple double coverage on a test polygonusing only 3-coloring.

Figure 4: Optimized double coverage using a visi-bility graph and optimization.

47

Page 53: Class of 2008 Senior Conference on Computational Geometry

4 Results and Conclusion

After testing our algorithm on progressively morecomplex polygons, our algorithm easily does bet-ter than⌊2n/3⌋ camera placement for double cover-age of cameras outside of the the worst case, whilethe entire program runs inn2 time, due to the factthat the points are looked at multiple times espes-cially during the optimalization step. It also provesfairly adept at making a strong placement for cov-erage greater than double, although it needs to bemore thoroughly tested to make any conclusions inthat regard.

References

V. Chvatal. 1973. A combinatoral theorem in plane ge-ometry. Number 18, pages 39–41.

M. de Berg, M. van Kreveld, M. Overmars, andO. Schwarzkopf. 2000. Computational geometry: Al-gorithms and applications (2nd ed.). pages 45–61.

V. Klee. 1979. Some unsolved problems in plane geom-etry. volume 52, pages 131–145.

Joseph O’Rourke. 1987. Art gallery theorems and algo-rithms. pages 11–23.

Raimund Seidel. 1991. A simple and fast incrementalrandomized algorithm for computing trapezoidal de-compositions and for triangulating polygons. InCom-putational Geometry The- ory and Application, vol. 1,no. 1, pp. 51-64.

Jorge Urrutia. 1991. Art gallery and illumination prob-lems.

48

Page 54: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 49–53,Computer Science Department, Swarthmore College

Voronoi Natural Neighbors Interpolation

Chris [email protected]

Mike [email protected]

Abstract

Implementing point cloud to grid con-version for digital elevation maps (DEM)presents one with many options for inter-polation and we intend to explore algo-rithms for interpolation during the con-version process with a specific focuson Voronoi natural neighbor interpola-tion. By partitioning the environmentinto Voronoi cells and using the informa-tion from neighboring cells and their re-spective generating point’s elevation, wecan achieve aesthetically pleasing inter-polation results with runtimes competi-tive with lower-order interpolation algo-rithms. We compare our natural neigh-bors interpolation method with a linearinterpolation method and a regularizedspline interpolation method quantitativelyusing cross-validation and qualitatively byrendering the interpolted meshes usingGRASS. 1

1 Introduction

When dealing with discrete sets of elevation datasuch as elevation information collected using meth-ods such as laser range finding or LIDAR, it is oftendesirable to be able to estimate or predict the val-ues of unsampled locations using the available infor-mation. One application where interpolation can beuseful is visualization of elevation data. Point eleva-tion data obtained through LIDAR or other remotesensing methods is not always uniformly sampled.One way to visualize the data set would be to simplytriangulate the point set into a triangular mesh and

1http://grass.itc.it/

render that mesh, but the resulting image would notmodel the underlying data well. By using differentinterpolation methods on the original elevation data,more accurate rendering can be performed and de-pending on the method of interpolation, the resultingvisualization can change dramatically.

There are many interpolation methods available toestimate these unsampled values, and the differentmethods usually offer tradeoffs between the accu-racy of the prediction and the efficiency of the com-putation. One of the simplest interpolation meth-ods would be to assign each unsampled location avalue based upon which location within the set ofknown values it lies closest to. Although this sim-ple method is computationally efficient, the resultingfunction is not continuous everywhere, specificallyalong the edges where locations are equidistant fromthe samples. In most cases these discretized estima-tions will not be as accurate as the results from othermore computationally expensive interpolations. Thediscontinuities in the resulting function also do notmodel the sampled data in an aesthetically pleasingmanner. Methods such as interpolation by regular-ized spline with tension result in functions whichhave regular derivatives of all orders everywhere al-lowing for analysis of surface geometry as well asimproved accuracy in estimation (?).

Natural neighbors interpolation provides a goodtradeoff between computational efficiency and accu-racy. In this method the value of an unsampled pointis determined through a weighted average of the val-ues of the interpolation points neighbors within thesample set. These natural neighbors are determinedby finding which Voronoi regions from the originalpoint set would intersect the Voronoi region of theinterpolation point, if it were to be inserted. The re-sulting function is continuous everywhere within theconvex hull of the sample set and mimics a taut rub-

49

Page 55: Class of 2008 Senior Conference on Computational Geometry

ber sheet being stretched over the data. Our hope isthat Natural Neighbors Interpolation will provide acomputationally efficient method with which to ac-curately visualize elevation data.

2 Related Work

There are an overwhelming number of options whenchoosing which method to use for interpolationwhen converting from a point cloud to a grid for aDEM. (?) details many low-level routines for in-terpolation including: the level plane; linear plane;double linear; bilinear; biquadratic; Jancaitis bi-quadratic polynomial; piecewise cubic; bicubic; andbiquintic interpolation method. (?) draws the con-clusion that higher- order interpolation methods willalways outperform those with linear complexity interms of modeling the terrain accurately. The prob-lem with choosing higher-order interpolation rou-tines is that the computational backlash is not neces-sarily proportional to the gain in accuracy; this begsthe question: How do we balance modeling accuracyand compuational efficiency?

Other interpolation methods such as the regular-ized spline with tension described in (?) attempt tobalance computational efficiency and modeling ac-curacy. The regularized spline with tension delib-erately attempts to smooth the surface being iterpo-lated and tweaks the mesh appropriately. Thougha little less straightforward than other lower-levelmethods of interpolation, this method is a goodbenchmark for performance and modeling accuracy;as such, we will use it as a comparison for ourVoronoi natual neighbors method in this paper. Weexpect Voronoi natural neighbors interpolation torepresent a desirable balance between computationalcomplexity and aesthetics.

3 Methods

3.1 Computing the Delaunay triangulationThe Delaunay triangulation for a set of points P is atriangulation DT(P) such that no point in P is withinthe circumcircle of any triangle within the triangu-lation. This is also the triangulation which maxi-mizes the minimum angle within the triangulation.DT(P) is computed using a randomized incrementalapproach as outlined in (?). Each point in P is in-serted incrementally and the Delaunay triangulation

for that set of points is computed. Initially the tri-angulation consists of a single triangle which is de-fined to contain all of the points within P. As eachpoint is inserted, the appropriate edges are addedto the current Delaunay triangulation so that it re-mains a triangulation although it is not necessarilystill a Delaunay triangulation. In order to ensure thatno point within the current triangulation lies withinthe circumcircle of any triangle, illegal edges mustbe flipped. An illegal edge is one where the cir-cumcircle defined by the three vertices of one ad-jacent triangle contains the outlying point from theother adjacent triangle. Special care must be takenwhen legalizing edges where one or more of the ver-tices involved belong to the initial bounding trian-gle. Only edges whose adjacent triangles have beenchanged due to the insertion of the new point canbe illegal since the triangulation was legal before-hand. As a result when an edge is illegal and must beflipped, the other edges incident to the involved tri-angles must also be legalized. Since the angle mea-sure of the triangulation increases with each edgeflip and there is a maximum angle measure for thegiven set of points, the edge legalization is guaran-teed to terminate. Once all of the points have beeninserted into the triangulation, the vertices of the ini-tial bounding triangle and all of the edges incident tothese three vertices must be removed from the trian-gulation.

3.2 Transforming to the Voronoi Diagram

The Voronoi Diagram of a set of points P Vor(P)can be computed easily given its dual DT(P). Eachtriangle within DT(P) corresponds to a vertex inVor(P). Each edge in DT(P) corresponds to an edgein Vor(P). For a triangle in DT(P), the location of thevertex in Vor(P) can be calculated by determiningthe center of the circle circumscribed by the threevertices of the triangle. This point can be found bydetermining the intersection of the perpindicular bi-sectors of each edge in the triangle. Each edge inDT(P) is adjacent to two triangles and correspondsto an edge in Vor(P) connecting the two verticeswhich are the duals of these adjacent triangles. Us-ing this dual transformation it is a simple procedureto compute Vor(P) given DT(P).

50

Page 56: Class of 2008 Senior Conference on Computational Geometry

Figure 1: This figureashows the Voronoi cell for the insertedpoint v overlayed on the Voronoi diagram for the original pointset. One of v’s natural neighbors, p, is shown with its Voronoicell shaded. The area stolen by the insertion of v can be seen inthe overlap between the two Voronoi cells.

3.3 Computing the Natural NeighborsInterpolant

When computing the natural neighbors interpolant,it is important to intuit the relative ‘neighborliness,’as (?) calls it, of adjacent Voronoi cells. Theseneighbors are the points within the original pointset whose Voronoi cells intersect the Voronoi cellof the interpolated point, if it were to be added tothe point set. The interpolated value is computedas a weighted average of the area stolen from eachneighbor by the insertion of this point.

To compute this weighted average, we first com-pute the Delaunay triangulation of the original setof points P. Given DT(P) we need to calculate theVoronoi cell of the point v, whose value we want toestimate, if it were to be added to P. Since the in-sertion of v will only alter DT(P) and consequentlyVor(P) locally, we do not need to recompute the en-tire Delaunay triangulation. We only need to com-pute a Delaunay triangulation for the points whichwould be neighbors of v. In order to determine thislocal point set we can use the existing triangulationDT(P)and corresponding Voronoi diagram. The areastolen from each neighbor of v can be computed byfinding the difference between the area of Voronoicell in Vor(P) and the area within the local Voronoidiagram. The interpolated value for v is then cal-

culated as:∑

neighbors ofvareastolen

area of the Voronoi cell ofvαwhere alpha is the value, possibly an elevation value,for the specific neighbor.

To compute DT(P) and transform to Vor(P) as de-scribed earlier takes O(n logn) time where n is thesize of P. Vor(P) must be calculated once for theoriginal point set. The local Voronoi diagram mustbe calculated for each interpolated point. Since thesize of this local subset of P does not depend onn but rather the distribution of points in P and thenumber of neighbors that the inserted point wouldhave, we can assume that for large point sets, thislocal set of points will be much smaller than n andwill not depend on n. This means calculating the lo-cal Voronoi diagram will take a relatively constantamount of time independent of the size of P. In or-der to determine which points belong in this localpoint set we determine which triangle in DT(P) thepoint lies within. We can follow the outgoing edgesfrom the vertices of this triangle to determine the ap-propriate neighbors to include. This process againdepends on the the size of the local point set whichdoes not depend on n. To calculate the weighted av-erage we must locate Voronoi cells a constant num-ber of times. We can use the DAG search structurefor DT(P) to locate points and follow the dual point-ers into Vor(P). Locating a Voronoi cell will takeO(logn) time. For each point we need to interpo-late we need to perform a constant number of lognsearches plus a relatively constant amount of workto compute the local Voronoi diagram, so to inter-polate k points for a point set of size n would takeO((n+k)logn) time.

4 Results

A set of 50 points within a 400 by 400 region werechosen. Elevation data for these points was then ob-tained by sampling an elevation image which can beseen in Figure 2 (far left). Three different interpola-tion methods were performed on a small subregionof the image using the 50 sampled points. The firstmethod used was our natural neighbor interpolationalgorithm. The results of our interpolation were thencompared to two of GRASS’ built in interpolationroutines, regularized spline with tension and inversedistance weighting. The differences between the re-sulting interpolated images and the original image

51

Page 57: Class of 2008 Senior Conference on Computational Geometry

Figure 2: This figure shows the original image, the image generated using our natural neighbors interpolation routine, GRASS’regularized spline with tension and GRASS’ inverse distance weighting from left to right, respectively.

Figure 3: This figure shows the difference images generated by subtracting the interpolated images from the original image. Thedifference images were then thresholded to only display values above a certain value. Their arrangement is identical to the tablebelow.

Threshold NNI RST IDW10 5.1% 13.5% 38.9%2 28.4% 44.4% 57.1%

Table 1: This table displays the percent of the interpolated image that differs from the original image by a defined threshold.

52

Page 58: Class of 2008 Senior Conference on Computational Geometry

were calculated within the appropriate region. Theresults were thresholded at varying levels and per-centages for estimated values lying outside of thethreshold were calculated in table 1.

For the given data set and sampled points, ournatural neighbor interpolation routine outperformedthe built in regularized spline with tension and in-verse distance weighting interpolation routines. Ata threshold of 10 units, only 5.1% of the pixels wereincorrectly estimated by our interpolation routinecompared with 13.5% and 38.9% incorrect respec-tively for the regularized spline with tension and in-verse distance weighting routines. At a lower thresh-old of 2 units, our routine still dramatically outper-formed the other two methods.

5 Discussion

All three methods of interpolation seemed to havetrouble estimating values in relatively similiar areas.This could result from the sample points being moresparse in these areas or the frequency of the data inthe original image being higher. Looking at the dif-ference images generated for each of the interpola-tion routines reveals that these trouble zones for in-terpolation are common across each method.

Due to a lack of robustness in our interpolationroutine, values at certain locations could not be es-timated which can be seen with the speckling in thedifference image. This leads to a greater percent in-correct which leads us to believe that our methodwould perform even better given a more robust im-plementation. The relative aesthetic advantage ofnatural neighbors interpolation over the regularizedspline with tension method and the inverse distanceweighting method is readily apparent. It seems thatthe natural neighbors method is much more capa-ble of dealing with a sparse set of points to interpo-late. This advantage could be because the tessela-tion underlying the interpolation routine extends be-yond the boundary of the eventual image, allowingfor better interpolation around the boundary of theimage relative to the other methods.

We chose not to include runtime comparisons be-cause our method took far longer to finish comparedto the others. Each time we ran the natural neighborsroutine, it required approximately an entire nightto complete. When GRASS interpolated using its

built-in routines, they both finished in about one sec-ond - negligible compared to our runtime. The ex-treme expedience of GRASS’ routine is likely dueto the sparse number of points that were interpolatedover.

6 Future Work

There are several improvments to our interpolationmethod that would greatly enhance the usefullnessof our implementation. The first necessary improve-ment centers around the degeneracies hinder theproper triangulation of the environment. Having amore robust Delaunay triangulation would removethe uninterpolated holes in the final image. Thiscould have also been worked around easily by av-eraging over the gaps in interpolation once the De-launay triangulation failed. Improving our point in-sertion method during the interpolation step wouldhelp cut down on some of the computational costsas well.

Creating a more extensive set of comparisons byvarying the number of points interpolated over, vary-ing the image frequency and complexity and in-cluding other interpolation methods would providea more accurate gauge of our interpolation method’srelative performance. A more comprehensive run-time comparison between methods would hopefullyhelp determine the practical usage of our interpola-tion method too.

53

Page 59: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 54–58,Computer Science Department, Swarthmore College

Bridge Detection By Road Detection

Jeff [email protected]

1 Introduction

It is useful to be able to determine water flowpatterns over terrain. The raw data for this taskis usually collected via airborne laser range find-ing, or LIDAR. This yields a point cloud rep-resenting the uppermost surface of the terrain.This cloud is interpolated onto a grid whereeach grid cell represents a square portion of theearth’s surface and it’s value is the average hightof that portion. Water flow patterns can then becalculated by looking at the direction of greatestdescent from each cell.

There is a problem, however, with local min-ima: cells from which there is no direction ofdescent. A common cause of this is bridges.The area over which a bridge passes shows up inthe digital elevation as being of a height greaterthan the surrounding terrain, but for the pur-poses of water flow it is not there. A water flowsimulation model will treat those grid cells asindicating a barrier, then, when there is in factno impediment to water flow. The goal of thisproject is to identify bridges to aid in the accu-rate determination of water flow patterns

2 Past Attempts and Related Work

A common method for dealing with local min-ima is flooding. In this all grid cells, exclud-ing those at the edges of the grid, where thereis no lower adjacent cell are raised up to theheight of their lowest neighbor. Repeating thiswill eventually rid the map of local minima.Identical results to this naive method can beachieved efficiently with a plane sweep algorithmusing topological persistence. (Edelsbrunner etal., 2000) Unfortunately, as Soille et. al. (Soilleet al., 2003) recognize, this loses information.Large flat areas, a common result of flooding,retain no information about their original lowpoints and do not provide information actual

flow patterns. One can still determine a pos-sible flow pattern through it, but that patternmay be totally different from the true one.

Soille et. al. were working with a very lowresolution (250m) grid elevation model to de-termine the water flow pattern for Europe andthe problems they ran into are somewhat dif-ferent from those encountered with higher res-olution data. When they encountered a localminimum, specifically, it was usually becausesome small stream or channel went undetectedwith the coarse sampling. Their replacement offlooding, carving paths from local minima to thenearest lower area, makes sense for dealing withthe missing channels but can of course get thingswrong. As the local minima in higher resolutiondata are much more likely to be products of hu-man terrain manipulation, generally in the cre-ation of roads, a system that tags and removesbridges ought to come closer to true water flowpaths than either flooding or carving.

For last year’s senior conference, Manfrediand Pshenichkin (Manfredi and Pshenichkin,2006) used a series of classifiers to tag bridges.They had a series of simple criteria that a win-dow had to match to be tagged a bridge. Theywere able to detect many of the larger bridgesbut missed some smaller ones, as well as complexstructures such as highway interchanges. Theirsystem also had a large number of false positives,detecting vegetation and other small artifacts asbridges. They rightly point out, however, thatthere is not too much harm in removing themalong with bridges as they are also not reallythere from the perspective of water flow.

One feature that they did not take advan-tage of is the tendency of bridges to be partof the road network. All of their classificationwork considered only the window that poten-tially contained the bridge. There has been some

54

Page 60: Class of 2008 Senior Conference on Computational Geometry

work on detection of of roads from LIDAR data(Clode et al., 2005), and while the final detectedroads may not be completely accurate, for thistask we don’t need perfection. Instead we justneed a rough idea of how likely a region is tobe part of the road network, which can then beinput to the bridge detection system.

3 Bridge Detection via RoadDetection

For this project I locate bridges in two stages.In the first I determine an approximate map ofthe road network, a map that should generallybe best in areas where the roads are in high re-lief. These areas correspond well to those wherebridges are likely, so it should be a well suitedmap for the task. Second I identify local min-ima that are near the computed roads in orderto tag road sections as bridges. Input consists ofa digital elevation model in the form of a grid offloats indicating hight. Output consists of fivesimilar models with floats indicating likelihoodof being a bridge, with calibration required forthe particular data set.

3.1 Road Detection

Roads are places in the terrain that are flat. Anyflat area could be part of a road. Areas that arelinearly flat, however, are much more likely to beroads. These would be areas where lines in onedirection are flat while in other directions arenot. Finally, roads tend not to bend sharply,so if there is a road in a direction we treat gridcells in that direction as being more likely to bea road.

This yields four indicators of bridge-likeness.All are computed on a series of cells represent-ing a potential road. For every cell c in the gridwe calculate 32 potential roads of a configurablelength running through that point. We then findwhich of those series of cells has the lowest av-erage change in steepness and call that the ‘bestroad’ centered on that cell. We also find theset of cells representing a line perpendicular tothe best road and call that the ‘perpendicular’.Each indicator acts on one of these two roadsand yields a value attributed to c.

1. Maximum gradient. For the best road, thelikelihood of it being actually a road is in-versely proportional to the greatest differ-ence between adjacent cells in the road.

2. Average gradient. Like the previous, exceptthe average absolute difference is calculatedinstead of the maximum one.

3. Maximum gradient of perpendicular. Thelikelihood of the best road being a road in-stead of just a cornfield is indicated by theunroadlikeness of the perpendicular. Thisis calculated as for the maximum gradient.

4. Standard deviation of gradient. Even whennot level, roads tend to be flat. That is,while they might sometimes have high gra-dients the (root mean square) standard de-viation should be low.

3.2 Local Minima

A maximally simple algorithm for determinationof local minima turns out to be quite effectiveas the data is not very noisy. For every gridcell, if no neighbor is smaller, then that cell isa local minimum. With worse data we mighthave a large number of these places and a smallamount of flooding might be worth while. Afterflooding an amount small enough not to overflowbridges we have not lost much flow informationand now should generally have local minima justin places where there are bridges.

4 Results

These four indicators were tested on two differ-ent examples of roads. Figures 1 and 2 showthe LIDAR-derived input grids. Figures 3 and 4show the maximum gradient indicator. Fig-ures 5 and 6 show the average gradient indicator.Figures 7 and 8 show the maximum gradient ofperpendicular indicator. Figures 9 and 10 showthe standard deviation of gradient indicator.

All four indicators appear to capture an ele-ment of bridge detection. One important aspectof these indicators is that they most strongly la-bel cells as indicating bridges when those cellsare in places where they would be incorrectly

55

Page 61: Class of 2008 Senior Conference on Computational Geometry

Figure 1: The input digital elevation model forthe Bridge test

Figure 2: The input digital elevation model forthe Interchange test

Figure 3: The maximum gradient indicator onthe Bridge

Figure 4: The maximum gradient indicator onthe Interchange

Figure 5: The average gradient indicator on theBridge

Figure 6: The average gradient indicator on theInterchange

56

Page 62: Class of 2008 Senior Conference on Computational Geometry

Figure 7: The maximum perpendicular of gra-dient indicator on the Bridge

Figure 8: The maximum perpendicular of gra-dient indicator on the Interchange

Figure 9: The standard deviation of gradient onthe Bridge

Figure 10: The standard deviation of gradienton the Interchange

impeding water flow. Actual use of these in-dicators on real data would require calibratingthem. This would require hand tagging a smallnumber of bridge examples and computationallydetermining the combination of these indicatorsthat best fits that data.

5 Conclusions

In this paper we have shown that several rel-atively simple functions analyzing a digital el-evation model can produce good indicators forclassification of cells as to their probability of be-ing a road. Further work would include a largescale test with calibration on a large digital ele-vation model. Implementation of a second passthat combined these local bridge likelihood es-timates into a road network could also improveaccuracy.

References

S. Clode, F. Rottensteiner, and P. Kootsookos.2005. Improving city model determination by us-ing road detection from lidar data. IAPRSSIS,XXXVI(3/W24):159–164.

H. Edelsbrunner, D. Letscher, and A. Zomorodian.2000. Topological persistence and simplification.In 41st IEEE Symposium on Foundations Com-puter Science, pages 454–463.

A. Manfredi and A. Pshenichkin. 2006. Bridgedetection from elevation data using a classi-

57

Page 63: Class of 2008 Senior Conference on Computational Geometry

fier cascade. http://web.cs.swarthmore.edu/∼adanner/cs97/f06/papers/bridge.pdf.

P. Soille, J. Vogt, and R. Colombo. 2003. Carvingand adaptive drainage enforcement of grid digi-tal elevation models. Water Resources Research,39(12).

58

Page 64: Class of 2008 Senior Conference on Computational Geometry

Appeared in: Proceedings of the Class of 2008 Senior Conference, pages 59–65,Computer Science Department, Swarthmore College

Image Stained Glass using Voronoi Diagrams

Michael [email protected]

Abstract

The geometrical concept of the Voronoidiagram was used to create an imagefilter providing a “stained glass” or mo-saic effect on an image. The Voronoidiagram was calculated by exploitingits dual relationship with the Delaunaytriangulation, which was in turn calcu-lated using a randomized incrementalalgorithm and stored in a DCEL. Var-ious methods were tried for selectingthe points, including sampling from adistribution built using edge detection.Sampling using edge detection distri-butions was shown to provide resultssignificantly better than uniform ran-dom sampling.

1 Introduction

Voronoi diagrams, when calculated on someset of N points in the 2d plane, segment thespace into regions surrounding every point. Thepolygonal regions are such that, within a regionsurrounding some point p0, the point p0 is closerto any point p in that region than any other ofthe N points included in the Voronoi diagram.The mapping between points in the plane andsurrounding regions is one to one.

This information has many uses, but one ofthe most obvious is processing an image for anartistic effect. The representation created byshading a Voronoi diagram on N points in theimage plane with colors from each sample pointcreates a “stained glass” or mosaic version of theimage. One of the key problems here is effectiveselection of the point set P for the Voronoi dia-gram.

2 Theory

2.1 Voronoi Diagrams

First, it is appropriate to examine the algo-rithms involved in the efficient calculation of aVoronoi diagram on a set of N points. The goalis a polygonal map of the plane consisting of aset of polygons surrounding the N points. Thepolygon surrounding a point p covers the areafor which p is the closest of the N points.

Given two points p and p′, we can create aVoronoi diagram by drawing a line perpendic-ular to the line pp′, intersecting pp′ at its mid-point. A Voronoi diagram with more points in-cludes many such lines, meaning that each poly-gon has straight edges consisting of line seg-ments which are sections of such perpendiculars.

Voronoi diagrams can be calculated directly,using for example the beach line algorithm fromthe work (Fortune, 1986). It is often simpler,however, to take advantage of the close rela-tionship that exists between the structure of theVoronoi diagram, and that of the Delaunay tri-angulation. (Guibas et al., 1990)

2.2 Delaunay Triangulation

A triangulation of some point set P is a planarsubdivision such that every polygon is a triangle(except for the unbounded face), and the ver-tices are points in P . A triangulation exists forevery point set P , as any bounded face can besplit up into triangles, and the unbounded faceis simply the complement of the convex hull forP . There are, of course, many different trian-gulations on any one set of points P . Giventwo triangles bordered by a common edge, it isalways possible to “flip” this edge such that itconnects the remaining two points, assuming thequadrilateral in question is convex. (Berg, 2000)

In a triangulation, it is undesirable to havesmall (sharp) angles. There is one triangula-

59

Page 65: Class of 2008 Senior Conference on Computational Geometry

tion, called the Delaunay triangulation, whichmaximizes the minimum angle and therefore isthe “best” triangulation. One simple way to findthis triangulation is to take an arbitrary trian-gulation and flip all illegal edges. Here, an il-legal edge is defined as an edge for which flip-ping will improve the triangulation: the orderedset of angles after flipping will be lexicographi-cally greater than the set before flipping. (Berg,2000) Of course, an edge can only be flipped inthe case of a convex quadralateral. An exampleof such an edge flip is shown on fig. 1.

It is not necessary to calculate all the anglesto determine the legality of an edge. Considertwo triangles abc and dbc that share an edge cb.Let C be the circle defined by abc. The edge ijis illegal if an only if the point d lines inside C.A proof can be found in (Berg, 2000).

Figure 1: An edge flip during the process ofcreating a Delaunay triangulation.http://www.cescg.org/CESCG-2004/web/Domiter-Vid/

A Delaunay triangulation can be constructedusing an incremental algorithm based on theabove. (Berg, 2000) Randomizing the point setP , add the points sequentially to the triangula-tion. Each time a point is added, start by trian-gulating the face containing the new point, andthen legalize edges recursively until all edges inthe triangulation are legal. Thus, the algorithmmaintains a correct Delaunay triangulation ofthe currently included points as an invariant.

2.3 Dual Transformation

The last step in constructing a Voronoi diagramon P is to convert the Delaunay triangulationon P into a Voronoi diagram. The structuresare related through duality.

A face in the Delaunay triangulation corre-sponds to a vertex of the Voronoi diagram, suchthat the location of the Voronoi vertex is thecenter of circumcircle for the (triangular) De-launay face. A vertex in the Delaunay trian-gulation corresponds to a face in the Voronoidiagram. This Voronoi face surrounds the De-launay vertex and represents the Voronoi cell forthis vertex. An edge in the Delaunay triangula-tion corresponds to a perpendicular edge in theVoronoi diagram. Two Voronoi vertices are con-nected if an only if the corresponding Delaunayfaces are adjacent. Figure 2 shows a Delaunaytriangulation and the corresponding Voronoi di-agram.

2.4 Point Sampling

One of the primary difficulties in using Voronoidiagrams to create stained glass effects is theselection of the point set P on which to buildthe diagram. Badly chosen points create a re-sult that captures none of the features in theoriginal image. In this project, the implemen-tation of fully automated, intelligent point se-lection was a key goal. Point selection can bedone, or adjusted, manually, however the needfor such intervention limits to applicability ofthe processing, and so was not studied here.

2.4.1 Naive Approaches

The simplest method for point selection usesa random sample of N points, distributed uni-formly within the boundaries of the image. Sucha method is of course very simple to implement,and also has an advantage that follows from itsuniformity. Because the distribution is uniform,the sizes of all the Voronoi cells will be relativelysmall, and thus a badly-colored Voronoi cell canhave only a limited size. The obvious issue withsuch a method is that it fails to account for theglobal features of an image. Random point se-lection, in practice, results in significantly dis-torted representations, especially in high-detailregions of the image, even at large N .

A grid-based point selection approach is an-other simple alternative. It has the advantage ofhighly uniform cell size, similar to that seen in areal mosaic. Like uniform random sampling, it

60

Page 66: Class of 2008 Senior Conference on Computational Geometry

Figure 2: Example of a Delaunay triangulation(top) and corresponding Voronoi diagram (bot-tom). The colors have no meaning.

suffers from a failure to account for the image’simportant features. Good representations canonly be obtained with fairly large N values.

2.4.2 Distribution Sampling

The earlier discussion of uniform sampling canbe generalized to an arbitrary probability distri-bution on the 2d plane of the image. The ques-tion, then, is what distribution Ps(x, y) on theimage pixels would, when sampled from for atotal of N points, produce the best representa-tion of the image. One quantitative criterionfor Ps(x, y) is the error between the colored,N-point Voronoi representation with samplingfrom Ps(x, y) and the real image. Such a value,however, does not necessarily reflect an aestheticjudgment of the colored Voronoi mosaic.

Edge detection appears as an efficient way toobtain a good Ps(x, y). Good mosaics are cre-ated when Voronoi cell edges fall on edges ofthe image. In order for this to happen, Voronoipoints must be located at equal distances froman edge line. It is undesirable for sampled pointsto fall on image edges themselves, as then theVoronoi cell surrounding that point is likely tobe badly colored, in a way that is not expressiveof key image features. The goal then, is to re-ceive a distribution that has symmetric and sig-nificant values around edges (leading to pointslikely sampled there), and low values directly onedges. Here, symmetric means that values areequal at equal distances along a perpendicularto the edge.

Such a distribution can be achieved usingbasic edge detection and blur filters. Specifi-cally, it is effective to use a distribution of theform Ps(x, y) = Pblur(x, y)− Psharp(x, y). Here,Psharp(x, y) comes from an sharp, or only veryslightly blurred, black and white edge detectionimage. Pblur(x, y) comes from an image pro-cessed with the same edge detection filter, fol-lowed by a significant (on the order of 5 pix-els) gaussian blur. The subtracted distributionhas low (dark) values immediately on the edges,and higher (lighter) values farther out from theedges. Due to the Gaussian blur, the lighter val-ues decrease in intensity with distance from theedge. Example distributions are presented on

61

Page 67: Class of 2008 Senior Conference on Computational Geometry

fig. 3. Note that the distribution along bothsides of an edge is symmetric, which is good forVoronoi point selection.

2.4.3 Related Work

In addition to considering the distributionPs(x, y), it is also possible to look instead at therepresentation error discussed earlier. This wasimplemented in the work (Dobashi et al., 2002).The authors started with a simple set of pointsleading to a hexagonal Voronoi diagram acrossthe image. They then adjust the locations ofthe Voronoi points to decrease the error (calcu-lated as difference in colors per pixel) betweenthe mosaic and real image representation. In thefirst phase, the entire set of points is moved inbatch, with each point moving somewhere in itssurrounding 8 pixels in such a way as to decreasethe error. This process continues until changesin error are below a threshold. The second phaseimplements finer adjustment where each site ismoved individually within its 8 pixels and theerror is recalculated each time.

While this approach appears to be effective,it requires significant computational power evenwith approximations, and the inclusion of man-ual adjustments in the paper makes it difficultto judge the effectiveness of such a method forpurely autoamted processing.

3 Methodology and Implementation

3.1 The Doubly-Connected Edge List

The most important component in an implemen-tation of the above algorithms is the data struc-ture used to represent the planar subdivision,whether it be the Delaunay triangulation or theVoronoi diagram. This data structure must sup-port several operations in a performant way. Itneeds to allow fast adding of points into an exist-ing triangulation structure, flipping of any par-ticular edge, and traversal of a face to find itsboundary edges.

The most common data structure used tomeet the above requirements is called a dou-bly connected edge list (DCEL) (Muller andPreparata, 1977). The structure contains sev-eral types of records: faces, edges, and vertices.

Figure 3: Examples of sampling distributionscreated using edge detection: Psharp(x, y) (top),Pblur(x, y) (middle), and Ps(x, y) (bottom).Edge detection and blur were implemented us-ing Apple Inc.’s Core Image processing filters.

62

Page 68: Class of 2008 Senior Conference on Computational Geometry

Edges are represented as half edges, storing apointer to their twin, adjacent face, and dou-bly linked list pointers allowing traversal of faceboundaries. A face record simply contains apointer to one half-edge along the face’s outerboundary (if it exists), and a set containing oneedge along every “hole” inside the face. TheDelaunay triangulation was constructed in aDCEL, and then the Delaunay DCEL was trans-formed into its dual, representing the Voronoidiagram.

The DCEL structure described here meets allthe requirements for storing a planar subdivi-sion. However, given a point, the structure doesnot provide a fast way to locate the face con-taining a point. For this purpose, an additionalDAG (Directed Acyclic Graph) data structureis layered on top of the DCEL.

3.2 DAG For Point Location

A Directed Acyclic Graph was constructed toprovide fast point location during triangulation.This point location was used during the first tri-angulation step, where it is necessary to findthe face containing the point being added. TheDAG algorithm used was described in (Berg,2000).

The leaf nodes of the DAG correspond to thecurrent triangulation. The other nodes corre-spond to previous triangles that existed ear-lier during the incremental triangulation pro-cess. When a point p is added, causing a splitof the face f , the leaf node representing f re-ceives 3 children for the newly created triangles.The DAG is also updated on edge flips, leadingto situations where a leaf node has more than 1pointer leading to it.

Using such a DAG structure, a point can belocated by starting from the root and navigatingdown the children, checking for containment inthe process.

4 Results and Discussion

The figures below present the results of con-structing mosaic representations for a test im-age.

The butterfly image was chosen as it is sim-ilar to example images used in (Dobashi et al.,

2002). It is extremely difficult to constructed au-tomated mosaic representations on images withmany human faces.

Looking at the images on figs 4 and 5, we cansee that the representation unsurprisingly im-proves with increasing N . It is clear that theimages generated using edge-detection distribu-tion based sampling retain significantly more ofthe key features, and also have a far cleanerappearance. This is due to points being sam-pled from a distribution symmetric around theedges, leading to Voronoi cell edges matching upwith image edges. The improvement using edge-detection distribution based sampling is partic-ularly evident with lower N values.

Significant artifacts still exist with edge-detection based sampling under lower pointcounts. This is because the correct distributiondoes not guarantee a good set of sampled pointswith low N , meaning that there are or empty ar-eas in the points. One approach to remedy thiswould be to adjust the distribution during thesampling process, subtracting discreet, 2d Gaus-sians from the distribution around each point asit is sampled. This would help prevent clustersof points and empty areas, improving uniformitywith low N .

Ideally, it would be effective to add equidis-tant points in pairs, one on each side of an edge.Doing this, however, requires knowledge of theedges as vector paths instead of as lighter pix-els in an image. Such an approach would notrequire sampling, and would probably work sig-nificantly better than a distribution-based ap-proach. It does, however, require a very differentkind of processing.

5 Conclusion

A stained glass / mosaic filter was successfullyimplemented based on Voronoi diagrams. Sev-eral solutions to the problem of sampling pointswere compared. While the solution by (Dobashiet al., 2002) provides good results, it requiresboth significant processing power and manualadjustment. A simple, fully automated sam-pling method was proposed based on subtractionof blurred distributions obtained using edge de-

63

Page 69: Class of 2008 Senior Conference on Computational Geometry

Figure 4: An example image (top), rendered us-ing distribution-based point selection. The dis-tribution was created by subtracting two blurrededge detection distributions, with a blur of 5.0and a blur of 1.0. The middle image has N =1000 points sampled, and the lower image hasN = 5000.

Figure 5: An example image (top), rendered us-ing uniformly random point selection. The mid-dle image has N = 1000 points sampled, and thelower image has N = 5000.

64

Page 70: Class of 2008 Senior Conference on Computational Geometry

tection. Results presented from application ofthis method, shown on figs. 4 and 5, are bothsignificantly cleaner than the mosaics createdusing random sampling, and more reflective ofkey image features.

References

Mark de Berg. 2000. Computational geometry: al-gorithms and applications. Springer, Berlin, 2ndrev. ed edition.

Y. Dobashi, T. Haga, H. Johan, and T. Nishita.2002. A method for creating mosaic images us-ing voronoi diagrams. In Proc. EUROGRAPHICS2002 Short Presentations, pages 341–348.

S Fortune. 1986. A sweepline algorithm for voronoidiagrams. In SCG ’86: Proceedings of the sec-ond annual symposium on Computational geome-try, pages 313–322, New York, NY, USA. ACM.

Leonidas J. Guibas, Donald E. Knuth, and MichaSharir. 1990. Randomized incremental construc-tion of delaunay and voronoi diagrams. In Pro-ceedings of the seventeenth international collo-quium on Automata, languages and programming,pages 414–431, New York, NY, USA. Springer-Verlag New York, Inc.

N. E. Muller and F. P. Preparata. 1977. Finding theintersection of two convex polyhedra. TechnicalReport ADA056889, U. Illinois at Urbana Cham-paign, Coordinated Science Lab, October.

65