哈尔滨工业大学软件构造Lab1

实验中遇到的一个值得思考的问题

3.2

题目描述:

Implement convexHull, which computes the convex hull, the smallest convex set that contains all the points in a set of input points. The gift-wrapping algorithm is one simple approach to this problem, and there are other algorithms too. Remember that 6.031 focuses on SFB/ETU/RFC, so your code will not be judged by its performance.

The specification comment above convexHull requires you to return the “minimal subset of the input points that form the vertices of the perimeter of the convex hull.” This statement is well-defined on any set of input points. What should you do for a set of 2 points? 1 point? 0 points? What should you do for a point that lies on an edge of the convex hull, but is not a vertex of that edge?

大体意思就是要求我们完成一个闭包计算的问题,题目暗示我们可以使用gift-wrapping algorithm,经过网上查找该算法的相关资料,知道了计算凸包的几个步骤:

  1. 首先要选出最左下角 的点

  1. 接着需要选出距离选出的点极角最小的点,如果有角度相同的,那么比较距离,将较远的点加入凸包中

  1. 重复上述操作,直到形成凸包

在此问题中我遇到的问题是不会界定终止条件,开始我想的是遍历所有的点,当所有点都被遍历过一次后该算法终止,可是这样的终止条件并不能保证我们得到正确的闭包。经过思考,我选择在开始将选出的左下角的点打上已经被访问过的标记,在选出第二个凸包内的点后将开始左下角点打上的访问过的标记取消,并将终止条件设置为左下角的那个点再次加入凸包。经过这样的修改,程序可以运行产生正确的凸包。时间复杂度为O(n^{2})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值