Core code:
1 /////////////////////////////////////// /////////////////////////// 2 // returns the same part of the same distance as 3/ //////////////////////////////////////// //// // 4 static float getvaluepqs (const void * valuesptr, int stride, int N, float t) 5 {6 int I, J, K, M, L; 7 float Z, HH, XI, XJ; 8 float B [8]; 9 10 // Initial Value 11 z = 0.0; 12 13 // Special Case Processing 14 if (n <1) 15 {16 return (z ); 17} 18 if (n = 1) 19 {20 z = yfgetfloatva Lue (valuesptr, stride, 0); 21 return (z); 22} 23 if (n = 2) 24 {25 float Y0 = yfgetfloatvalue (valuesptr, stride, 0 ); 26 float Y1 = yfgetfloatvalue (valuesptr, stride, 1); 27 z = y0 + (Y1-y0) * t; 28 return (z ); 29} 30 31 float xstep = 1.0f/(n-1); 32 33 // fractional interpolation 34 if (n <= 8) 35 {36 K = 0; 37 m = N; 38} 39 else if (T <(4.0f * xstep) 40 {41 K = 0; 42 m = 8; 43} 44 else if (T> (N-5) * xstep) 45 {46 k = n-8; 47 M = 8; 48} 49 else 50 {51 k = (INT) (T/xstep)-3; 52 m = 8; 53} 54 55 B [0] = yfgetfloatvalue (valuesptr, stride, k); 56 for (I = 2; I <= m; I ++) 57 {58 HH = yfgetfloatvalue (valuesptr, stride, I + k-1); 59 L = 0; 60 j = 1; 61 62 while (L = 0) & (j <= i-1) 63 {64 if (FABS (hh-B [J-1]) + 1.0f = 1.0f) 65 {66 L = 1; 67} 68 else69 {70 xi = (I + k-1) * xstep; 71 XJ = (J + k-1) * xstep; 72 HH = (Xi-XJ) /(hh-B [J-1]); 7 3} 74 75 J = J + 1; 76} 77 78 B [I-1] = HH; 79 if (L! = 0) 80 {81 B [I-1] = 1.0e + 35f; 82} 83} 84 85 Z = M-1]; 86 for (I = s-1; I> = 1; I --) 87 {88 z = B [I-1] + (t-(I + k-1) * xstep)/Z; 89} 90 91 return (z); 92}
Cut graph:
Related Software: http://files.cnblogs.com/WhyEngine/TestSpline.zip
Piecewise interpolation functions of Splines