优化/简化路径

jma*_*erx 6 algorithm path

假设我有150个节点/顶点的路径.如果是这样,我怎么能简化,例如一条带有3个顶点的直线,将删除中间的一条,因为它不会添加到路径中.我怎么能避免破坏尖角?我怎样才能消除微小的变化并保持平滑的曲线.

谢谢

use*_*594 3

更简单的方法。取 3 个顶点 a、b 和 c,并计算顶点之间的角度/倾斜度。

std::vector<VERTEX> path;
//fill path
std::vector<int> removeList;
//Assure that the value is in the same unit as the return of angleOf function.
double maxTinyVariation = SOMETHING; 

for (int i = 0; i < quantity-2; ++i) {
  double a = path[i], b = path[i + 1] , c = path[i + 2]
  double abAngle = angleOf(a, b);
  double bcAngle = angleOf(b, c);
  
  if (abs(ab - bc) <= maxTinyVariation) {
      //a, b and c are colinear
      //remove b later
      removeList.push_back(i+1);
  }
}
//Remove vertecies from path using removeList.
Run Code Online (Sandbox Code Playgroud)