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 做吗?

谢谢

4

2 回答 2

2

猜测一下,索引 1 似乎是数组中的第一个元素(否则第一个元素永远不会在任何地方被索引)。确定的最好方法可能是尝试一下:)

于 2010-08-16T18:09:28.273 回答
1

它是 1 索引的。注意这一行:

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

也:

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

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

于 2010-08-16T18:10:31.740 回答