C#使用立方平滑样条曲线 [英] C# To use Cubic Smoothing Splines

查看:799
本文介绍了C#使用立方平滑样条曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!



我必须使用样条方法来平滑我的数据曲线。

我需要平滑数据x和数据z。



我使用此链接: C#Cubic Spline Interpolation [ ^ ]



我试图将它集成到我的代码中。



这里涉及的代码部分通过三次样条插值:(在Void Start中)



  //  使用样条线 

x = new [CPT-1];
y = new float [cpt-1];

for int i = 0 ; i < cpt-1; i ++){
for int j = 1 ; j < names.Length + 1; j ++){

x [i] = nv_data [j-1] .positions [i] .x; // 数据位置保存在文本文件中
y [i] = nv_data [j-1] .positions [I] .Z; // 保存在文本文件中的数据位置

}
}

int n = 20 ;
xs = new float [n];

float stepSize =(x [x.Length - 1 ] - x [ 0 ])/(n - 1 );

for int i = 0 ; i < n; i ++)

{
xs [i] = xs [ 0 ] + i * stepSize;
}

// 这两行不正确:出现CubicSpline和FitAndEval红色
CubicSpline spline = new CubicSpline();
float [] ys = spline.FitAndEval(x,y,xs);





我试图在Void Start之前声明它:



 公共 CubicSpline样条; 

CubicSpline spline = new CubicSpline();





但这不好。



Ps:我把其他有用的代码(CubicSpline,TriDiagonalMatrix,ArrayUtil)放在当前代码的相同位置。



提前谢谢你

解决方案

首先,了解背景:

http://en.wikipedia .org / wiki / Interpolation [ ^ ],

http://en.wikipedia.org/wiki/Smoothing_spline [ ^ ],

http://en.wikipedia.org/wiki/Spline_%28mathematics%29 [ ^ ],

http://en.wikipedia.org/wiki/Spline_interpolation [ ^ ],

http://en.wikipedia.org/wiki/Discrete_spline_interpolation [ ^ ]。



对于实现,例如,此CodeProject文章: C#Cubic Spline Interpolation [ ^ ]。



需要更多?请参阅: http://bit.ly/1I8rda8 [ ^ ]。



-SA


Hello !

I have to use the spline method to smooth my data curve.
I need to smooth data x and data z.

I use this link : C# Cubic Spline Interpolation[^]

I tried to integrate it in my code.

Here the part of the code which is concerned by the cubic spline interpolation : (in Void Start)

// To use Spline

x = new float[cpt-1];
y = new float[cpt-1];

for (int i = 0; i < cpt-1; i++) {
    for (int j = 1; j < names.Length+1; j++) {

        x[i] = nv_data[j-1].positions[i].x; // Data positions saved in text file
        y[i] = nv_data[j-1].positions[i].z; // Data positions saved in text file

    }
}

    int n = 20;
    xs = new float[n];

    float stepSize = (x[x.Length - 1] - x[0]) / (n - 1);

    for (int i = 0; i < n; i++)

    {
        xs[i] = xs[0] + i * stepSize;
    }

// These two lines are not correct : CubicSpline and FitAndEval appear in red
CubicSpline spline = new CubicSpline();
float[] ys = spline.FitAndEval(x, y, xs);



I tried to declare it before Void Start :

public CubicSpline spline;

CubicSpline spline = new CubicSpline ();



But it's not good.

P-s : I put the other useful codes (CubicSpline, TriDiagonalMatrix, ArrayUtil) at the same location of this current code.

Thank you in advance

解决方案

First, learn the background:
http://en.wikipedia.org/wiki/Interpolation[^],
http://en.wikipedia.org/wiki/Smoothing_spline[^],
http://en.wikipedia.org/wiki/Spline_%28mathematics%29[^],
http://en.wikipedia.org/wiki/Spline_interpolation[^],
http://en.wikipedia.org/wiki/Discrete_spline_interpolation[^].

For implementation, for example, this CodeProject article: C# Cubic Spline Interpolation[^].

Need more? Please see: http://bit.ly/1I8rda8[^].

—SA


这篇关于C#使用立方平滑样条曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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