转载:平面点集凸壳算法大全(英文)

2023-11-09 18:00

本文主要是介绍转载:平面点集凸壳算法大全(英文),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载自:http://www.tcs.fudan.edu.cn/rudolf/Courses/Algorithms/Alg_cs_07w/Webprojects/Zhaobo_hull/#section26
  1. Introduction
  2. Algorithms
    • Brute force
    • Graham's scan
    • Jarvis' march(gift wrapping)
    • Divide-and-Conquer
    • Quick hull
    • Chan's algorithm(output sensitivity)
    • Incremental
    • Monotone Chain
    • Running time comparision
  3. Related algorithms
    • Onion-peeling
    • Onion triangulations
    • Point Location
  4. References

1. Introduction

convexhull

We are given a set P of n points in the plane. We can define the convex hull of P, that is CH(P), as the largest convex polygonwhose vertices are all points in P, or the unique convex polygon that contains P and whose vertices are all points in P. There are two main properties of convex hulls:

  • One of these properties is that all of the points in the final polygon must be indented outwards, or more formally, convex. If any points are concave, there exists a better path by excluding that point, and drawing a direct line between its two neighbor points, which reduces the overall perimeter point count by one. This property is exploited by Graham's Scan, a pioneering algorithm for convex hulls covered later in the paper.

  • Another important property is that the most extreme point on any axis is part of the convex hull. This fact is apparent if you consider an example in which an extreme point is not in the convex hull. This would mean the perimeter of the convex hull passes through a point less extreme than that point. However, it is then obvious that the extreme point would not be included in the enclosed set, thus voiding a fundamental characteristic of convex hulls. This property is used by a number of algorithms because they rely on information computed from an initial point in the convex hull[1].

Computing a convex hull (or just "hull") is one of the first sophisticated geometry algorithms, and there are many variations of it. The most common form of this algorithm involves determining the smallest convex set (called the "convex hull") containing a discrete set of points.

The most popular algorithms are the "Graham scan" algorithm [Graham, 1972] and the "divide-and-conquer" algorithm [Preparata & Hong, 1977]. Implementations of both these algorithms are readily available (see [O'Rourke, 1998]). Both are O(n log n) time algorithms, but the Graham has a low runtime constant in 2D and runs very fast there. However, the Graham algorithm does not generalize to 3D and higher dimensions whereas the divide-and-conquer algorithm has a natural extension. We do not consider 3D algorithms here (see [O'Rourke, 1998] for more information)[2].


2. Algorithms


 

If the java applet could not run normally, please install SUN JRE 1.4 or higher version.



2.1 Brute force

This is a simple O(n3) convex hull algorithm, which operates by considering each ordered pair of points (p, q),and then determining whether all the remaining points of the set lie within the half-plane lying to the right of thedirected line from p to q.

Back to home

2.2 Graham's scan
simplepolygon

The Graham's Algorithm first explicitly sorts the points in O(nlogn) and then applies a linear-time scanning algorithm to finish building the hull.

We start Graham's scan by finding the leftmost point l. We connect l with all the other points, then according to the angles in polar coordinates of the lines, we connect the points in couterclockwise order, starting and ending at l. Now we get a simple polygon with n vertices.

To change this polygon into convex hull, we apply the three-penny algorithm,the scanning phase takes O(n) time altogether. So the total time is O(nlogn)

Back to home

2.3 Jarvis's march(gift wrapping)
Jarvis'march

Jarvis's match algorithm is like wrapping a piece of string around thepoints. It starts by computing the leftmost point l, since we know that the left most point must be a convex hull vertex.This processwill take linear time.Then the algorithm does a series of pivoting steps to find each successive convex hull vertex untill the next vertex is the original leftmost point again.

The algorithm find the successive convex hull vertex like this: the vertex immediately following a point p is the point that appears to be furthest to the right to someone standing atp and looking at the other points. In other words, if q is the vertex following p, and r is any other input point, then thetriple p, q, r is in counter-clockwise order. We can find each successive vertex in linear time by performing a series of O(n) counter-clockwise tests.

Since the algorithm spends O(n) time for each convex hull vertex, the worst-case running time is O(n2). However, if the convex hull has very few vertices, Jarvis's march is extremelyfast. A better way to write the running time is O(nh), where h is the number of convex hull vertices. In the worst case, h = n, and we get our old O(n2) time bound, but in the best case h = 3, and the algorithm only needs O(n) time. This is a so called output-sensitive algorithm, the smaller the output, the faster the algorithm.

Back to home

2.4 Divide-and-Conquer

This is another O(nlogn) time algorithm , which is based on the divide and conquer design technique. It can be viewed as a generalization of the MergeSort sorting algorithm. It begins by sorting the pointsby their x coordinate, in O(nlogn) time. The remainder of the algorithmis 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.

Back to home

2.5 Quick hull
quickhull

Like the divide-and-conquer algorithm can be viewed as a sort of generalization of MergeSort, the QuickHull algorithm can be thought of as a generalization of the QuickSort sorting procedure. Like QuickSort , this algorithm runs in O(nlogn) time for favorable inputs but can take as long as O(n2) time for unfavorable inputs.

The idea behind QuickHull is to discard points that are not on the hull as quickly as possible. QuickHull begins by computing the points with the maximum and minimum, x- and y- coordinate. Clearly thesepoints must be on the hull, and connect the four points we get a convex quadrilateral, all the points within this quadrilateral canbe eliminated from further consideration. All of this can be done in O(n) time.



Back to home

2.6 Chan's algorithm(output sensitivity)
chan_one

This is another output-sensitive algorithm, which was discoverd by Timothy Chan in 1993, the running time is O(nlogh). Chan's algorithm involves cleverly combining two slower algorithms, that is , Graham's scan and Jarvis's March,to form an algorithm that is faster than either one.

First suppose we know there are h points on the convex hull, this algorithm starts by shattering the input points in n/h arbitray subsets, each of size h, and computing the convex hull of each subset using (say) Graham's scan. This much of the algorithm requires O((n/h)hlogh) = O(nlogh) time.

Once we have the n/h subhulls, we follow the general outline of Javis'smarch, wrapping a string around the n/h subhulls. Start with the leftmost input point l, starting with p = l we successively find the convex hull vertexes in counter-clockwise order until we return back to the original leftmost point again.

The successor of p must lie on a right tangent line between p and one of the subhulls, a line from p through a vertex of the subhull, such that the subhull lies completely on the right side of the line from p's point of view. We can find the right tangent line between p and any subhull in O(logh) time using a variant of binary search. Since there are n/h subhulls, finding the successor of p takes O((n/h)logh) time together. Since there are h convex hull edges, and we find each edge in O((n/h)logh) time, the overall running time of the algorithm is O(nlogh).

Unfortunately, this algorithm only takes O(nlogh) time if we know the value of h in advance. So how do we know h's value? Chan's trick is to guess the correct value of h, let's denote the guess by h'.Then we shatter the points into n/h' subsets of size h', compute their subhulls, and then find the first h' edges of the globalhull. If h < h', this algorithm computes the complete convex hull in O(nlogh') time. Otherwise, the hull doesn't wrap all theway back around to l, so we know our guess h' is too small.

Chan's algorithm starts with the optimistic guess h' = 3. If we finish an iteration of the algorithm and find that h' is too small, we square h' and try again. In the final iteration, h'<h2, so the last iteration takes O(nlogh') = O (nlogh2) = O(nlogh) time.

The total running time of Chan's algorithm is given by the sum: O(nlog3 + nlog32 + nlog34 + ... + nlog32k) , for some integer k. We can rewrite this as a geometric series: O(nlog3 + 2nlog3 + 4nlog3 + ... + 2knlog3). So Chan's algorithm runs in O(nlogh) time overall, even we don't know the value of h.

In the figures, in order to keep things as clear as possible, the original author [6] have chosenthese subsets so that their convex hulls are disjoint. This is not true in general.

chan_two







Back to home





2.7 Incremental

The incremental convex hull algorithm are 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 neighbor points to update the hull. By repeating this process for the rest points outsidethe hull, finally, we get the convex hull for the points set

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 n-1, 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).

Back to home

2.8 Monotone Chain
monotone

Andrew's Monotone Chain Convex Hull algorithm is an algorithm which constructs convex hull of a set of 2D points in O(nlogn) time. It does this by first sorting the points lexicographically (first by x-coordinate, and in case of a tie, by y-coordinate), and then constructing upper and lower hulls of the points in O(n) time. An upper hull is the part of the convex hull, which is visible from the above. It runs from its rightmost point to the leftmost point in counterclockwise order. Lower hull is the remaining part of the convex hull.





Back to home

2.9 Running time comparision

Algorithm Running Time Discovered By
Brute Force O(n3) ——
Graham Scan O(nlog n) Graham, 1972
Jarvis March O(nh) Jarvis, 1973
QuickHull O(nh) Eddy, 1977 ; Bykat, 1978
Divide-and-Conquer O(nlog n) Preparata & Hong, 1977
Monotone Chain O(nlog n) Andrew, 1979
Incremental O(nlog n) Kallay, 1984
Chan's algorithm O(nlog h) Timothy Chan, 1993

Back to home

3. Related algorithms
3.1 Onions-peeling

Consider a set S of n on the plane. Compute the convex hull of S, and let S' be the set of points remaining in the interior of the hull. Then compute the convex hull of S' and recursively repeat this process until no more points remain. One ends up with a sequence of nested convex hulls, called the onion-peeling of S[4].

We have a simple algorithm to compute the onion-peeling of the point set S.

  1. Sort all points of S by x-coordinate.
  2. Run an algorithm which could compute the convex hull of S in time O(n), such as Graham's Scan, to get the convex hull H of S.
  3. Remove the vertices of H from S. If |S|>2, repeat step 2; else finished.

The sort process takes time O(nlogn). Each process of compute the convex hull takes time O(n), and in the worst case, each convex hull H computed is a triangle, in which case we need O(n) iterations. So, the total running time is O(n2). There is a sophiscatied and complicated algorithm that computes the onion in time O(nlogn) , thanks to Chazelle [3].

Note that the innermost structure can either be a line segment or a single point, besides a convex polygon. This graph gives information as to the layering of the points, i.e. how "deep" points are relative to each other other.

Back to home

3.2 Onion triangulations

The region between two nested convex hulls is called an annulus. Toussaint (1986) presents a simple algorithm for triangulating an annulus, using the Rotating Calipers. Using his method, once the onion peeling has been obtained, the entire set can be triangulated in linear time. Furthermore, the triangulation has two advantages: it keeps the onion-peeling as a subgraph, and it is hamiltonian, that is the dual of the triangulation graph is a chain.

The algorithm for triangulating an annulus is quite simple. The input is assumed to be a convex hull Q nested in an other hull P, both given in clockwise order.

  1. Insert the edges of the hulls as edges in the triangulation.
  2. Compute the points with minimum x coordinate for both P and Q, calling them xmin(P) and xmin(Q).
  3. Construct two vertical lines of support (the calipers) at xmin(P) and xmin(Q); call them LP and LQ.
  4. Insert (xmin(P), xmin(Q)) as an edge in the triangulation.
  5. The "current" points p and q for LP and LQ are xmin(P) and xmin(Q), respectively.
  6. Rotate the lines clockwise until one coincides with an edge. A new vertex has therefore been "hit" by one of the lines.
    • If it belongs to P (call it p'), insert (p', q) into the triangulation. Update the "current" points to p' and q.
    • If it belongs to Q (call it q'), insert (p, q') into the triangulation. Update the "current" points to p and q'.
    • In case of parallel edges, both lines of support coincide with edges, and two new vertices are "hit" (call them p' and q'). Then, insert (p', q'), and either (p, q') or (p', q) into the triangulation. Update the "current" points to p' and q'.
  7. Repeat the previous step until the starting minimum points are reached.

The above algorithm has linear time complexity. When used to triangulate a set of points, a single convex hull is run (at most) twice through the procedure, once as the inner hull of the annulus, and once as the outer. Then the entire running time for triangulating a set of n points remains O(n)[4].

Back to home

3.3 Point location

A convex polygon P can be stored as an array of n vertices in sorted order along the boundary, a related question is about how can we test whether a query point q lies inside P?

Without loss of generality, let us assume that the points are in anticlockwise order (if not,we can simply access the elements of the array in reverse order). Let the points in the array be p1,p2, . . . ,pn. Let the first edge p1p2 be the reference edge; we will measure all angles with respect to this edge. We will use sector in the following way: take the diagonals from p1 to two adjacent vertices, extend them away from p1 into half-infinite lines, and the region between the two lines is a sector. Note that because P is convex, it is possible to draw lines to every other vertex from p1 without intersecting the exterior of P.

In general, what we seek to do is to perform a binary search for the sector that q lies in, and then test whether q lies in the triangle bounded by the edge opposite to p1 and the two rays defining the sector. The angle that a point s makes with the reference edge is which between the vectors p1p2 and p1s, denoted as the dot product[5]:

  1. If q = p1, then report that q is in the polygon immediately; else, continue.
  2. Calculate the angle that q makes with the reference edge, which denoted as θq.
  3. If θ≥ π, then report that q is outside the polygon; else, go to next step.
  4. If 0≤ θ< π, because the given vertices are in sorted order around P, the angle that successive vertices makewith the reference edgemust be non-decreasing; Therefore, the mapping from the elements of the array of points to angles relative to the reference edge results in a non-decreasing sequence of values (θ2,…,θn); Then, we can perform a binary search for largest θi≤θq, with three possibilities:
    • θq< 0 or θq> θn: the point lies outside of the possible range of angle values, and q cannot lie inside P.
    • θq= θi for some i: the point lies on a half-infinite ray from p1 to some other point. In this case, q lies inside P iff |p1q|≤|p1pi|.
    • θi< θq< θi+1 for some i: the point lies in the sector bounded by the half-infinite rays from p1 to pi and pi+1. If q lies inside P, then q must lie to the left of , so that it is possible to draw a line from p to q without going over the edge of . To do this, we can use the cross product; q lies inside P iff pointing out of the page (assuming a right-handed coordinate system).

The preprocessing steps are all O(1) operations. The binary search takes O(nlogn); note that we only need to calculate the mapping from points to angles for the points that we compare against in the binary search to avoid the O(n) cost of converting all the points. The post-processing after we have found the value of θi is O(1). In total, the query of whether q lies in P is O(nlogn).

Back to home

4. References
  1. Chris Harrison. An Investigation of Graham's Scan and Jarvis' March URL:http://www.chrisharrison.net/projects/convexHull/index.html
  2. Dan Sunday. The Convex Hull of a 2D Point Set or Polygon URL:http://www.softsurfer.com/Archive/algorithm_0109/algorithm_0109.htm
  3. Bernard Chazelle. On the convex layers of a planar set. In IEEE Transactions on Information Theory 31(4):509-517, 1995.
  4. Hormoz Pirzadeh's HomePage. URL:http://cgm.cs.mcgill.ca/~orm/ontri.html
  5. Enoch Lau. Computational Geometry: An Odyssey. COMP4045 Assignments. SID 200415765.
  6. Some of the pictures used in this page are from http://www.algorithmist.com/index.php/Monotone_Chain_Convex_Hull;http://www.cs.berkeley.edu/~jrs/274/hullErickson.ps
  7. The code of the java applet in this page made references from http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html and http://bo.majewski.name/bluear/cg/hull/hull.html

这篇关于转载:平面点集凸壳算法大全(英文)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/377711

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

康拓展开(hash算法中会用到)

康拓展开是一个全排列到一个自然数的双射(也就是某个全排列与某个自然数一一对应) 公式: X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! 其中,a[i]为整数,并且0<=a[i]<i,1<=i<=n。(a[i]在不同应用中的含义不同); 典型应用: 计算当前排列在所有由小到大全排列中的顺序,也就是说求当前排列是第

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

【数据结构】——原来排序算法搞懂这些就行,轻松拿捏

前言:快速排序的实现最重要的是找基准值,下面让我们来了解如何实现找基准值 基准值的注释:在快排的过程中,每一次我们要取一个元素作为枢纽值,以这个数字来将序列划分为两部分。 在此我们采用三数取中法,也就是取左端、中间、右端三个数,然后进行排序,将中间数作为枢纽值。 快速排序实现主框架: //快速排序 void QuickSort(int* arr, int left, int rig

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

秋招最新大模型算法面试,熬夜都要肝完它

💥大家在面试大模型LLM这个板块的时候,不知道面试完会不会复盘、总结,做笔记的习惯,这份大模型算法岗面试八股笔记也帮助不少人拿到过offer ✨对于面试大模型算法工程师会有一定的帮助,都附有完整答案,熬夜也要看完,祝大家一臂之力 这份《大模型算法工程师面试题》已经上传CSDN,还有完整版的大模型 AI 学习资料,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

dp算法练习题【8】

不同二叉搜索树 96. 不同的二叉搜索树 给你一个整数 n ,求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种?返回满足题意的二叉搜索树的种数。 示例 1: 输入:n = 3输出:5 示例 2: 输入:n = 1输出:1 class Solution {public int numTrees(int n) {int[] dp = new int

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

最大公因数:欧几里得算法

简述         求两个数字 m和n 的最大公因数,假设r是m%n的余数,只要n不等于0,就一直执行 m=n,n=r 举例 以18和12为例 m n r18 % 12 = 612 % 6 = 06 0所以最大公因数为:6 代码实现 #include<iostream>using namespace std;/