该伪代码是否假定索引从零开始?
我不确定当他们写 1 时这是数组中的第一个还是第二个元素:
function DouglasPeucker(PointList[], epsilon)
//Find the point with the maximum distance
dmax = 0
index = 0
for i = 2 to (length(PointList) - 1)
d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end]))
if d > dmax
index = i
dmax = d
end
end
//If max distance is greater than epsilon, recursively simplify
if dmax >= epsilon
//Recursive call
recResults1[] = DouglasPeucker(PointList[1...index], epsilon)
recResults2[] = DouglasPeucker(PointList[index...end], epsilon)
// Build the result list
ResultList[] = {recResults1[1...end-1] recResults2[1...end]}
else
ResultList[] = {PointList[1], PointList[end]}
end
//Return the result
return ResultList[]
end
例如,我在 c++ 中实现这个,所以它说 i = 2,我应该为 int i = 1 做什么?
谢谢
I'm not sure if when they write 1 if this is the first or second element in the array:
function DouglasPeucker(PointList[], epsilon)
//Find the point with the maximum distance
dmax = 0
index = 0
for i = 2 to (length(PointList) - 1)
d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end]))
if d > dmax
index = i
dmax = d
end
end
//If max distance is greater than epsilon, recursively simplify
if dmax >= epsilon
//Recursive call
recResults1[] = DouglasPeucker(PointList[1...index], epsilon)
recResults2[] = DouglasPeucker(PointList[index...end], epsilon)
// Build the result list
ResultList[] = {recResults1[1...end-1] recResults2[1...end]}
else
ResultList[] = {PointList[1], PointList[end]}
end
//Return the result
return ResultList[]
end
for example, i'm implementing this in c++ so where it says for i = 2, should I do for int i = 1?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据猜测,索引 1 似乎是数组中的第一个元素(否则第一个元素永远不会在任何地方建立索引)。最好的确定方法可能就是尝试一下:)
At a guess, it looks like index 1 is the first element in the array (otherwise the first element is never being indexed anywhere). The best way to tell for sure is probably to try it though :)
它是 1 索引的。请注意行:
以及:
两者都从列表的开头进行访问。
It's 1-indexed. Notice the line:
as well as:
Both access from the beginning of the list.