`
lovnet
  • 浏览: 6714022 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

poj2187 凸包问题

 
阅读更多

Pseudo-Code: Graham Scan Algorithm

Input: a set of points S = {P = (P.x,P.y)}

Select the rightmost lowest point P0 in
S.
Sort
S angularly about P0 as a center.
For ties, discard the closer points.
Let P[N] be the sorted array of points.

Push P[0]=P0 and P[1] onto a stack
W.

while i < N
{
Let PT1 = the top point on
W
Let PT2 = the second top point on
W
if (P[i] is strictly left of the line PT2 to PT1) {
Push P[i] onto
W
i++ // increment i
}
else
Pop the top point PT1 off the stack

}


Output: W = the convex hull ofS.


转自:凸包问题的几种算法,包括Graham scan 算法

这个算法其实也很好想通的。

第一步:找到y坐标最小的点p0;

第二步:以p0为原点,对所有的点按逆时针顺序排序;

第三步:逐步迭代,加入边界点。(画出一条边,如果一个新的边更靠左,则加入,否则不加入)。




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics