732 Chapter 13 Computational Geometry Topics
new edges are V , P
U
and V , P
L
. Because the edge P
L
, P
L
is entirely on the lower
tangent, that edge can also be discarded and replaced by the new edge V , P
L
. If this
step is not performed, the final hull of the points will contain collinear edges. Such
edges can be collapsed in a postprocessing phase.
Determining whether or not an edge is visible is just a matter of computing or-
dering of three points, the end points of the directed edge and the point V . In Figure
13.34, the directed edge P
L
, A is visible to V . The triangle V , P
L
, A is clock-
wise ordered. The directed edge P
U
, B is not visible to V . The triangle V , P
U
, B
is counterclockwise ordered. Only P
L
of the directed edge P
L
, P
L
is visible to V .
The triangle V , P
L
, P
L
is degenerate (a line segment). The cases are quantified by
a dot product test. Let Q
0
, Q
1
be a directed hull edge and define
d = Q
1
− Q
0
and
n =−
d
⊥
, an inner-pointing normal to the edge. The edge is visible to V whenever
n ·(V − Q
0
)<0 and not visible to V whenever n · (V − Q
0
)>0. If the dot product
is zero, then only the closest end point of the edge is visible to V . End point Q
0
is
closest if
d · (V − Q
0
)<0; end point Q
1
is closest if
d · (V − Q
0
)>
d
2
.
The order of the algorithm depends on the amount of work that must be done
in the merge step. In the worst case, each input point to
Merge is outside the current
hull, and the tangent points are found by iterating over all hull vertices and testing
the dot product conditions. The order is O(n
2
). Because of this, one hope is that the
initial points are ordered in such a way that most of the time the input point is in
the current hull. This is the idea of randomized algorithms, where the input points are
randomly permuted in an attempt to generate a large partial hull from the first few
input points. When this happens, many of the remaining points most likely will fall
inside the current hull. Because the relationship between the next input point and
the current hull is not known, a search over the hull vertices must be made to find
the tangent points. A randomized algorithm is discussed in de Berg et al. (2000). The
same idea occurs in Section 13.11 when finding the minimum-area circle containing
a point set.
A nonrandomized approach that guarantees an O(n log n) algorithm actually
sorts the points so that the next input point is outside the current hull! The sort
of the points dominates the algorithm time. The points are sorted using the less-
than operation: (x
0
, y
0
)<(x
1
, y
1
) when x
0
<x
1
or when x
0
= x
1
and y
0
<y
1
.The
points are initially sorted in place for the discussion. In an implementation, the points
are most likely sorted into separate storage so as not to change the original point
set. After the sort, duplicate points can be eliminated. The sort and comparison can
be implemented to use fuzzy floating-point arithmetic to handle those cases where
floating-point round-off errors might cause two equal points (in theory) to be slightly
different from each other.
The algorithm has information about the relationship between the next input and
the current hull so that the tangent construction is only O(n) over the total lifetime of
the loop in the pseudocode. In particular, the last-inserted hull vertex is the starting
point for the search for the points of tangency and may already be a tangent point
itself. Although any single search might require visiting a significant number of points