tags:

views:

90

answers:

2

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

+2  A: 

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 :)

Gian
Okay thanks :).
Milo
+1  A: 

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.

Justin Ardini