Home > Software engineering >  Cubic spline interpolation
Cubic spline interpolation

Time:11-08

Known iPeakarrayY [xlabel] and iPeakarrayX [xlabel], who is under the machine real-time calculated number, now want to cubic spline interpolation to redraw the graphics, the following code is a reference of cubic spline interpolation to do online, but calculating not to come out, can you help me take a look at why? I can't find the reason


IPeakarrayY [xlabel]=rawmax;//get peak value
IPeakarrayX [xlabel]=ipeakpp;//get wave abscissa
RW=rawmax;

/* chafenvalue=https://bbs.csdn.net/topics/iPeakarrayY [xlabel];//return wave crest value */
//the following by cubic spline interpolation to add
If (xlabel>
=2){
Chafenx [xlabel - 1]=iPeakarrayX [xlabel] - iPeakarrayX [xlabel - 1); Abscissa//
Chafenxpp [xlabel - 1]=iPeakarrayY [xlabel] - iPeakarrayY [xlabel - 1);//ordinate

//calculate x step
for(i=1; i<149; I++)
{
H=chafenx [I] [I] - chafenx [I - 1);
}
//specified coefficient, coefficient of upper triangular matrix
for(i=1; i<147; I++)
{
A [I]=h [I - 1);
[I]=2 B * (h + h [I] [I - 1)); [I]//B=2 * (h + h [I] [I + 1));
[I]=C h [I];//ignore C (n - 1) C [I]=h [I + 1);
}
//specified constant D
For (I=1; i<147; I++)
{
[I]=6 D * ((chafenxpp [I] - chafenxpp] [I - 1)/(h] [I - 1 + 1) - (chafenxpp] [I - 1 - chafenxpp [2] I -)/(h/I - 2 + 1));
}
D [0]=0;
D [300]=0;
//equation
//on triangular matrix
C [0]=C [0]/2;
D [0]=D [0]/2;

For (I=1; i<149; I++)
{
XCF=(B [I] - A [I] * C [I - 1));
C=C [I]/[I] (XCF + 1);
[I] [I]=D (D - A [I] * D] [I - 1)/(XCF + 1);
}

//the last value of X
X [149] [149]=D;

//reverse iteration, calculate X
For (I=148; I>=0; I -)
{
X=D [I] - [I] [I] C * X [I - 1);
}
//natural boundary
M [0]=0;
M [149]=0;
for(i=1; i<149; I++)
{
M=X [I] [I - 1);
}
//calculate the cubic spline curve coefficient
For (I=0; i <149; I++)
{
Ai=chafenxpp [I] [I];
Bi [I]=(chafenxpp [I] - chafenxpp] [I - 1)/(h] [I - 1 + 1) - (2 * h * [I - 1] M [I] [I - 1) * M + h] [I - 1)/6.
Ci=[I] M [I]/2;
Di [I]=(M - [I] M [] I - 1)/(6 * h [I] + 1);
}
for(i=0; i<150; I++)
{
SRwave [I] + [I]=ai bi [I] * (xlabel - chafenx [I]) + ci [I] * (xlabel - chafenx [I]) * (xlabel - chafenx [I]) + di [I] * (xlabel - chafenx [I]) * (xlabel - chafenx [I]) * (xlabel - chafenx [I]);

}
}

CodePudding user response:

Gdi + drawing curve when the sample is three times the difference, need not oneself

CodePudding user response:

No, I this is a machine to send the data to the PC, real-time display, so you need to interpolation calculation

CodePudding user response:

In the "Nurbs BOOK" have a cubic spline interpolation generated source code, copy to come over you can use,

CodePudding user response:

 
# define POINTS_ON_CURVE 40
//by using LineTo () we do not need too many points.
//if use SetPixel (), happens it!
/* * P0, P1, P2, P3 four point defines a cubic bezier curve B (t) :
* * B (t)=(1 - t) * (1 - t) * (1 - t) + 3 * t * * P0 (1 - t) * (1 - t) * (P1 + 3 t * * t * * (1 - t) P2 + t t * * t * P3
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL CTtfShowDlg: : CubicBezier (CDC * pDC, const POINT * lpPoints, int nCount)
{//lpPoints contains all points. Each 4 points make a cubic Bezier curve.
Double t;
Double dt=1/POINTS_ON_CURVE (double);
CPoint pt;
//afxDump & lt; For (int I=0; i {
If (I==0)
{//only 1 start point need to be set!
PDC - & gt; MoveTo (lpPoints [0]);
}
For (t=0.0; T & lt; 1.0 + dt; T +=dt)
{//4 points, each cubic Bezier curve.
Pt. X=(long) ((1 - t) * (1 - t) * (1 - t) * lpPoints [I] 0 + x +
3 * t * (1 - t) * (1 - t) * lpPoints [r]. 1 + I + x
3 t * * t * (1 - t) * lpPoints [2 + I]. X +
T * * t * t lpPoints [3 + I]. X);
Pt. Y=(long) ((1 - t) * (1 - t) * (1 - t) * lpPoints [I] 0 + y +
3 * t * (1 - t) * (1 - t) * lpPoints [r]. 1 + I + y
3 t * * t * (1 - t) * lpPoints [2 + I] y +
T * * t * t lpPoints [3 + I] y);
PDC - & gt; The LineTo (pt);
//pDC - & gt; SetPixel (pt, 0 xff0000);//blue!
}
}
Return TRUE;
}

CodePudding user response:

Void CTtfShowDlg: : DrawCurve (CDC * pDC, BYTE * pBuffer, int BufferLength, GLYPHMETRICS gm, the POINT of Origin)
{
.
# ifdef USE_MY_CUBIC
CubicBezier (pDC, Points, PointCount);
# the else
pDC - & gt; PolyBezier (PointCount Points);
# endif
  • Related