问题如下:已知六个点的坐标,怎样使用 Bezier 曲线将它们光滑的连接起来,要求输出的曲线的光滑度可以指定

解决方案 »

  1.   

    下列代码可以求出你要的曲线上的点,包含在 pPoints 中,其中 P1 - P4 为你输入的六个点,nCount 为你给定的曲线的光滑程度,nCount 越多越光滑:BOOL MakeBezier(const POINT * P1,
    const POINT * P2,
    const POINT * P3,
    const POINT * P4,
    const POINT * P5,
    const POINT * P6,
    int nCount,
    POINT * pPoints)
    {
    if(P1 == NULL || P2 == NULL ||
       P3 == NULL || P4 == NULL ||
       P5 == NULL || P6 == NULL ||
       nCount < 3 || pPoints == NULL)
    return FALSE; pPoints[0].x = P1->x;
    pPoints[0].y = P1->y;
    pPoints[nCount-1].x = P6->x;
    pPoints[nCount-1].y = P6->y; double t_step = (double)1 / (nCount - 1);
    double t = t_step; for(int i=1; i<nCount-1; i++, t+=t_step)
    {
    double s = 1-t;
    double d0 = s * s * s * s * s;
    double d1 = 5 * t * ( s * s * s * s );
    double d2 = 10 * t * t * ( s * s * s );
    double d3 = 10 * t * t * t * ( s * s );
    double d4 = 5 * t * t * t * t * s;
    double d5 = t * t * t * t * t; double X = d0 * P1->x +
       d1 * P2->x +
       d2 * P3->x +
       d3 * P4->x +
       d4 * P5->x +
       d5 * P6->x;
    double Y = d0 * P1->y +
       d1 * P2->y +
       d2 * P3->y +
       d3 * P4->y +
       d4 * P5->y +
       d5 * P6->y; pPoints[i].x = (int)X;
    pPoints[i].y = (int)Y;
    } return TRUE;
    }
      

  2.   

    好,问题解决,谢谢dzmsoft(天上的星星) !