27,374
社区成员
发帖
与我相关
我的任务
分享
#define POINTS_ON_CURVE 40
// by using LineTo() we do not need too many points.
// if use SetPixel(), increase it !
/** P0、P1、P2、P3 四个点定义了三次方贝塞尔曲线 B(t):
** B(t)=(1-t)*(1-t)*(1-t)*P0+3*t*(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=(double)1/POINTS_ON_CURVE;
CPoint pt;
//afxDump << nCount << "=nCount\n";
for(int i=0 ; i < nCount - 3 ; i += 3)
{
if(i==0)
{// only 1 start point need to be set !
pDC->MoveTo(lpPoints[0]);
}
for(t=0.0 ;t < 1.0 + dt ;t += dt)
{// 4 points each,cubic Bezier curve.
pt.x=(long)((1-t)*(1-t)*(1-t)*lpPoints[0+i].x +
3*t*(1-t)*(1-t)*lpPoints[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[0+i].y +
3*t*(1-t)*(1-t)*lpPoints[1+i].y +
3*t*t*(1-t)*lpPoints[2+i].y +
t*t*t*lpPoints[3+i].y);
pDC->LineTo(pt);
//pDC->SetPixel(pt,0xFF0000);// blue !
}
}
return TRUE;
}
其中 pDC->LineTo(pt);
即 G01