我在维基百科上读了gift-wrapping algorithm,觉得我对它的理解还算不错(我错了)。因此,我想我也应该尝试用python实现它。然而维基百科上的伪代码在几点上让我迷失了方向。在
1:jarvis(S)
2: pointOnHull = leftmost point in S
3: i = 0
4: repeat
5: P[i] = pointOnHull
6: endpoint = S[0] // initial endpoint for a candidate edge on the hull
7: for j from 1 to |S|
8: if (endpoint == pointOnHull) or (S[j] is on left of line from P[i] to endpoint)
9: endpoint = S[j] // found greater left turn, update endpoint
10: i = i+1
11: pointOnHull = endpoint
12: until endpoint == P[0] // wrapped around to first hull point
假设我用的是一张坐标表
^{pr2}$我知道如何获取pointOnHull,并且我知道外部循环是针对外壳上的每个项目循环,而内部循环是点集合中的所有点。然而,我并不真正了解for循环中发生了什么,也不知道如何进行
(S[j] is on the left of line from P[i] to endpoint)
是否经过计算? 当然,它可以从一系列坐标中计算出来,但我不知道怎么计算。 稍微详细一点的解释会对我有很大帮助,或者也许只是一个不同的解释。在
目前没有回答
相关问题 更多 >
编程相关推荐