Better description for Andrew's algorithm
This commit is contained in:
parent
93bb7d1ed9
commit
a8723ccfb8
|
@ -396,21 +396,20 @@ an easy way to
|
||||||
construct the convex hull for a set of points
|
construct the convex hull for a set of points
|
||||||
in $O(n \log n)$ time.
|
in $O(n \log n)$ time.
|
||||||
The algorithm constructs the convex hull
|
The algorithm constructs the convex hull
|
||||||
in two steps:
|
in two parts:
|
||||||
first the upper hull and then the lower hull.
|
first the upper hull and then the lower hull.
|
||||||
Both steps are similar, so we can focus on
|
Both parts are similar, so we can focus on
|
||||||
constructing the upper hull.
|
constructing the upper hull.
|
||||||
|
|
||||||
We sort the points primarily according to
|
First, we sort the points primarily according to
|
||||||
x coordinates and secondarily according to y coordinates.
|
x coordinates and secondarily according to y coordinates.
|
||||||
After this, we go through the points and always
|
After this, we go through the points and
|
||||||
add the new point to the hull.
|
add each point to the hull.
|
||||||
After adding a point we check using cross products
|
Always after adding a point to the hull,
|
||||||
whether the tree last point in the hull turn left.
|
we make sure that the last line segment
|
||||||
If this holds, we remove the middle point from the hull.
|
in the hull does not turn left.
|
||||||
After this we keep checking the three last points
|
As long as this holds, we repeatedly remove the
|
||||||
and removing points, until the three last points
|
second last point from the hull.
|
||||||
do not turn left.
|
|
||||||
|
|
||||||
The following pictures show how
|
The following pictures show how
|
||||||
Andrew's algorithm works:
|
Andrew's algorithm works:
|
||||||
|
|
Loading…
Reference in New Issue