核心代码:
////////////////////////////////////////////////////////////////////// // 埃特金逐步插值 ////////////////////////////////////////////////////////////////////// static float GetValueAitken(const void* valuesPtr, int stride, int n, float t, float eps) { int i,j,k,m,l; float z,xx[10],yy[10]; // 初值 z = 0.0f; // 特例处理 if (n < 1) { return(z); } if (n == 1) { z = YfGetFloatValue(valuesPtr, stride, 0); return(z); } float xStep = 1.0f/(n - 1); // 开始插值 m=10; if (m > n) { m = n; } if (t <= 0.0f) { k = 1; } else if (t >= (n-1)*xStep) { k = n; } else { k = 1; j = n; while ((k-j != 1) && (k-j != -1)) { l = (k+j)/2; if (t < (l-1)*xStep) j = l; else k = l; } if (fabs(t-((l-1)*xStep)) > fabs(t-(j-1)*xStep)) { k = j; } } j = 1; l = 0; for (i = 1; i <= m; i++) { k = k+j*l; if ((k<1) || (k>n)) { l = l+1; j = -j; k = k+j*l; } xx[i-1] = (k-1)*xStep; yy[i-1] = YfGetFloatValue(valuesPtr, stride, k - 1); l = l+1; j = -j; } i = 0; do { i = i+1; z = yy[i]; for (j = 0; j <= i-1; j++) { z = yy[j]+(t-xx[j])*(yy[j]-z)/(xx[j]-xx[i]); } yy[i] = z; } while ((i != m-1) && (fabs(yy[i]-yy[i-1]) > eps)); return(z); }
切图:
相关软件的下载地址为:http://files.cnblogs.com/WhyEngine/TestSpline.zip