该伪代码是否假定索引从零开始?

发布于 2024-09-14 09:46:25 字数 841 浏览 8 评论 0原文

我不确定当他们写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2024-09-21 09:46:25

据猜测,索引 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 :)

深白境迁sunset 2024-09-21 09:46:25

它是 1 索引的。请注意行:

recResults1[] = DouglasPeucker(PointList[1...index], epsilon)

以及:

ResultList[] = {recResults1[1...end-1] recResults2[1...end]}

两者都从列表的开头进行访问。

It's 1-indexed. Notice the line:

recResults1[] = DouglasPeucker(PointList[1...index], epsilon)

as well as:

ResultList[] = {recResults1[1...end-1] recResults2[1...end]}

Both access from the beginning of the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文