The convex hull is a ubiquitous structure in computational geometry. Even though it is a useful tool in its own right, it is also helpful in constructing other structures like Voronoi diagrams, and in applications like unsupervised image analysis.
We can visualize what the convex hull looks like by a thought experiment. Imagine that the points are nails sticking out of the plane, take an elastic rubber band, stretch it around the nails and let it go. It will snap around the nails and assume a shape that minimizes its length. The area enclosed by the rubber band is called the convex hull of . This leads to an alternative definition of the convex hull of a finite set of points in the plane: it is the unique convex polygon whose vertices are points from and which contains all points of .
The set of green nails are the convex hull of the collection of the points.
A few of the applications of the convex hull are:
Collision avoidance: If the convex hull of a car avoids collision with obstacles then so does the car. Since the computation of paths that avoid collision is much easier with a convex car, then it is often used to plan paths.
Smallest box: The smallest area rectangle that encloses a polygon has at least one side flush with the convex hull of the polygon, and so the hull is computed at the first step of minimum rectangle algorithms. Similarly, finding the smallest three-dimensional box surrounding an object depends on the 3D-convex hull.
Shape analysis: Shapes may be classified for the purposes of matching by their "convex deficiency trees", structures that depend for their computation on convex hulls.
Convexity A set is convex if and implies that the segment . This can be taken as the primary definition of convexity. Note that this definition does not specify any particular dimensions for the points, whether is connected, bounded, unbounded, closed or open.
We have now developed an intuitive definition of the convex hull. Let us now look at more precise definitions of the convex hull.
The convex hull of a set of points is the intersection of all half-spaces that contain . A half space in two dimensions is the set of points on or to one side of a line. This notion generalizes to higher dimensions. A half-space is the set of points on or to one side of a plane and so on.
Note that the convex hull of a set is a closed "solid" region which includes all the points on its interior. Often the term is used more loosely in computational geometry to mean the boundary of this region, since it is the boundary that we compute, and that implies the region.
Graham's scan algorithm is a method of computing the convex hull of a finite set of points in the plane with time complexity .The algorithm finds all vertices of the convex hull ordered along its boundary .
The procedure in Graham's scan is as follows:
Find the point with the lowest coordinate. If there are two points with same value, then the point with smaller x coordinate value is considered. Put the bottom-most point at first position.
Consider the remaining points and sort them by polar angle in counterclockwise order around points. If polar angle of two points is same, then put the nearest point first.
Create an empty stack and push points, points and points to.
Process remaining points one by one. Do the following for every point ‘points’
Keep removing points from stack while orientation of following points is not counterclockwise (or they don’t make a left turn).
- Point next to top in stack
- Point at the top of stack
Push points[i] to S
A pseudocode implementation of the above procedure is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Runtime of the graham's scan
• Step 1: + for setting up and sorting
• Step 2: constant time for pushing items into the stack
• Step 3: each point gets pushed once withing the for loop
• Step 4 for popping within the loop , each point gets popped once at most
• Total running time:
The bottleneck of the algorithm is sorting the points by polar angles. This operation as we have seen requires time.
Identifying extreme edges of the convex hull is somewhat easy. An edge is extreme if every point on is on or to one side of the line determined by the edge. It seems easiest to detect this by treating the edge as directed, and specifying one of the two possible directions as determining the "side". Let the left side of a directed edge be inside. Phrased negatively, a directed edge is not extreme if there is some point that is not left of it or on it. This is the formulation we use in the pseudo-code below.
1 2 3 4 5 6
This algorithm clearly runs in time because there are three nested loops, each costing .
A minor variation of the Extreme Edge algorithm will both improve it by a factor of and output the points in the order in which they occur around the hull boundary. The idea is to use on extreme edge as an anchor for finding the next. This works because we know that the extreme edges are kinked into a convex polygon. Since the most vertices this polygon can have is , the number of extreme edges is . The anchored search will only explore candidates, rather than candidates in our extreme edge algorithm above.