You are on page 1of 10

A Tutorial On Convex Hulls

by Fan Chen Enrique Portillo Daniel Yehdego Paul Delgado

Convex Hull Tutorial 1. Introduction To explain what a convex hull is, we will explain what it means to be convex. A subset S of a space is titled convex if and only if for any pair of points p & q in the set S, the line section from p to q is enclosed completely in the set of S, as portrayed on the images below.



With this definition now we can explain what convex hull means, imagine in a two dimensional space there exists a finite set of points K={k1, k2, , kn} on a Cartesian plane. The set K contains a subset of points L={l1, l2, ,ln} where 2 L K, then L is the smallest set of points that embrace all the points in K, as portrayed in the images below.

A Hull, but not convex

Convex Hull

With these images we can explain what a convex hull is. The image in the left is not a convex hull because although all the points touching the red edges embrace all the points in the entire set, this set of points cannot be a convex hull because there are line segments between points that lie outside the outer boundary. The image on the right, on the other hand, is a convex hull because all line segments between points lie entirely in (or on) the boundary. Note that the purple edges indeed form the smallest set that embraces all the points in the entire set. There is an analogy that help understand this problem really easy. Imagine that the blue points in the images above are nails, then if you stretch a rubber band around them and release it the nails touching the rubber band is the convex hull set.

Figure 1.2 Rubber bands fitting tightly around a set of nails forms a convex hull

Our project is about finding ways to compute the convex hull for two, three, , N dimensions and applying it to real life applications like mesh generation, video games, path finding and many more problems. 2. Significance It is one of the most ubiquitous problems in mathematics and computer science. As one of the oldest problems addressed in the field of computational geometry, it lays the foundation for algorithms to many geometric and graph theoretic problems. Though algorithms (O(n^4)) have existed to compute a convex hull since medieval times, the first efficient algorithms didnt appear until the work of Chand & Kapur (1970). A wide variety of algorithms have been developed since then, including optimal algorithms (Chan, 1996). Furthermore, advancement of these algorithms has led to further development in other fields of mathematics and computer science. Among the applications of convex hulls include optimal path finding, collision detection / avoidance, linear programming, mesh generation, and pattern detection. The real world implications of these applications are detailed next. 2.1 Application: Cleaning Your Floors

Figure 2.1 The iRobot Roomba, with elapsed photography illustrating sweeping patterns. Source: Consumer Reports

The iRobot Roomba Vacuum Cleaning Robot is an innovative device which automatically removes cleans entire household. The ability to detect walls, tables, chairs, and other objects seems almost magical. But in fact, the ability to plot a path around obstacles is based upon the capacity to identify the boundaries around these obstacles.

Figure 2.1 - An optimal path around obstacles, using convex hulls.

In two dimensions, the convex hull of an object is simply the smallest polygon that fits tightly around the outer corners of an object. Moving around the room, the Roomba can detect these corners and the boundaries encompassing the obstacle. With this information, it can compute the optimal (minimal distance) path between any two points in any given room. This is especially important to determine the sweeping patterns necessary to clean the room, and the path to return to its charging station. 2.2 Application: Finding Your True Love The popular dating website claims to be the first relationship service on the web to use a scientific approach to match highly compatible singles (Heineman et al, 2008). Users of the service fill out a detailed survey, detailing 29 dimensions of compatibility. From these surveys, eHarmony searches a database of over 14 million users for a close match. With over 14 million users, one would think that the search for a close match in 29 dimensional space would be computationally expensive.

Figure 2.2 - A system of linear constraints, depicting compatibility preferences. To speed up the search, eHarmony can filter out users by using a convex hull. Each compatibility metric forms a linear constraint, limiting the range of possible closest matches.

The set of feasible solutions to these linear constraints forms a convex set whose boundaries form a convex hull. The points within the hull are all compatible matches to the user. Within this set, the eHarmony can search for the closest matches and new matches very quickly. 2.3 Application: Building a skyscraper Before any complex structure is built, an engineer must know with great certainty whether it will withstand the forces likely to act on it. Some structures, such as a skyscraper, are too large and expensive to risk building without near absolute certainty of its structural integrity. Instead, engineers employ a process called finite element analysis, where a mathematical model of the building is tested against these forces. The model is built by breaking the complex shape of the building into a set of smaller, simpler shapes called a finite element mesh.

Figure 2.3 - Finite element mesh representing a beam bending under stress forces.

The convex hull plays an important role in the generation of a finite element mesh. By sampling nodal points in a p dimensional space, one can projected these points onto a p+1 dimensional paraboloid. Once the convex hull of these p+1 dimensional points is found, the lower part of the hull can be project back to p dimensions to form a p dimensional mesh.

Figure 2.4 - 2D triangular mesh generated from the lower convex hull on a paraboloid.

2.4 Application: Getting a Speeding Ticket

Traffic cameras are often employed to give moving violations to unsuspecting drivers, especially in certain hotspots. In some cities, the number of traffic violations can be quite large, and manually sorting through each image to determine the exact license plate number can be quite tedious. Automatic pattern recognition algorithms are used to automatically determine not only the license plate number, but also the state logo and registration number.

To determine the letter from a picture, a convex hull of the character in each position is obtained. From these hulls, another algorithm determines the empty spaces within the hull and matches it against a template shape corresponding to the specific character or number. The algorithms to accomplish this were developed in the 1970s (Toussaint, 1978) and were first implemented traffic control technology in the late 1980s (Gonzalez et al, 1989). With so many applications of convex hulls, scientists and mathematicians have sought efficient algorithms to compute them. The following section describes these algorithms in detail. 3. Existing Algorithms In Computational geometry, numerous algorithmic techniques are proposed for computing the convex hull of a finite set of points, with various computational complexities. The computational complexity of the corresponding algorithms is usually estimated in terms of n, the number of input points, and h, the number of points on the convex hull. It is interesting to note that many algorithms for computing a convex hull are analogous to basic sorting algorithms. A brief survey of these algorithms are described below. 3.1 Grahams Scan Given a set of points on the plane, Graham's scan computes their convex hull. The algorithm works in three phases: 1. Find an extreme point. This point will be the pivot, is guaranteed to be on the hull, and is chosen to be the point with largest y coordinate. 2. Sort the points in order of increasing angle about the pivot. We end up with a star-shaped polygon (one in which one special point, in this case the pivot can "see" the whole polygon).

3. Build the hull, by marching around the star-shaped poly, adding edges when we make a left turn, and back-tracking when we make a right turn.

Figure 3.1 Grahams Scan walks along the boundary, making right turns along the way

3.2 Jarviss March (Gift Wrapping) This is perhaps the most simple-minded algorithm for the convex hull, and yet in some cases it can be very fast. The basic idea is as follows: 1. Start at some extreme point, which is guaranteed to be on the hull. 2. At each step, test each of the points, and find the one which makes the largest right-hand turn. The point has to be the next one on the hull. The simplest (although not the most time efficient in the worst case) algorithm in the plane was proposed by R.A. Jarvis in 1973. It is also called gift wrapping algorithm. It has O(nh) time complexity, where n is the number of points in the set, and h is the number of points in the hull, in the worst cases the complexity is O(n^2).

Figure 3.2 Execution of Jarviss March

3.3 - Divide and Conquer

The divide-and-conquer algorithm is an algorithm for computing the convex hull of a set of points in two or more dimensions. The algorithm runs in O(nlogn) time, and is based on the divide and conquer design technique. It can be viewed as a generalization of the Merge Sort sorting algorithm. It begins by sorting the points by their x coordinate, in O(nlogn) time. The remainder of the algorithm is shown below. 1. If |P|<=3 then compute the convex hull by brute force in O(1) time and return. 2. Otherwise, partition the point set P into two sets L and R, where L consists of half the points with the lowest x coordinates and R consists of half of the points with the highest x coordinates. 3. Recursively compute HL = CH(L) and HR = CH(R). 4. Merge the two hulls into a common convex hull, H, by computing the upper and lower tangents for HL and HR and discarding all the points lying between these two tangents.

Figure 3.3 The divide and conquer approach merges two sub-convex hulls into one.

3.4 - Quick Hull Like the divide-and-conquer algorithm can be viewed as a sort of generalization of Merge-Sort, the Quick-Hull algorithm can be thought of as a generalization of the Quick-Sort sorting procedure. Like Quick-Sort, this algorithm runs in O(nlogn) time for favourable inputs but can take as long as O(n2) time for unfavourable inputs. The idea behind Quick-Hull is to discard points that are not on the hull as quickly as possible. Quick-Hull begins by computing the points with the maximum and minimum, x- and ycoordinate. Clearly these points must be on the hull, and connect the four points we get a convex quadrilateral, all the points within this quadrilateral can be eliminated from further consideration. All of this can be done in O(n) time.

Figure 3.4 Quck Hull successively eliminates points on the interior of the hull

3.5 Incremental The incremental convex hull algorithm is usually relatively simple to implement, and generalize well to higher dimensions. This algorithm operates by inserting points one at a time and incrementally updating the hull. If the new point is inside the hull there is nothing to do. Otherwise, we must delete all the edges that the new point can see. Than we connect the new point to its two neighbour points to update the hull. By repeating this process for the rest points outside the hull, finally, we get the convex hull for the points set

Figure 3.5 Incremental Algorithm creates the hull, one point at a time.

The randomized version of the algorithm operates as follows. Permute the points randomly, let P = (p0, p1,..., pn-1) be this sequence. Let H2 = CH(p0, p1, p2) (a triangle). For i running from 3 to n1, insert pi into the existing hull Hi-1. As with other randomized algorithms, the expected running time depends on the random order of insertion, but is independent of the point set. By a backwards analysis, we can know its running time is O(nlogn). A summary of the runtime of these, and other existing algorithms is shown in Figure 3.1

Algorithm Brute Force Graham Scan Jarvis March QuickHull Divide-and-Conquer Monotone Chain Incremental Chan's algorithm 4. Proposed Projects

Running Time O(n3) O(nlog n) O(nh) O(nh) O(nlog n) O(nlog n) O(nlog n) O(nlog h)

Discovered By Graham, 1972 Jarvis, 1973 Eddy, 1977 ; Bykat, 1978 Preparata & Hong, 1977 Andrew, 1979 Kallay, 1984 Timothy Chan, 1993

Figure 3.6 Summary of Asymptotic Behaviors of existing Convex Hull Algorithms

Three of our group members will work on developing and testing new algorithms in arbitrary dimensions, while the fourth member works on an application on the convex hull. New algorithms will be developed by merging two existing algorithms into a hybrid program that may, in theory, lead to faster performance than either algorithm individually. The application of convex hulls to be studied is that of creating triangular finite element meshes in 2 dimensions by projecting the lower convex hull of a point set on a paraboloid. The work of each individual in our group is divided as follows: Fan Chen - Merging QuickHull and Incremental algorithms into a hybrid program. Enrique Portillo - Merging Quick Hull and Gift Wrapping algorithms into a hybrid program. Daniel Yehdego Merging QuickHull and Divide and Conquer algorithms into a hybrid program. Paul Delgado - Generating convex hulls in 3D to generate triangular meshes in 2D. If time permits, he will also use 4D convex hulls to create 3D tetrahedral meshes using an analogous technique.