包含多边形点的数组。我们可以遍历它的边界吗?
Array that contains points of polygon. Can we iterate through it's border?
假设我们有一个由点 (x,y)(tile) 填充的数组,所有这些都是伪代码,形成一个封闭且填充的二维多边形。我们如何才能仅遍历构成多边形边界的点?
应用 gift-wrapping algorithm 也称为 Jarvis 行进,它将仅输出构成边界的那些点。
jarvis(S)
// S is the set of points
pointOnHull = leftmost point in S // which is guaranteed to be part of the CH(S)
i = 0
repeat
P[i] = pointOnHull
endpoint = S[0] // initial endpoint for a candidate edge on the hull
for j from 1 to |S|
if (endpoint == pointOnHull) or (S[j] is on left of line from P[i] to endpoint)
endpoint = S[j] // found greater left turn, update endpoint
i = i+1
pointOnHull = endpoint
until endpoint == P[0] // wrapped around to first hull point
假设我们有一个由点 (x,y)(tile) 填充的数组,所有这些都是伪代码,形成一个封闭且填充的二维多边形。我们如何才能仅遍历构成多边形边界的点?
应用 gift-wrapping algorithm 也称为 Jarvis 行进,它将仅输出构成边界的那些点。
jarvis(S)
// S is the set of points
pointOnHull = leftmost point in S // which is guaranteed to be part of the CH(S)
i = 0
repeat
P[i] = pointOnHull
endpoint = S[0] // initial endpoint for a candidate edge on the hull
for j from 1 to |S|
if (endpoint == pointOnHull) or (S[j] is on left of line from P[i] to endpoint)
endpoint = S[j] // found greater left turn, update endpoint
i = i+1
pointOnHull = endpoint
until endpoint == P[0] // wrapped around to first hull point