优化/简化路径 [英] Optimizing / simplifying a path

查看:110
本文介绍了优化/简化路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有150个节点/ verticies的路径。我怎么能简化如果因此例如与3 verticies一条直线,就因为它确实没有什么要补充的路径中删除中间的一个。另外我怎么能避免破坏尖角?我怎么能去除微小的变化,并有剩余的平滑曲线。

Say I have a path with 150 nodes / verticies. How could I simplify if so that for example a straight line with 3 verticies, would remove the middle one since it does nothing to add to the path. Also how could I avoid destroying sharp corners? And how could I remove tiny variations and have smooth curves remaining.

感谢

推荐答案

的简单的方法。取3 vertecies a,b和c和calcule:的vertecies之间的角度/倾斜

The simpler approach. Take 3 vertecies a, b and c and calcule: The angle/inclination of between vertecies.

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.

这篇关于优化/简化路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆