实现de castlejau算法c ++

时间:2015-03-11 13:45:25

标签: c++ algorithm graphics

程序运行但曲线未显示。 这是我的代码和注释,我在一个数组中有4个顶点。

void GLWidget::drawControlPolygon(){
    for (int i = 0; i < vertices.size()-1;i++){
        drawEdge(vertices[i], vertices[i+1], RGBValue(0,0,0));
    }
}

void GLWidget::drawDeCasteljau(float t) {

    Point p;
    int N_PTS = 4;

    p.x = pow((1-t),3)*vertices[0].x+3* t * pow((1 -t), 2) * vertices[1].x + 3 * (1-t)*pow(t,2)*vertices[2].x+ pow (t, 3)*vertices[3].x;
    p.y = pow((1-t),3)*vertices[0].y+3* t * pow((1 -t), 2) * vertices[1].y + 3 * (1-t)*pow(t,2)*vertices[2].y+ pow (t, 3)*vertices[3].y;
    p.z = pow((1-t),3)*vertices[0].z+3* t * pow((1 -t), 2) * vertices[1].z + 3 * (1-t)*pow(t,2)*vertices[2].z+ pow (t, 3)*vertices[3].z;

    int bezPoints[3][3] ;

    for (float u = 0.0; u <= 1.0; u += t) {
        for (int diag = N_PTS-2; diag >= 0; diag--) {
            for (int i = 0; i <= diag; i++) {
                int j = diag - i;
                bezPoints[i][j] = (1.0-u)*bezPoints[i][j+1] + u*bezPoints[i+1][j];
            }
        }
        // set the pixel for this parameter value

//Set pixel method for theImage object.
//        void setPixel(Index row, Index col, Byte red, Byte green, Byte blue, Byte alpha=255);
//        void setPixel(Index row, Index col, RGBValue colour, Byte alpha = 255);
                theImage.setPixel(bezPoints[0], bezPoints[0][0], RGBValue());

    }

}
void GLWidget::drawBezierCurve() {

}

这里的完整课程是指向它的链接...... https://www.dropbox.com/s/j6jw51uhz30m3tb/testApp.cc?dl=0

到目前为止输出看起来像这样 current output

谢谢!

0 个答案:

没有答案