简体   繁体   English

c ++中的曲线平滑

[英]curve smoothing in c++

I want to smooth a curve and i don't know what approach to follow , The pattern are stored in a vector . 我想平滑曲线,我不知道要采用什么方法,模式存储在矢量中。

class Point2D
    {
    public:
        double x, y;
        Point2D() 
        {
            this->x=0; 
            this->y=0;
        }
        Point2D(double x, double y)
        {
            this->x = x;
            this->y = y;
        }
           }

vector<Point2D> vec1;

vec1 : vec1:

         *
       *    *

    .        .
   .           . 
  .              .
 .                 .
.                    .    .
                        . 

Expected pattern after smoothing: 平滑后的预期模式:

         *
       *    *
     .        .

   .             . 
  .                .
 .                  .
.                    .    .
                        . 

Try Laplacian smoothing. 尝试拉普拉斯平滑。 Except for the points you want to remain fixed (eg the stars in your diagram), set each point to the average of its immediate neighbors. 除了要保持固定的点(例如图中的星星)外,将每个点设置为其近邻的平均值。 Repeat once or twice, depending on how much smoothing you want. 重复一次或两次,具体取决于您想要的平滑程度。

This is a bit of a vague question but if you want to smooth out a set of data you can have a look into this . 这是一个模糊的问题但是如果你想要平滑一组数据,你可以看看这个

It is a link for polynomial regression. 它是多项式回归的链接。 You can then use your fitted polynomial to generate smooth points on the curve. 然后,您可以使用拟合多项式在曲线上生成平滑点。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM