2D Convex Hulls and Extreme Points( Convex Hull Algorithms) CGAL 4.13 -User Manual

Introduction

A subset SR2 is convex if for any two points p and q in the set the line segment with endpoints p and q is contained in S. The convex hull of a set S is the smallest convex set containing S. The convex hull of a set of points P is a convex polygon with vertices in P. A point in P is an extreme point (with respect to P) if it is a vertex of the convex hull of P. A set of points is said to be strongly convex if it consists of only extreme points.html

This chapter describes the functions provided in CGAL for producing convex hulls in two dimensions as well as functions for checking if sets of points are strongly convex are not. There are also a number of functions described for computing particular extreme points and subsequences of hull points, such as the lower and upper hull of a set of points.算法

 一個點集SR2,若是對於點集中任意兩個點 p 和 q ,以p 和q 爲端點的線段被包在這個子集(構成的多邊形)中,咱們稱S是凸的(convex )。一個點集S的凸包(convex hull )是包含S的最小凸集。一個點集P的凸包(convex hull )是一個以P中的點爲頂點的多項式。若是P中一個點是其凸包(convex hull )中的一個頂點,則該點是一個P的極點(extreme point )。一個點集被稱爲強凸的(strongly convex )若是它只包含極點。
ide

本章描述CGAL提供的在2維中生成凸包(convex hulls)的函數和用於檢查點集是否強凸的(strongly convex )的函數。還有一些函數用於計算特定極點以及包(hull)生成以後的其餘函數,如點集的下半包和上半包。函數

saarhull.png

Convex Hull

CGAL provides implementations of several classical algorithms for computing the counterclockwise sequence of extreme points for a set of points in two dimensions (i.e., the counterclockwise sequence of points on the convex hull). The algorithms have different asymptotic running times and require slightly different sets of geometric primitives. Thus you may choose the algorithm that best fits your setting.post

Each of the convex hull functions presents the same interface to the user. That is, the user provides a pair of iterators, first and beyond, an output iterator result, and a traits class traits. The points in the range [firstbeyond) define the input points whose convex hull is to be computed. The counterclockwise sequence of extreme points is written to the sequence starting at position result, and the past-the-end iterator for the resulting set of points is returned. The traits classes for the functions specify the types of the input points and the geometric primitives that are required by the algorithms. All functions provide an interface in which this class need not be specified and defaults to types and operations defined in the kernel in which the input point type is defined.測試

Given a sequence of n input points with h extreme points, the function convex_hull_2() uses either the output-sensitive O(nh) algorithm of Bykat [5] (a non-recursive version of the quickhull [4] algorithm) or the algorithm of Akl and Toussaint, which requires O(nlogn) time in the worst case. The algorithm chosen depends on the kind of iterator used to specify the input points. These two algorithms are also available via the functions ch_bykat() and ch_akl_toussaint(), respectively. Also available are the O(nlogn) Graham-Andrew scan algorithm [3][9] (ch_graham_andrew()), the O(nh) Jarvis march algorithm [8] (ch_jarvis()), and Eddy's O(nh)algorithm [6] (ch_eddy()), which corresponds to the two-dimensional version of the quickhull algorithm. The linear-time algorithm of Melkman for producing the convex hull of simple polygonal chains (or polygons) is available through the function ch_melkman().ui

CGAL提供了2d空間中的幾種典型的算法來計算逆時針序的極點集(即凸包的逆時針序的點集)。各個算法有着不一樣的漸近線時間效率,須要稍有不一樣的幾何元語集合。這樣你能夠選擇最適合你的算法。this

每一個計算凸包的函數提供了相同的接口。用戶提供一對 iterator , first和beyond,一個輸出iterator result, 和一個traits類 traits。在範圍[firstbeyond)的點用於定義輸入的須要計算其凸飯點集。逆時針序的極點集被寫入了始於result的序列中,且最後一個點的(past-the-end)iterator被 返回。traits 類用於肯定輸入點的數的類型和算法所要求的幾何元語集合。全部的函數提供了一個接口,使用這個接口時這個類不須要指定,輸入點的缺省類型(All functions provide an interface in which this class need not be specified and defaults to types and operations defined in the kernel in which the input point type is defined)。atom

給定n個輸入點的序列,其中有h個極點,spa

(1)Bykat 算法(output-sensitive O(nh) algorithm of Bykat, 一種quickhull算法的非迴歸版本),

(2)Akl 和 Toussaint算法,它們最差的狀況下須要O(nlogn)時間。算法的選擇依賴於指定的輸入點集。這兩個算法也能夠經過ch_bykat() 和 ch_akl_toussaint()函數分別獲得。

(3)Graham-Andrew 掃描算法(Graham-Andrew scan algorithm , (ch_graham_andrew()),)其算法時間爲O(nlogn) 。

(4)Jarvis march算法(Jarvis march algorithm,  (ch_jarvis()), O(nh)

(5)Eddy'算法(Eddy's O(nh)algorithm,ch_eddy()),它對應於quickhull算法的2維版本。

(6)Melkman 算法提供線性時間,爲簡單多邊形鏈計算凸包(函數ch_melkman()

Example using Graham-Andrew's Algorithm

In the following example a convex hull is constructed from point data read from standard input using Graham_Andrew algorithm. The resulting convex polygon is shown at the standard output console. The same results could be achieved by substituting the function ch_graham_andrew() by other functions such as ch_bykat().

下面的例子使用標準輸入點數據生成凸包,使用ch_graham_andrew()算法。其結果凸多邊形輸出到標準輸出窗口。換函數ch_bykat()可獲得相同結果。
File Convex_hull_2/ch_from_cin_to_cout.cpp

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/ch_graham_andrew.h>
 
typedef K::Point_2 Point_2;
 
int main()
{
CGAL::set_ascii_mode(std::cout);
std::istream_iterator< Point_2 > in_start( std::cin );
std::istream_iterator< Point_2 > in_end;
std::ostream_iterator< Point_2 > out( std::cout, "\n" );
CGAL::ch_graham_andrew( in_start, in_end, out );
return 0;
}

Extreme Points and Hull Subsequences

In addition to the functions for producing convex hulls, there are a number of functions for computing sets and sequences of points related to the convex hull.

The functions lower_hull_points_2() and upper_hull_points_2() provide the computation of the counterclockwise sequence of extreme points on the lower hull and upper hull, respectively. The algorithm used in these functions is Andrew's variant of Graham's scan algorithm [3][9], which has worst-case running time of O(nlogn).

There are also functions available for computing certain subsequences of the sequence of extreme points on the convex hull. The function ch_jarvis_march() generates the counterclockwise ordered subsequence of extreme points between a given pair of points and ch_graham_andrew_scan() computes the sorted sequence of extreme points that are not left of the line defined by the first and last input points.

Finally, a set of functions (ch_nswe_point()ch_ns_point()ch_we_point()ch_n_point()ch_s_point()ch_w_point()ch_e_point()) is provided for computing extreme points of a 2D point set in the coordinate directions.

另外,還有一些函數用於與凸包相關的點集計算。

(1)lower_hull_points_2() 和 upper_hull_points_2()用於計算逆時針序的下半包和上半包。這個算法是Graham's scan algorithm的Andrew'變種,最差爲O(nlogn);

(2)還有一些函數用於計算已經生成的凸包中的極點的子序列(subsequence )的函數。ch_jarvis_march()用於計算給定兩點之間的逆時針序的極點的子序列,ch_graham_andrew_scan()用於生成一個逆時針排列的極點的子序列,這個子序列的全部極點均不在給定輸入點的左側。(computes the sorted sequence of extreme points that are not left of the line defined by the first and last input points.)

(3)最後,一個函數集用於計算給定座標方向( coordinate directions)的極點集(ch_nswe_point()ch_ns_point()ch_we_point()ch_n_point()ch_s_point()ch_w_point()ch_e_point()).

Traits Classes

Each of the functions used to compute convex hulls or extreme points is parameterized by a traits class, which specifies the types and geometric primitives to be used in the computation. There are several implementations of 2D traits classes provided in the library. The class Convex_hull_traits_2 corresponds to the default traits class that provides the types and predicates presented in the 2-dimensional CGAL kernel in which the input points lie. The class Convex_hull_constructive_traits_2 is a second traits class based on CGAL primitives but differs from Convex_hull_traits_2 in that some of its primitives reuse intermediate results to speed up computation.

In addition, the 2D and 3D Linear Geometric Kernel provides three projective traits classes (Projection_traits_xy_3Projection_traits_xz_3, and Projection_traits_yz_3), which may be used to compute the convex hull of a set of three-dimensional points projected into each of the three coordinate planes.

每一個計算凸包或極點的函數都被一個traits類參數化,這個traits指定了計算中使用的類型和幾何元語。庫中有幾個2D traits類。

(1)Convex_hull_traits_2 類對應於2D CGAL內核中缺省的traits 類,提供了類型和斷定(The class Convex_hull_traits_2 corresponds to the default traits class that provides the types and predicates presented in the 2-dimensional CGAL kernel in which the input points lie. )。

(2)Convex_hull_constructive_traits_2類是第二個基於CGAL元語的traits類,與 Convex_hull_traits_2不一樣的是,它的元語複用了中間結果來加速計算。

(3)另外, 2D 和3D Linear Geometric Kernel 提供了三個投射traits類(projective traits classes ),分別是Projection_traits_xy_3Projection_traits_xz_3, 的Projection_traits_yz_3,用於計算3維點投射到三個座標平面的點集的凸包。

Convexity Checking

The functions is_ccw_strongly_convex_2() and is_cw_strongly_convex_2() check whether a given sequence of 2D points forms a (counter)clockwise strongly convex polygon. These are used in postcondition testing of the two-dimensional convex hull functions.

函數is_ccw_strongly_convex_2() 和is_cw_strongly_convex_2() 檢查給定一個序列的2D點集是否造成一個(順)逆時針的強凸多邊形。這些函數用於對2維凸包函數的後置條件進行測試。

相關文章
相關標籤/搜索