void Lugrange(CPoint *aa, int k, int l_section,CDC *pDC)
{
float blend[4][100],f_blend[4][100],l_blend[4][100];
float u,v,w;
CPoint sm[4];
int x,y;
for(int i=0;i<l_section;i++)
{
u=float(i)/float (l_section);
blend[0][i]=u*(u-1)*(u-2)/(-6);
blend[1][i]=(u+1)*(u-1)*(u-2)/2;
blend[2][i]=(u+1)*u*(u-2)/(-2);
blend[3][i]=(u+1)*u*(u-1)/6;
v=u-1;
f_blend[0][i]=v*(v-1)*(v-2)/(-6);
f_blend[1][i]=(v+1)*(v-1)*(v-2)/2;
f_blend[2][i]=(v+1)*v*(v-2)/(-2);
f_blend[3][i]=(v+1)*v*(v-1)/6;
w=u+1;
l_blend[0][i]=w*(w-1)*(w-2)/(-6);
l_blend[1][i]=(w+1)*(w-1)*(w-2)/2;
l_blend[2][i]=(w+1)*w*(w-2)/(-2);
l_blend[3][i]=(w+1)*w*(w-1)/6;
}
for(int i=0;i<4;i++)
{
sm[i].x=aa[i].x;
sm[i].y=aa[i].y;
}
pDC->MoveTo(aa[0].x,aa[0].y);
for(int j=0;j<l_section;j++)
{
x=y=0;
for(int i=0;i<4;i++)
{
x=x+sm[i].x*f_blend[i][j];
y=y+sm[i].y*f_blend[i][j];
}
pDC->LineTo(x,y);
}
for(int m=4;m<k;m++)
{
for(int j=0;j<l_section;j++)
{
x=y=0;
for(int i=0;i<4;i++)
{
x=x+sm[i].x*blend[i][j];
y=y+sm[i].y*blend[i][j];
}
pDC->LineTo(x,y);
}
for(int i=0;i<3;i++)
{
sm[i].x=sm[i+1].x;
sm[i].y=sm[i+1].y;
}
sm[3].x=aa[m].x;
sm[3].y=aa[m].y;
}
for(int j=0;j<l_section;j++)
{
x=y=0;
for(int i=0;i<4;i++)
{
x=x+sm[i].x*l_blend[i][j];
y=y+sm[i].y*l_blend[i][j];
}
pDC->LineTo(x,y);
}
pDC->LineTo(sm[3].x,sm[3].y);
}
拉格朗日插值曲线
最新推荐文章于 2022-12-04 07:22:30 发布