我想在C++中实现Ramer–Douglas–Peucker_algorithm。帮助理解该算法
伪代码如下所示:
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
这是我的理解为止。 这是一个递归函数,它考虑了一系列点和距离阈值。
然后它遍历当前点找到最大距离的点。
我有点遗失了正交距离函数。我如何计算这个?我从来没有见过以线段作为参数的距离函数。
我想除此之外,我应该没问题,我只会使用std :: vectors作为数组。我想我会使用std :: copy,然后根据算法说的推或者弹出。
由于
那么,是不是OrthogonalDistance应该计算一个点与线的正交距离?当然一条线包含2点。你可以用一些基本的三角函数来计算它。 – futureelite7 2010-08-16 17:20:32